integration/js/edition.js
changeset 101 e40637c085b0
parent 95 5f42ac58d262
child 102 172abe53cf6c
equal deleted inserted replaced
95:5f42ac58d262 101:e40637c085b0
     1 var myMedia = undefined,
     1 var myMedia = undefined,
     2     currentChapter = undefined,
     2     currentChapter = undefined,
     3     currentAnnotation = undefined;
     3     currentAnnotation = undefined,
       
     4     secMiniChapter = 10;
     4 
     5 
     5 $(function(){
     6 $(function(){
     6 
     7 
     7 var global = {
     8 var global = {
     8     colorsIndex : 0,
     9     colorsIndex : 0,
    22         var t = myMedia.duration * parseInt(ui.helper.css("left")) / ( $(".timeline-annotations").width() - 2 * ui.helper.width() );
    23         var t = myMedia.duration * parseInt(ui.helper.css("left")) / ( $(".timeline-annotations").width() - 2 * ui.helper.width() );
    23         myMedia.setCurrentTime(t);
    24         myMedia.setCurrentTime(t);
    24     }
    25     }
    25 });
    26 });
    26 
    27 
    27 $('.timeline-annotations').on('click', '.annotation', function(e){
    28 //survol
       
    29 $(document).on('mouseover', '.timeline-annotations .annotation, #list-annotations-rows tr, .item-display-annotation' , function(){
       
    30     if(!$(this).hasClass('shadow')) {
       
    31         var idAnnotation = $(this).attr('data-id');
       
    32         $('#annotation-timeline-'+idAnnotation+', #row-list-annotation-'+idAnnotation+', #item-current-annotation-'+idAnnotation).addClass('shadow');
       
    33     }
       
    34 });
       
    35 
       
    36 $(document).on('mouseover', '.chapter-segment, .row-list-chapter' , function(){
       
    37     if(!$(this).hasClass('shadow')) {
       
    38         var idChapter = $(this).attr('data-id');
       
    39         $('#row-list-chapter-'+idChapter+', #'+idChapter).addClass('shadow');
       
    40     }
       
    41 });
       
    42 
       
    43 $(document).on('mouseout', '.shadow' , function(){
       
    44     $('.shadow').removeClass('shadow');
       
    45 });
       
    46 
       
    47 
       
    48 $(document).on('click', '.annotation, .item-display-annotation', function(e){
    28     e.preventDefault();
    49     e.preventDefault();
    29     var idAnnotation = $(this).attr('data-id'),
    50     var idAnnotation = $(this).attr('data-id'),
    30         annotation = _.find(annotations, function(c){ return c.id == idAnnotation; });
    51         annotation = _.find(annotations, function(c){ return c.id == idAnnotation; });
    31     myMedia.setCurrentTime(annotation.begin);
    52     myMedia.setCurrentTime(annotation.begin);
    32     if($('#tab-annotation-'+idAnnotation).length){
    53     if($('#tab-annotation-'+idAnnotation).length){
   128 
   149 
   129         if(v.begin <= t && v.end >= t){
   150         if(v.begin <= t && v.end >= t){
   130             currentAnnotationsDisplay.push(v.id);
   151             currentAnnotationsDisplay.push(v.id);
   131             if(!$('#item-current-annotation-'+v.id).length){
   152             if(!$('#item-current-annotation-'+v.id).length){
   132                 var itemAnnotation = getTemplate('#tpl-item-annotation-display');
   153                 var itemAnnotation = getTemplate('#tpl-item-annotation-display');
       
   154                 v.iconTab = getIcon(v.type);
   133                 itemAnnotation = Mustache.render(itemAnnotation, v);
   155                 itemAnnotation = Mustache.render(itemAnnotation, v);
   134                 $('.list-current-annotations').append(itemAnnotation)
   156                 $('.list-current-annotations').append(itemAnnotation)
   135             }
   157             }
   136         }
   158         }
   137     });
   159     });
   155     $('#annotation-timeline-'+idAnnotation).addClass('editing');
   177     $('#annotation-timeline-'+idAnnotation).addClass('editing');
   156 }
   178 }
   157 //display annotation view
   179 //display annotation view
   158 $('.list-current-annotations').on('click', 'a', function(e){
   180 $('.list-current-annotations').on('click', 'a', function(e){
   159     e.preventDefault();
   181     e.preventDefault();
       
   182     /*
   160     var annotationDisplayView = $('.annotation-display-view'),
   183     var annotationDisplayView = $('.annotation-display-view'),
   161         idAnnotation = $(this).attr('data-id');
   184         idAnnotation = $(this).attr('data-id');
   162     var annotation = _.find(annotations, function(c){ return c.id == idAnnotation; });
   185     var annotation = _.find(annotations, function(c){ return c.id == idAnnotation; });
   163 
   186 
   164     if(annotationDisplayView.attr('data-id') == idAnnotation && annotationDisplayView.is(":visible")){
   187     if(annotationDisplayView.attr('data-id') == idAnnotation && annotationDisplayView.is(":visible")){
   168             .attr('data-id', idAnnotation)
   191             .attr('data-id', idAnnotation)
   169             .css('backgroundColor', annotation.color)
   192             .css('backgroundColor', annotation.color)
   170             .text(annotation.type+' : '+annotation.title)
   193             .text(annotation.type+' : '+annotation.title)
   171             .show();
   194             .show();
   172     }
   195     }
       
   196     */
   173 });
   197 });
   174 
   198 
   175 //########### modal
   199 //########### modal
   176 
   200 
   177     $(document).on('click', 'a.open-modal', function(e){
   201     $(document).on('click', 'a.open-modal', function(e){
   333         loadFormChapter(chapter.id);
   357         loadFormChapter(chapter.id);
   334     }
   358     }
   335 
   359 
   336     $('.chapter-widget').on('click', '.btn-cut-chapter', function(e){
   360     $('.chapter-widget').on('click', '.btn-cut-chapter', function(e){
   337         e.preventDefault();
   361         e.preventDefault();
   338 
   362         var begin = myMedia.currentTime,
       
   363             end = organizeNewChapter(myMedia.currentTime);
       
   364         if(!end){
       
   365             alert('Les chapitres doivent durer au moins '+secMiniChapter+' secondes');
       
   366             return;
       
   367         }
   339         var dataChapter = {
   368         var dataChapter = {
   340             title : 'New',
   369             title : 'New',
   341             begin : myMedia.currentTime,
   370             begin : begin,
   342             end : organizeNewChapter(myMedia.currentTime),
   371             end : end,
   343             description : 'description',
   372             description : 'description',
   344             keywords : ['tag1','tag2']
   373             keywords : ['tag1','tag2']
   345         };
   374         };
   346 
   375 
   347         newChapter(dataChapter, true);
   376         newChapter(dataChapter, true);
   348 
   377 
   349     });
   378     });
   350     
   379     
   351     function organizeNewChapter(beginNew){
   380     function organizeNewChapter(beginNew){
   352 
   381 
   353         var returnEnd;
   382         var returnEnd = false;
   354         $.each(chapters, function(k, v){
   383         $.each(chapters, function(k, v){
   355             var begin = v.begin,
   384             var begin = v.begin,
   356                 end = v.end;
   385                 end = v.end;
   357             if(beginNew>=begin && beginNew<=end){
   386 
       
   387             if(beginNew>=begin && beginNew<=end && end-beginNew>secMiniChapter*1000 && beginNew-begin>secMiniChapter*1000){
   358                 returnEnd = new IriSP.Model.Time(end);
   388                 returnEnd = new IriSP.Model.Time(end);
   359                 v.setEnd(beginNew); 
   389                 v.setEnd(beginNew); 
   360             }
   390             }
   361         });
   391         });
   362  
   392  
   384                     left = v.begin * wChapterSegmentWrap / myMedia.duration,
   414                     left = v.begin * wChapterSegmentWrap / myMedia.duration,
   385                     segment = $('<li>'+v.title+'</li>').css({
   415                     segment = $('<li>'+v.title+'</li>').css({
   386                         left : left,
   416                         left : left,
   387                         width : width,
   417                         width : width,
   388                         backgroundColor : v.color
   418                         backgroundColor : v.color
   389                     }).attr('id', v.id);
   419                     }).attr('id', v.id)
       
   420                     .attr('data-id', v.id)
       
   421                     .addClass('chapter-segment');
   390         
   422         
   391                 chapterSegmentWrap.append(segment);
   423                 chapterSegmentWrap.append(segment);
   392 
   424 
   393                 //liste
   425                 //liste
   394                 var tplChapterRow = getTemplate('#tpl-chapter-row');
   426                 var tplChapterRow = getTemplate('#tpl-chapter-row');
   514         currentAnnotation[name] = value;
   546         currentAnnotation[name] = value;
   515         if(name == 'title'){
   547         if(name == 'title'){
   516             var idAnnotation = $(this).parents('form').attr('data-id');
   548             var idAnnotation = $(this).parents('form').attr('data-id');
   517             $('#onglet-title-'+idAnnotation).text(value);
   549             $('#onglet-title-'+idAnnotation).text(value);
   518             $(this).parents('form').find('.btn-delete-annotation').attr('data-title', value);
   550             $(this).parents('form').find('.btn-delete-annotation').attr('data-title', value);
       
   551             $('#annotation-timeline-'+ idAnnotation).attr('title', value);
   519             $('#annotation-timeline-'+ idAnnotation+' span').text(value);
   552             $('#annotation-timeline-'+ idAnnotation+' span').text(value);
   520         }
   553         }
   521     });
   554     });
   522 
   555 
   523     //delete annotation
   556     //delete annotation