integration/js/edition.js
changeset 105 8645721dd9fc
parent 102 172abe53cf6c
child 107 f354d24e08ca
equal deleted inserted replaced
103:1c163781996b 105:8645721dd9fc
     1 var myMedia = undefined,
     1 var myMedia = undefined,
     2     currentChapter = undefined,
     2     currentChapter = undefined,
     3     currentAnnotation = undefined,
     3     currentAnnotation = undefined,
       
     4     currentSlider = undefined,
     4     secMiniChapter = 10;
     5     secMiniChapter = 10;
     5 
     6 
     6 $(function(){
     7 $(function(){
     7 
     8 
     8 var global = {
     9 var global = {
   222     e.preventDefault();
   223     e.preventDefault();
   223 });
   224 });
   224 
   225 
   225 //--title-editor
   226 //--title-editor
   226     $(document).on('click', '.project-title-editor i, .project-title', function () {
   227     $(document).on('click', '.project-title-editor i, .project-title', function () {
   227         disabledPreview();
   228         
   228         var html = $('.project-title').html();
   229         var html = $('.project-title').html();
   229         var input = $('<input type="text" />');
   230         var input = $('<input type="text" />');
   230         input.val(html);
   231         input.val(html);
   231         $('.project-title').replaceWith(input);
   232         $('.project-title').replaceWith(input);
   232         input.focus().keypress(function(e){
   233         input.focus().keypress(function(e){
   255         var idChapter = $(this).attr('id');
   256         var idChapter = $(this).attr('id');
   256         loadFormChapter(idChapter);
   257         loadFormChapter(idChapter);
   257     });
   258     });
   258 
   259 
   259     $('.chapter-widget-info').on('keyup', 'input[name=title], textarea', function(e){
   260     $('.chapter-widget-info').on('keyup', 'input[name=title], textarea', function(e){
   260         disabledPreview();
   261         
   261 
   262 
   262         var name = $(this).attr('name'),
   263         var name = $(this).attr('name'),
   263             value = $(this).val();
   264             value = $(this).val();
   264         currentChapter[name] = value;
   265         currentChapter[name] = value;
   265         if(name == 'title'){
   266         if(name == 'title'){
   272 
   273 
   273 
   274 
   274 
   275 
   275     function loadFormChapter(idChapter){
   276     function loadFormChapter(idChapter){
   276 
   277 
   277         disabledPreview();
   278         
   278         
   279         
   279 
   280 
   280         currentChapter = _.find(chapters, function(c){ return c.id == idChapter; });
   281         currentChapter = _.find(chapters, function(c){ return c.id == idChapter; });
   281         var chapterWrap = $('.chapter-widget-info'),
   282         var chapterWrap = $('.chapter-widget-info'),
   282             indexChapter = _.indexOf(chapters, currentChapter),
   283             indexChapter = _.indexOf(chapters, currentChapter),
   323     e.preventDefault();
   324     e.preventDefault();
   324     $('.form-chapter-edit').remove();
   325     $('.form-chapter-edit').remove();
   325 })
   326 })
   326 
   327 
   327 function deleteChapter(idChapter){
   328 function deleteChapter(idChapter){
   328     disabledPreview();
   329     
   329     $("#modal-confirm").modal('hide');
   330     $("#modal-confirm").modal('hide');
   330     var chapter = _.find(chapters, function(c){ return c.id == idChapter; }),
   331     var chapter = _.find(chapters, function(c){ return c.id == idChapter; }),
   331         indexChapter = _.indexOf(chapters, chapter),
   332         indexChapter = _.indexOf(chapters, chapter),
   332         chapterModify;
   333         chapterModify;
   333     if(indexChapter == 0){
   334     if(indexChapter == 0){
   406  
   407  
   407         return returnEnd;
   408         return returnEnd;
   408     }
   409     }
   409     
   410     
   410     function renderChapter(){
   411     function renderChapter(){
   411         disabledPreview();
   412         
   412 
   413 
   413         var chapterSegmentWrap = $('.chapter-segments'),
   414         var chapterSegmentWrap = $('.chapter-segments'),
   414             wChapterSegmentWrap = chapterSegmentWrap.width(),
   415             wChapterSegmentWrap = chapterSegmentWrap.width(),
   415             chapterList = $('.list-chapter-rows-wrap');
   416             chapterList = $('.list-chapter-rows-wrap');
   416 
   417 
   467         
   468         
   468         return annotation;
   469         return annotation;
   469     }
   470     }
   470 
   471 
   471     function renderAnnotation(){
   472     function renderAnnotation(){
   472         disabledPreview();
   473         
   473 
   474 
   474         var timeline = $('.timeline-annotations'),
   475         var timeline = $('.timeline-annotations'),
   475             wTimeline = timeline.width(),
   476             wTimeline = timeline.width(),
   476             annotationList = $('#list-annotations-rows');
   477             annotationList = $('#list-annotations-rows');
   477 
   478 
   540     }//renderAnnotation
   541     }//renderAnnotation
   541 
   542 
   542     //edit annotation
   543     //edit annotation
   543     $('#list-annotations').on('click', 'a.btn-edit-annotation', function(e){
   544     $('#list-annotations').on('click', 'a.btn-edit-annotation', function(e){
   544         e.preventDefault();
   545         e.preventDefault();
   545         disabledPreview();
   546         
   546         var idAnnotation = $(this).attr('data-id');
   547         var idAnnotation = $(this).attr('data-id');
   547         //si il est déjà ouvert
   548         //si il est déjà ouvert
   548         if($('#tab-annotation-'+idAnnotation).length){
   549         if($('#tab-annotation-'+idAnnotation).length){
   549             $('a[href=#tab-annotation-'+idAnnotation+']').tab('show');
   550             $('a[href=#tab-annotation-'+idAnnotation+']').tab('show');
   550         }else{
   551         }else{
   552             openTab(data.type, data);
   553             openTab(data.type, data);
   553         } 
   554         } 
   554     });
   555     });
   555 
   556 
   556     $('.tab-content').on('keyup', '.form-info-general-annotation input[name=title], .form-info-general-annotation textarea', function(e){
   557     $('.tab-content').on('keyup', '.form-info-general-annotation input[name=title], .form-info-general-annotation textarea', function(e){
   557         disabledPreview();
   558         
   558         var name = $(this).attr('name'),
   559         var name = $(this).attr('name'),
   559             value = $(this).val();
   560             value = $(this).val();
   560         currentAnnotation[name] = value;
   561         currentAnnotation[name] = value;
   561         if(name == 'title'){
   562         if(name == 'title'){
   562             var idAnnotation = $(this).parents('form').attr('data-id');
   563             var idAnnotation = $(this).parents('form').attr('data-id');
   576         btnDeleteModal.attr('data-type-delete', 'annotation');
   577         btnDeleteModal.attr('data-type-delete', 'annotation');
   577         btnDeleteModal.attr('data-id', idAnnotation);
   578         btnDeleteModal.attr('data-id', idAnnotation);
   578     });
   579     });
   579 
   580 
   580     function deleteAnnotation(idAnnotation){
   581     function deleteAnnotation(idAnnotation){
   581         disabledPreview();
   582         
   582         $("#modal-confirm").modal('hide');
   583         $("#modal-confirm").modal('hide');
   583         annotations.removeId(idAnnotation);
   584         annotations.removeId(idAnnotation);
   584         myProject.getAnnotations().removeId(idAnnotation, true);
   585         myProject.getAnnotations().removeId(idAnnotation, true);
   585         closeTab(idAnnotation);
   586         closeTab(idAnnotation);
   586         renderAnnotation();
   587         renderAnnotation();
   629             //head commun à tous
   630             //head commun à tous
   630             var tplHead = getTemplate('#tpl-head');
   631             var tplHead = getTemplate('#tpl-head');
   631             var output = Mustache.render(tplHead, dataView);
   632             var output = Mustache.render(tplHead, dataView);
   632             $(tabContent).append(output);
   633             $(tabContent).append(output);
   633             $(tabContent).find(".slider-duration").slider(configSlider(dataView));
   634             $(tabContent).find(".slider-duration").slider(configSlider(dataView));
       
   635             currentSlider = $(tabContent).find(".slider-duration");
   634             $(tabContent).find(".ui-slider-range.ui-widget-header.ui-corner-all").css('background', dataView.color);
   636             $(tabContent).find(".ui-slider-range.ui-widget-header.ui-corner-all").css('background', dataView.color);
   635             $(tabContent).find('.tag-it').tagit(tagitParam);
   637             $(tabContent).find('.tag-it').tagit(tagitParam);
   636             //type
   638             //type
   637             var viewType = {
   639             var viewType = {
   638                 id : idAnnotation,
   640                 id : idAnnotation,
   732 
   734 
   733     //définit currentAnnotation quand la tab s'ouvre
   735     //définit currentAnnotation quand la tab s'ouvre
   734     $('#onglet-annotations').on('show', 'a[data-toggle="annotation"]', function (e) {
   736     $('#onglet-annotations').on('show', 'a[data-toggle="annotation"]', function (e) {
   735         var idAnnotation = $(e.target).attr('data-id');
   737         var idAnnotation = $(e.target).attr('data-id');
   736         currentAnnotation = _.find(annotations, function(c){ return c.id == idAnnotation; });
   738         currentAnnotation = _.find(annotations, function(c){ return c.id == idAnnotation; });
       
   739         currentSlider = $('#tab-annotation-'+idAnnotation).find(".slider-duration");
   737         showCurrentAnnotationInTimeline(idAnnotation);
   740         showCurrentAnnotationInTimeline(idAnnotation);
   738     });
   741     });
   739 
   742 
   740     //rafraichit annotations au retour sur la liste
   743     //rafraichit annotations au retour sur la liste
   741     $('#onglet-annotations').on('show', 'a[data-toggle="list-annotations"]', function (e) {
   744     $('#onglet-annotations').on('show', 'a[data-toggle="list-annotations"]', function (e) {
   958     if(!isNaN(value)){
   961     if(!isNaN(value)){
   959         currentAnnotation.content.slideduration = value * 1000;
   962         currentAnnotation.content.slideduration = value * 1000;
   960     }
   963     }
   961 });
   964 });
   962 
   965 
       
   966 $('.alert').bind('close', function (e) {
       
   967     e.preventDefault();
       
   968     $(this).hide();
       
   969 });
       
   970 
       
   971 function showAlertByClassName(className){
       
   972     $('.alert').hide();
       
   973     $('.'+className).show();
       
   974 }
   963 //save project
   975 //save project
       
   976 
   964 $('.btn-save-project').bind('click', function(e){
   977 $('.btn-save-project').bind('click', function(e){
   965     $('.btn-apercu-projet').removeClass('disabled');
   978     e.preventDefault();
       
   979     if($(this).hasClass('disabled')) return;
       
   980 
       
   981     showAlertByClassName('save-load');
       
   982     $(this).addClass('disabled');
   966 
   983 
   967     console.log(myProject.serialize());
   984     console.log(myProject.serialize());
   968 
   985 
   969     $.ajax({
   986     $.ajax({
   970         type: "POST",
   987         type: "POST",
   973         contentType: "application/cinelab",
   990         contentType: "application/cinelab",
   974         headers: {
   991         headers: {
   975             "X-CSRFToken": tokenSaveProject
   992             "X-CSRFToken": tokenSaveProject
   976         },
   993         },
   977         success: function(data, status, request){
   994         success: function(data, status, request){
       
   995             showAlertByClassName('save-ok');
       
   996             $(this).removeClass('disabled');
       
   997             $('.btn-apercu-projet').removeClass('disabled');
   978             console.log('data : ', data);
   998             console.log('data : ', data);
   979             console.log('status : ', status);
   999             console.log('status : ', status);
   980             console.log('request : ', request);
  1000             console.log('request : ', request);
   981 
  1001 
   982         },
  1002         },
   983         error: function(jqXHR, textStatus, errorThrown){
  1003         error: function(jqXHR, textStatus, errorThrown){
   984             alert(gettext("Server error\nYour hashcut couldn't be published"));
  1004             showAlertByClassName('save-error');
       
  1005             $(this).removeClass('disabled');
       
  1006             //alert(gettext("Server error\nYour hashcut couldn't be published"));
   985         }
  1007         }
   986     });
  1008     });
   987 
  1009 
   988 
  1010 
   989 });
  1011 });
  1007     }
  1029     }
  1008     
  1030     
  1009 }
  1031 }
  1010 
  1032 
  1011 var tagitParam = {
  1033 var tagitParam = {
       
  1034     allowSpaces: true,
  1012     afterTagRemoved : onTagItChange,
  1035     afterTagRemoved : onTagItChange,
  1013     afterTagAdded : onTagItChange
  1036     afterTagAdded : onTagItChange
  1014 }
  1037 }
  1015 
  1038 
  1016 //CLEditor annotation > text (wysiwyg)
  1039 //CLEditor annotation > text (wysiwyg)
  1054                 wTimeline = $('.timeline-annotations').width(),
  1077                 wTimeline = $('.timeline-annotations').width(),
  1055                 annotationTimeline = $('#annotation-timeline-'+ data.id),
  1078                 annotationTimeline = $('#annotation-timeline-'+ data.id),
  1056                 width = Math.floor(data.getDuration() * wTimeline / myMedia.duration),
  1079                 width = Math.floor(data.getDuration() * wTimeline / myMedia.duration),
  1057                 left = Math.floor(data.begin * wTimeline / myMedia.duration);
  1080                 left = Math.floor(data.begin * wTimeline / myMedia.duration);
  1058 
  1081 
  1059             $( '#'+ idSlider +'-begin' ).html(data.begin.toString());
  1082             $( '#'+ idSlider +'-begin span' ).html(data.begin.toString());
       
  1083             $( '#'+ idSlider +'-begin span' ).attr('data-milliseconds', data.begin);
  1060             $( '#'+ idSlider +'-duration' ).html(data.getDuration().toString());
  1084             $( '#'+ idSlider +'-duration' ).html(data.getDuration().toString());
  1061             $( '#'+ idSlider +'-end' ).html(data.end.toString());
  1085             $( '#'+ idSlider +'-end span' ).html(data.end.toString());
       
  1086             $( '#'+ idSlider +'-end span' ).attr('data-milliseconds', data.end);
  1062 
  1087 
  1063             annotationTimeline.css({
  1088             annotationTimeline.css({
  1064                 left : left,
  1089                 left : left,
  1065                 width :width
  1090                 width :width
  1066             });
  1091             });
  1119     }
  1144     }
  1120     return content;
  1145     return content;
  1121 }//getContentAnnotationByType
  1146 }//getContentAnnotationByType
  1122 
  1147 
  1123 
  1148 
  1124 
  1149 /* Tangles */
       
  1150     var tangleMsPerPixel = 100,
       
  1151         activeTangle,
       
  1152         tangleStartX,
       
  1153         tangleStartVal,
       
  1154         tangleHasMoved;
       
  1155     
       
  1156     $('.chapter-widget-info').on('mousedown', '.time-tangle', function(evt){
       
  1157         activeTangle = $(this);
       
  1158         activeTangle.addClass("active");
       
  1159         tangleStartVal = +activeTangle.attr("data-milliseconds");
       
  1160         tangleStartX = evt.pageX;
       
  1161         tangleHasMoved = false;
       
  1162         $(this).parents('td').siblings('td').find(".time-tangle").addClass("deactivate");
       
  1163         return false;
       
  1164     });
       
  1165 
       
  1166     $('.tab-content').on('mousedown', '.time-tangle', function(evt){
       
  1167         activeTangle = $(this);
       
  1168         activeTangle.addClass("active");
       
  1169         tangleStartVal = +activeTangle.attr("data-milliseconds");
       
  1170         tangleStartX = evt.pageX;
       
  1171         tangleHasMoved = false;
       
  1172         $(this).parents('td').siblings('td').find(".time-tangle").addClass("deactivate");
       
  1173         return false;
       
  1174     });
       
  1175 
       
  1176     $(document)
       
  1177         .mousemove(function(evt) {
       
  1178             if (activeTangle) {
       
  1179                 tangleHasMoved = true;
       
  1180                 var newval = new IriSP.Model.Time(tangleMsPerPixel * (evt.pageX - tangleStartX) + tangleStartVal);
       
  1181                 activeTangle.trigger("valuechange", newval);
       
  1182                 return false;
       
  1183             }
       
  1184         })
       
  1185         .mouseup(function() {
       
  1186 
       
  1187             if (activeTangle) {
       
  1188                 if(activeTangle.hasClass('slider-tangle')){
       
  1189                     renderAnnotation();
       
  1190                     refreshAnnotationDisplay(myMedia.getCurrentTime());
       
  1191                 }
       
  1192                 $(".time-tangle").removeClass("active deactivate");
       
  1193                 activeTangle = undefined;
       
  1194             }
       
  1195         });
       
  1196 
       
  1197 //chapters
       
  1198 
       
  1199     function updateRenderChapter(chapterData){
       
  1200         var segment = $('.chapter-segments li#'+chapterData.id),
       
  1201             wChapterSegmentWrap = $('.chapter-segments').width(),
       
  1202             wSegmentNew = chapterData.getDuration() * wChapterSegmentWrap / myMedia.duration,
       
  1203             lSegmentNew = chapterData.begin * wChapterSegmentWrap / myMedia.duration,
       
  1204             row = $('#row-list-chapter-'+chapterData.id),
       
  1205             form = ($('#form-chapter-edit-'+chapterData.id).length) ? $('#form-chapter-edit-'+chapterData.id) : false;
       
  1206 
       
  1207         segment.css({
       
  1208             width : wSegmentNew,
       
  1209             left : lSegmentNew
       
  1210         });
       
  1211 
       
  1212         row.find('.begin').text(chapterData.begin);
       
  1213         console.log(chapterData.getDuration())
       
  1214         row.find('.duration').text(chapterData.getDuration());
       
  1215         row.find('.end').text(chapterData.end);
       
  1216 
       
  1217         if(form){
       
  1218             form.find('.begin').text(chapterData.begin);
       
  1219             form.find('.begin').attr('data-milliseconds',chapterData.begin);
       
  1220             form.find('.duration').text(chapterData.getDuration());
       
  1221             form.find('.end').text(chapterData.end);
       
  1222             form.find('.end').attr('data-milliseconds',chapterData.end);
       
  1223         }
       
  1224     }
       
  1225 
       
  1226     function updateChapterDuration(val, chapterBefore, chapterAfter){
       
  1227 
       
  1228         if (val<=chapterAfter.end && val>=chapterBefore.begin && chapterAfter.end-val>secMiniChapter*1000 && val-chapterBefore.begin>secMiniChapter*1000) {
       
  1229             chapterAfter.setBegin(val);
       
  1230             chapterBefore.setEnd(val);
       
  1231 
       
  1232             updateRenderChapter(chapterAfter);
       
  1233             updateRenderChapter(chapterBefore);
       
  1234         }
       
  1235     }
       
  1236 
       
  1237     $('.chapter-widget-info').on('valuechange', '.tangle-start', function(evt, val){
       
  1238         var indexChapter = _.indexOf(chapters, currentChapter);
       
  1239         if(indexChapter == 0 || chapters.length<=1) return;
       
  1240         
       
  1241         var chapterBefore = chapters[indexChapter-1],
       
  1242             chapterAfter = currentChapter;
       
  1243 
       
  1244         updateChapterDuration(val, chapterBefore, chapterAfter);
       
  1245     });
       
  1246 
       
  1247     $('.chapter-widget-info').on('valuechange', '.tangle-end', function(evt, val){
       
  1248         var indexChapter = _.indexOf(chapters, currentChapter);
       
  1249         if(indexChapter == chapters.length-1 || chapters.length<=1) return;
       
  1250         
       
  1251         var chapterAfter = chapters[indexChapter+1],
       
  1252             chapterBefore = currentChapter;
       
  1253 
       
  1254             updateChapterDuration(val, chapterBefore, chapterAfter);
       
  1255     });
       
  1256 
       
  1257 //annotations
       
  1258 
       
  1259     $('.tab-content').on('valuechange', '.tangle-start', function(evt, val){
       
  1260         var max = currentSlider.slider('values')[1],
       
  1261             min = 0,
       
  1262             beginOrEnd = 'begin';
       
  1263 
       
  1264         updateAnnotationDuration(val, min, max, beginOrEnd);
       
  1265     });
       
  1266 
       
  1267     $('.tab-content').on('valuechange', '.tangle-end', function(evt, val){
       
  1268         var max = myMedia.duration,
       
  1269             min = currentSlider.slider('values')[0],
       
  1270             beginOrEnd = 'end';
       
  1271 
       
  1272         updateAnnotationDuration(val, min, max, beginOrEnd);
       
  1273     });
       
  1274 
       
  1275     function updateAnnotationDuration(val, min, max, beginOrEnd){
       
  1276         var idAnnotation = currentAnnotation.id,
       
  1277             tabAnnotation = $('#tab-annotation-'+idAnnotation),
       
  1278             spanTangleStart = tabAnnotation.find('.tangle-start'),
       
  1279             spanTangleEnd = tabAnnotation.find('.tangle-end'),
       
  1280             spanDuration = tabAnnotation.find('#'+idAnnotation+'-duration');
       
  1281 
       
  1282         if(val<max && val>min){
       
  1283             if(beginOrEnd == 'begin'){currentAnnotation.setBegin(val);}
       
  1284             if(beginOrEnd == 'end'){currentAnnotation.setEnd(val);}
       
  1285 
       
  1286             spanTangleStart.html(currentAnnotation.begin.toString());
       
  1287             spanTangleStart.attr('data-milliseconds', currentAnnotation.begin);
       
  1288             spanDuration.html(currentAnnotation.getDuration().toString());
       
  1289             spanTangleEnd.html(currentAnnotation.end.toString());
       
  1290             spanTangleEnd.attr('data-milliseconds', currentAnnotation.end);
       
  1291 
       
  1292             var wTimeline = $('.timeline-annotations').width(),
       
  1293             annotationTimeline = $('#annotation-timeline-'+ idAnnotation),
       
  1294             width = Math.floor(currentAnnotation.getDuration() * wTimeline / myMedia.duration),
       
  1295             left = Math.floor(currentAnnotation.begin * wTimeline / myMedia.duration);
       
  1296 
       
  1297             annotationTimeline.css({
       
  1298                 left : left,
       
  1299                 width :width
       
  1300             });
       
  1301             currentSlider.slider('values', [currentAnnotation.begin, currentAnnotation.end])
       
  1302         }
       
  1303     }
       
  1304 /* /Tangles */ 
  1125 
  1305 
  1126 //test
  1306 //test
  1127 
  1307 
  1128 $('.log-annotations').bind('click', function(e){
  1308 $('.log-annotations').bind('click', function(e){
  1129     e.preventDefault();
  1309     e.preventDefault();
  1130     console.log(annotations.length + ' annotations', annotations);
  1310     console.log(annotations.length + ' annotations', annotations);
       
  1311     currentSlider.slider( "values", 0, 55 );
  1131 });
  1312 });
  1132 
  1313 
  1133 $('.log-chapters').bind('click', function(e){
  1314 $('.log-chapters').bind('click', function(e){
  1134     e.preventDefault();
  1315     e.preventDefault();
  1135     console.log(chapters.length + ' chapitres',chapters);
  1316     console.log(chapters.length + ' chapitres',chapters);