integration/js/edition.js
changeset 83 8f954a0d6031
parent 79 5dfa74fcec4b
child 84 9f481f896e60
equal deleted inserted replaced
79:5dfa74fcec4b 83:8f954a0d6031
   100         if(pos+wBtnCutChapter>wContainer){
   100         if(pos+wBtnCutChapter>wContainer){
   101             btnCutChapter.css("left",(pos - wBtnCutChapter));
   101             btnCutChapter.css("left",(pos - wBtnCutChapter));
   102         }else{
   102         }else{
   103             btnCutChapter.css("left",pos);
   103             btnCutChapter.css("left",pos);
   104         }
   104         }
       
   105         $('.info-time').text(t)
   105         //annotations view
   106         //annotations view
   106         refreshAnnotationDisplay(t);
   107         refreshAnnotationDisplay(t);
   107 
   108 
   108     });//timeupdate
   109     });//timeupdate
   109     
   110     
   149     }
   150     }
   150 }
   151 }
   151 
   152 
   152 function showCurrentAnnotationInTimeline(idAnnotation){
   153 function showCurrentAnnotationInTimeline(idAnnotation){
   153     $('.timeline-annotations .annotation').empty();
   154     $('.timeline-annotations .annotation').empty();
   154     $('#annotation-timeline-'+idAnnotation).text('en cours');
   155     $('#annotation-timeline-'+idAnnotation).html('<i class="icon-pencil"></i> '+textCurrentAnnotationEditT);
   155 }
   156 }
   156 //display annotation view
   157 //display annotation view
   157 $('.list-current-annotations').on('click', 'a', function(e){
   158 $('.list-current-annotations').on('click', 'a', function(e){
   158     e.preventDefault();
   159     e.preventDefault();
   159     var annotationDisplayView = $('.annotation-display-view'),
   160     var annotationDisplayView = $('.annotation-display-view'),
   164         annotationDisplayView.hide();
   165         annotationDisplayView.hide();
   165     }else{
   166     }else{
   166         annotationDisplayView
   167         annotationDisplayView
   167             .attr('data-id', idAnnotation)
   168             .attr('data-id', idAnnotation)
   168             .css('backgroundColor', annotation.color)
   169             .css('backgroundColor', annotation.color)
   169             .text(annotation.type)
   170             .text(annotation.type+' : '+annotation.title)
   170             .show();
   171             .show();
   171     }
   172     }
   172 });
   173 });
   173 
   174 
   174 //########### modal
   175 //########### modal
   175 
   176 
   176     $(document).on('click', 'a.open-modal', function(e){
   177     $(document).on('click', 'a.open-modal', function(e){
   177 
   178 
   178     });
       
   179 
       
   180 //edition image
       
   181     $('.popup').on('change', '#media-type-select', function(e){
       
   182         var typeImage = $(this).val();
       
   183         $('.input-image-url, .input-image-upload').hide();
       
   184         $('.input-image-'+typeImage).show();
       
   185     });
   179     });
   186 
   180 
   187 //select on bibliotheque
   181 //select on bibliotheque
   188 
   182 
   189     //confirmation suppression
   183     //confirmation suppression
   204     e.preventDefault();
   198     e.preventDefault();
   205 });
   199 });
   206 
   200 
   207 //--title-editor
   201 //--title-editor
   208     $(document).on('click', '.project-title-editor i, .project-title', function () {
   202     $(document).on('click', '.project-title-editor i, .project-title', function () {
       
   203         disabledPreview();
   209         var html = $('.project-title').html();
   204         var html = $('.project-title').html();
   210         var input = $('<input type="text" />');
   205         var input = $('<input type="text" />');
   211         input.val(html);
   206         input.val(html);
   212         $('.project-title').replaceWith(input);
   207         $('.project-title').replaceWith(input);
   213         input.focus().keypress(function(e){
   208         input.focus().keypress(function(e){
   236         var idChapter = $(this).attr('id');
   231         var idChapter = $(this).attr('id');
   237         loadFormChapter(idChapter);
   232         loadFormChapter(idChapter);
   238     });
   233     });
   239 
   234 
   240     $('.chapter-widget-info').on('keyup', 'input[name=title], textarea', function(e){
   235     $('.chapter-widget-info').on('keyup', 'input[name=title], textarea', function(e){
       
   236         disabledPreview();
       
   237 
   241         var name = $(this).attr('name'),
   238         var name = $(this).attr('name'),
   242             value = $(this).val();
   239             value = $(this).val();
   243         currentChapter[name] = value;
   240         currentChapter[name] = value;
   244         if(name == 'title'){
   241         if(name == 'title'){
   245             var idChapter = $(this).parents('form').attr('data-chapter-id');
   242             var idChapter = $(this).parents('form').attr('data-chapter-id');
   250 
   247 
   251 
   248 
   252 
   249 
   253     function loadFormChapter(idChapter){
   250     function loadFormChapter(idChapter){
   254 
   251 
       
   252         disabledPreview();
   255         
   253         
   256 
   254 
   257         currentChapter = _.find(chapters, function(c){ return c.id == idChapter; });
   255         currentChapter = _.find(chapters, function(c){ return c.id == idChapter; });
   258         var chapterWrap = $('.chapter-widget-info'),
   256         var chapterWrap = $('.chapter-widget-info'),
   259             indexChapter = _.indexOf(chapters, currentChapter),
   257             indexChapter = _.indexOf(chapters, currentChapter),
   281     if(chapters.length == 1){alert('Le projet doit contenir au moins un chapitre.'); return;}
   279     if(chapters.length == 1){alert('Le projet doit contenir au moins un chapitre.'); return;}
   282     var idChapter = $(this).attr('data-chapter-id'),
   280     var idChapter = $(this).attr('data-chapter-id'),
   283         btnDeleteModal = $("#modal-confirm #btn-delete-modal");
   281         btnDeleteModal = $("#modal-confirm #btn-delete-modal");
   284     btnDeleteModal.attr('data-type-delete', 'chapter');
   282     btnDeleteModal.attr('data-type-delete', 'chapter');
   285     btnDeleteModal.attr('data-id', idChapter);
   283     btnDeleteModal.attr('data-id', idChapter);
   286    // $("#modal-confirm #btn-delete-modal").attr('onclick', 'deleteChapter("'+idChapter+'")')
       
   287 /*
       
   288     var idChapter = $(this).attr('data-chapter-id'),
       
   289         chapter = _.find(chapters, function(c){ return c.id == idChapter; }),
       
   290         indexChapter = _.indexOf(chapters, chapter),
       
   291         chapterModify;
       
   292     if(indexChapter == 0){
       
   293         chapterModify = chapters[1];
       
   294         chapterModify.setBegin(0);
       
   295     }else{
       
   296         chapterModify = chapters[indexChapter-1];
       
   297         //var newEnd = new IriSP.Model.Time(chapter.end)
       
   298         chapterModify.setEnd(chapter.end);
       
   299     }
       
   300     chapters = _(chapters).reject(function(c) { return c.id == idChapter; });
       
   301     renderChapter();
       
   302     //si le formulaire est visible
       
   303     if($('#form-chapter-edit-'+idChapter).length){
       
   304         $('#form-chapter-edit-'+idChapter).remove();
       
   305     }
       
   306 */
       
   307 
   284 
   308 });
   285 });
   309 
   286 
   310 function deleteChapter(idChapter){
   287 function deleteChapter(idChapter){
   311     $("#modal-confirm").modal('hide')
   288     disabledPreview();
       
   289     $("#modal-confirm").modal('hide');
   312     var chapter = _.find(chapters, function(c){ return c.id == idChapter; }),
   290     var chapter = _.find(chapters, function(c){ return c.id == idChapter; }),
   313         indexChapter = _.indexOf(chapters, chapter),
   291         indexChapter = _.indexOf(chapters, chapter),
   314         chapterModify;
   292         chapterModify;
   315     if(indexChapter == 0){
   293     if(indexChapter == 0){
   316         chapterModify = chapters[1];
   294         chapterModify = chapters[1];
   376  
   354  
   377         return returnEnd;
   355         return returnEnd;
   378     }
   356     }
   379     
   357     
   380     function renderChapter(){
   358     function renderChapter(){
       
   359         disabledPreview();
       
   360 
   381         var chapterSegmentWrap = $('.chapter-segments'),
   361         var chapterSegmentWrap = $('.chapter-segments'),
   382             wChapterSegmentWrap = chapterSegmentWrap.width(),
   362             wChapterSegmentWrap = chapterSegmentWrap.width(),
   383             chapterList = $('.list-chapter-rows-wrap');
   363             chapterList = $('.list-chapter-rows-wrap');
   384 
   364 
   385         chapters = _.sortBy(chapters, function(c){
   365         chapters = _.sortBy(chapters, function(c){
   431         
   411         
   432         return annotation;
   412         return annotation;
   433     }
   413     }
   434 
   414 
   435     function renderAnnotation(){
   415     function renderAnnotation(){
       
   416         disabledPreview();
       
   417 
   436         var timeline = $('.timeline-annotations'),
   418         var timeline = $('.timeline-annotations'),
   437             wTimeline = timeline.width(),
   419             wTimeline = timeline.width(),
   438             annotationList = $('#list-annotations-rows');
   420             annotationList = $('#list-annotations-rows');
   439 
   421 
   440         annotations = _.sortBy(annotations, function(c){
   422         annotations = _.sortBy(annotations, function(c){
   497     }//renderAnnotation
   479     }//renderAnnotation
   498 
   480 
   499     //edit annotation
   481     //edit annotation
   500     $('#list-annotations').on('click', 'a.btn-edit-annotation', function(e){
   482     $('#list-annotations').on('click', 'a.btn-edit-annotation', function(e){
   501         e.preventDefault();
   483         e.preventDefault();
   502 
   484         disabledPreview();
   503         var idAnnotation = $(this).attr('data-id');
   485         var idAnnotation = $(this).attr('data-id');
   504         //si il est déjà ouvert
   486         //si il est déjà ouvert
   505         if($('#tab-annotation-'+idAnnotation).length){
   487         if($('#tab-annotation-'+idAnnotation).length){
   506             $('a[href=#tab-annotation-'+idAnnotation+']').tab('show');
   488             $('a[href=#tab-annotation-'+idAnnotation+']').tab('show');
   507         }else{
   489         }else{
   509             openTab(data.type, data);
   491             openTab(data.type, data);
   510         } 
   492         } 
   511     });
   493     });
   512 
   494 
   513     $('.tab-content').on('keyup', '.form-info-general-annotation input[name=title], .form-info-general-annotation textarea', function(e){
   495     $('.tab-content').on('keyup', '.form-info-general-annotation input[name=title], .form-info-general-annotation textarea', function(e){
       
   496         disabledPreview();
   514         var name = $(this).attr('name'),
   497         var name = $(this).attr('name'),
   515             value = $(this).val();
   498             value = $(this).val();
   516         currentAnnotation[name] = value;
   499         currentAnnotation[name] = value;
   517         if(name == 'title'){
   500         if(name == 'title'){
   518             var idAnnotation = $(this).parents('form').attr('data-id');
   501             var idAnnotation = $(this).parents('form').attr('data-id');
   521     });
   504     });
   522 
   505 
   523     //delete annotation
   506     //delete annotation
   524     $(document).on('click','.btn-delete-annotation', function(e){
   507     $(document).on('click','.btn-delete-annotation', function(e){
   525         e.preventDefault();
   508         e.preventDefault();
   526         /*
   509 
   527         var idAnnotation = $(this).attr('data-id');
       
   528         annotations = _(annotations).reject(function(c) { return c.id == idAnnotation; });
       
   529         closeTab(idAnnotation);
       
   530         if(!$(this).hasAttr('data-no-render'))//si on ferme à partir de la tab renderAnnotation sera appelé 2 fois
       
   531             renderAnnotation();
       
   532         */
       
   533         var idAnnotation = $(this).attr('data-id'),
   510         var idAnnotation = $(this).attr('data-id'),
   534             btnDeleteModal = $("#modal-confirm #btn-delete-modal");
   511             btnDeleteModal = $("#modal-confirm #btn-delete-modal");
   535         btnDeleteModal.attr('data-type-delete', 'annotation');
   512         btnDeleteModal.attr('data-type-delete', 'annotation');
   536         btnDeleteModal.attr('data-id', idAnnotation);
   513         btnDeleteModal.attr('data-id', idAnnotation);
   537     });
   514     });
   538 
   515 
   539     function deleteAnnotation(idAnnotation){
   516     function deleteAnnotation(idAnnotation){
       
   517         disabledPreview();
   540         $("#modal-confirm").modal('hide');
   518         $("#modal-confirm").modal('hide');
   541         annotations = _(annotations).reject(function(c) { return c.id == idAnnotation; });
   519         annotations = _(annotations).reject(function(c) { return c.id == idAnnotation; });
   542         closeTab(idAnnotation);
   520         closeTab(idAnnotation);
   543         renderAnnotation();
   521         renderAnnotation();
   544     }
   522     }
   555         var type = $(this).attr('data-type');
   533         var type = $(this).attr('data-type');
   556         openTab(type);
   534         openTab(type);
   557     });
   535     });
   558 
   536 
   559     function openTab(type, data){
   537     function openTab(type, data){
   560 
   538         
   561         var dataView;
   539         var dataView;
   562         if(_.isUndefined(data)){//nouveau
   540         if(_.isUndefined(data)){//nouveau
   563             var currentTimePlusUnMin = 60 * 1000 + myMedia.currentTime,
   541             var currentTimePlusUnMin = 60 * 1000 + myMedia.currentTime,
   564                 endAnnotation = (currentTimePlusUnMin<myMedia.duration) ? currentTimePlusUnMin : myMedia.duration;
   542                 endAnnotation = (currentTimePlusUnMin<myMedia.duration) ? currentTimePlusUnMin : myMedia.duration;
   565             var dataAnnotation = {
   543             var dataAnnotation = {
   603             //particularité selon type
   581             //particularité selon type
   604             switch(type){
   582             switch(type){
   605                 case 'audio':
   583                 case 'audio':
   606                     break;
   584                     break;
   607                 case 'video':
   585                 case 'video':
   608                     
       
   609                     if(viewType.content.url != ""){
   586                     if(viewType.content.url != ""){
   610 
       
   611                         var videoWrap = $(tabContent).find('.annotation-video-content');
   587                         var videoWrap = $(tabContent).find('.annotation-video-content');
   612                         renderVideoInfo(videoWrap, viewType.content);
   588                         renderVideoInfo(videoWrap, viewType.content);
   613    
       
   614                     }
   589                     }
   615 
       
   616                     
       
   617 
       
   618                     break;
   590                     break;
   619                 case 'text': 
   591                 case 'text': 
   620                     var cledit = $(tabContent).find('.wysiwyg').cleditor(wysiwygConfig)[0];
   592                     var cledit = $(tabContent).find('.wysiwyg').cleditor(wysiwygConfig)[0];
   621                     break;
   593                     break;
   622                 case 'links': 
   594                 case 'links': 
   630                         addLinkRow(tbody);
   602                         addLinkRow(tbody);
   631                     }
   603                     }
   632                     break;
   604                     break;
   633 
   605 
   634                 case 'slideshow': 
   606                 case 'slideshow': 
   635 
   607                     $(tabContent).find('.number-spin').val(dataView.content.slideduration/1000);
   636                     $(tabContent).find('.number-spin').spin(spinParam);
   608                     $(tabContent).find('.number-spin').spin(spinParam);
   637                     $(tabContent).find('.ui-sortable').sortable({
   609                     $(tabContent).find('.ui-sortable').sortable({
   638                         start: function (event, ui) {
   610                         start: function (event, ui) {
   639                             $(ui.item).data("startindex", ui.item.index());
   611                             $(ui.item).data("startindex", ui.item.index());
   640                         },
   612                         },
   778         disabledBtnSortable(diaporama);
   750         disabledBtnSortable(diaporama);
   779     
   751     
   780     };
   752     };
   781 
   753 
   782     //edit title / description
   754     //edit title / description
   783     $('.tab-content').on('click', '.title-slideshow-row', function(){
   755     $('.tab-content').on('click', '.title-slideshow-row, .description-slideshow-row, .video-title-edit, .video-description-edit', function(){
   784         if($(this).find('input').length) return;
   756         if($(this).find('input').length) return;
   785         var html = $(this).find('span').html();
   757         var html = $(this).find('span').html(),
   786         var input = $('<input type="text" />').addClass('input-mini').attr('name', 'title');
   758             inputType = $(this).attr('data-input'),
       
   759             name = $(this).attr('data-name'),
       
   760             input = $('<'+inputType+'>').attr('name', name);
   787         input.val(html);
   761         input.val(html);
   788         $(this).find('span').replaceWith(input);
   762         $(this).find('span').replaceWith(input);
   789         input.focus().keypress(function(e){
   763         input.focus().keypress(function(e){
   790             code = (e.keyCode ? e.keyCode : e.which);
   764             code = (e.keyCode ? e.keyCode : e.which);
   791             if (code == 13) $(this).blur();
   765             if (code == 13) $(this).blur();
   792         });
   766         });
   793     });
   767     });
   794 
   768 
   795     $('.tab-content').on('click', '.description-slideshow-row', function(){
       
   796         if($(this).find('textarea').length) return;
       
   797         var html = $(this).find('span').html();
       
   798         var input = $('<textarea>').attr('name', 'description');
       
   799         input.val(html);
       
   800         $(this).find('span').replaceWith(input);
       
   801         input.focus().keypress(function(e){
       
   802             code = (e.keyCode ? e.keyCode : e.which);
       
   803             if (code == 13) $(this).blur();
       
   804         });
       
   805     });
       
   806 
       
   807     $(document).on('blur', '.title-slideshow-row input, .description-slideshow-row textarea', function(){
   769     $(document).on('blur', '.title-slideshow-row input, .description-slideshow-row textarea', function(){
   808         var newValue = $(this).val(),
   770         var newValue = $(this).val(),
   809             name = $(this).attr('name'),
   771             name = $(this).attr('name'),
   810             span = $('<span>').html(newValue),
   772             span = $('<span>').html(newValue),
   811             indexRow = $(this).parents('.row-image-diaporama').index();
   773             indexRow = $(this).parents('.row-image-diaporama').index();
   812         $(this).replaceWith(span);
   774         $(this).replaceWith(span);
   813 
       
   814         currentAnnotation.content.images[indexRow][name] = newValue;
   775         currentAnnotation.content.images[indexRow][name] = newValue;
       
   776     });
       
   777 
       
   778     $(document).on('blur', '.video-title-edit input, .video-description-edit textarea', function(){
       
   779         var newValue = $(this).val(),
       
   780             name = $(this).attr('name'),
       
   781             span = $('<span>').html(newValue);
       
   782         $(this).replaceWith(span);
       
   783         currentAnnotation.content[name] = newValue;
   815     });
   784     });
   816 
   785 
   817     //bouton up / down
   786     //bouton up / down
   818     $(document).on('click', '.ui-sortable .btn-sort', function(e){
   787     $(document).on('click', '.ui-sortable .btn-sort', function(e){
   819         e.preventDefault();
   788         e.preventDefault();
   907 });
   876 });
   908 
   877 
   909 $('.tab-content').on('change keyup', '.config-diaporama input[name=duration]', function(){
   878 $('.tab-content').on('change keyup', '.config-diaporama input[name=duration]', function(){
   910     var value = $(this).val();
   879     var value = $(this).val();
   911     if(!isNaN(value)){
   880     if(!isNaN(value)){
   912         currentAnnotation.content.duration = value;
   881         currentAnnotation.content.slideduration = value * 1000;
   913     }
   882     }
   914 });
   883 });
       
   884 
       
   885 //save project
       
   886 $('.btn-save-project').bind('click', function(e){
       
   887     $('.btn-apercu-projet').removeClass('disabled');
       
   888 
       
   889 });
       
   890 
       
   891 function disabledPreview(){
       
   892     if(!$('.btn-apercu-projet').hasClass('disabled'))$('.btn-apercu-projet').addClass('disabled');
       
   893 }
   915 
   894 
   916 //################ config
   895 //################ config
   917 //tagit
   896 //tagit
   918 function onTagItChange(e, ui) {
   897 function onTagItChange(e, ui) {
   919     var tagitType = $(this).attr('data-type'), 
   898     var tagitType = $(this).attr('data-type'), 
   935 }
   914 }
   936 
   915 
   937 //CLEditor annotation > text (wysiwyg)
   916 //CLEditor annotation > text (wysiwyg)
   938 //http://premiumsoftware.net/cleditor/docs/GettingStarted.html#optionalParameters
   917 //http://premiumsoftware.net/cleditor/docs/GettingStarted.html#optionalParameters
   939 var wysiwygConfig = {
   918 var wysiwygConfig = {
   940     width:        456, 
   919     width:        450, 
   941     height:       250, 
   920     height:       250, 
   942     controls:     "bold italic underline strikethrough | font size " +
   921     controls:     "bold italic underline strikethrough | font size " +
   943                     "style | color highlight removeformat | bullets numbering | source",
   922                     "style | color highlight removeformat | bullets numbering | source",
   944     fonts:        "Arial,Arial Black,Comic Sans MS,Courier New,Narrow,Garamond," +
   923     fonts:        "Arial,Arial Black,Comic Sans MS,Courier New,Narrow,Garamond," +
   945                     "Georgia,Impact,Sans Serif,Serif,Tahoma,Trebuchet MS,Verdana",
   924                     "Georgia,Impact,Sans Serif,Serif,Tahoma,Trebuchet MS,Verdana",
  1030             };
  1009             };
  1031             break;
  1010             break;
  1032         case 'slideshow': 
  1011         case 'slideshow': 
  1033             content = {
  1012             content = {
  1034                 mimetype : "application/x-ldt-slideshow",
  1013                 mimetype : "application/x-ldt-slideshow",
  1035                 duration : 1,
  1014                 slideduration : 1000,
  1036                 autostart : false,
  1015                 autostart : false,
  1037                 images : []
  1016                 images : []
  1038             };
  1017             };
  1039             break;
  1018             break;
  1040     }
  1019     }
  1067         }
  1046         }
  1068     }
  1047     }
  1069     this.splice(new_index, 0, this.splice(old_index, 1)[0]);
  1048     this.splice(new_index, 0, this.splice(old_index, 1)[0]);
  1070     return this; 
  1049     return this; 
  1071 };
  1050 };
  1072 
       
  1073 
  1051 
  1074 function getVideoPlayer(src, videoWrap){
  1052 function getVideoPlayer(src, videoWrap){
  1075 
  1053 
  1076     var youtubeTemplate = _.template(
  1054     var youtubeTemplate = _.template(
  1077         '<iframe width="<%- width %>" height="<%- height %>" src="http://www.youtube.com/embed/<%- ytid %>?rel=0&autoplay=<%- autoplay %>" frameborder="0"></iframe>'
  1055         '<iframe width="<%- width %>" height="<%- height %>" src="http://www.youtube.com/embed/<%- ytid %>?rel=0&autoplay=<%- autoplay %>" frameborder="0"></iframe>'