integration/js/editor.js
changeset 39 d3d8a88878ed
parent 32 47f9a2d63a0a
child 41 3ec2343f2b85
equal deleted inserted replaced
37:2cae82a5bdc2 39:d3d8a88878ed
     1 
     1 
     2 IriSP.hc_messages = {
     2 IriSP.hc_messages = {
     3     duration_ : "Durée :",
     3     Duration_ : "Durée :",
       
     4     duration_ : "durée :",
     4     edit_segment: "Éditer le segment",
     5     edit_segment: "Éditer le segment",
     5     segment_down: "Descendre le segment",
     6     segment_down: "Descendre le segment",
     6     segment_up: "Remonter le segment",
     7     segment_up: "Remonter le segment",
     7     delete_segment: "Supprimer le segment"
     8     delete_segment: "Supprimer le segment",
       
     9     clone_segment: "Cloner le segment",
       
    10     From_: "De :",
       
    11     to_: "à :",
       
    12     segment_title_placeholder: "Segment sans titre",
       
    13     mashup_title_placeholder: "Hashcut sans titre"
     8 }
    14 }
     9 
    15 
    10 IriSP.Hashcut = function(options) {
    16 IriSP.Hashcut = function(options) {
    11     
    17     
    12     
    18     
    18             serializer: IriSP.serializers.medialist
    24             serializer: IriSP.serializers.medialist
    19         }),
    25         }),
    20         mashup = new IriSP.Model.Mashup(false, project),
    26         mashup = new IriSP.Model.Mashup(false, project),
    21         mediatemplate = _.template('<li class="item-video" data-media-id="<%= id %>"><img src="<%= thumbnail %>" alt="<%= title %>" />'
    27         mediatemplate = _.template('<li class="item-video" data-media-id="<%= id %>"><img src="<%= thumbnail %>" alt="<%= title %>" />'
    22             + '<span class="video-info"><span class="title-video"><%= title %></span><span class="author"><%= description %></span>'
    28             + '<span class="video-info"><span class="title-video"><%= title %></span><span class="author"><%= description %></span>'
    23             + '<span class="time-length"><%= IriSP.hc_messages.duration_ %> <span><%= duration.toString() %></span></span></span></li>'),
    29             + '<span class="time-length"><%= IriSP.hc_messages.Duration_ %> <span><%= duration.toString() %></span></span></span></li>'),
    24         segmenttemplate = _.template('<li class="item-video" data-segment-id="<%= annotation.id %>" data-media-id="<%= annotation.getMedia().id %>">'
    30         segmenttemplate = _.template('<li class="item-video" data-segment-id="<%= annotation.id %>" data-media-id="<%= annotation.getMedia().id %>">'
    25             + '<img src="<%= annotation.getMedia().thumbnail %>" alt="<%= annotation.getMedia().title %>" />'
    31             + '<img src="<%= annotation.getMedia().thumbnail %>" alt="<%= annotation.getMedia().title %>" />'
    26             + '<span class="video-info"><span class="title-video"><%= annotation.getMedia().title %></span>'
    32             + '<div class="validate <%= annotation.status %>"><div class="validate-tooltip"><ul><li><%= annotation.status_messages.join("</li><li>") %></li></ul></div></div><span class="video-info"><span class="title-video"><%= annotation.getMedia().title %></span>'
    27             + '<span class="subtitle"><%= annotation.title %></span><span class="duration"><%= annotation.begin.toString() %> - <%= annotation.end.toString() %> (<%= annotation.getDuration().toString() %>)</span>'
    33             + '<span class="subtitle"><%= annotation.title %></span><span class="duration"><%= annotation.begin.toString() %> - <%= annotation.end.toString() %> (<%= annotation.getDuration().toString() %>)</span>'
    28             + '<ul class="tools"><li><a class="edit" href="#" title="<%= IriSP.hc_messages.edit_segment %>"></a></li><li><a class="bottom" href="#" title="<%= IriSP.hc_messages.segment_down %>"></a></li>'
    34             + '<ul class="tools"><li><a class="edit" href="#" title="<%= IriSP.hc_messages.edit_segment %>"></a></li><li><a class="bottom" href="#" title="<%= IriSP.hc_messages.segment_down %>"></a></li>'
    29             + '<li><a class="top" href="#" title="<%= IriSP.hc_messages.segment_up %>"></a></li><li><a class="delete" href="#" title="<%= IriSP.hc_messages.delete_segment %>"></a></li></ul></span></li>'),
    35             + '<li><a class="top" href="#" title="<%= IriSP.hc_messages.segment_up %>"></a></li><li><a class="delete" href="#" title="<%= IriSP.hc_messages.delete_segment %>"></a></li></ul></span></li>'),
    30         viztemplate = _.template('<div class="frise-segment" data-segment-id="<%= segmentid %>" style="background-color:<%= color %>; left:<%= left %>%; width:<%= width %>%;"></div>'),
    36         viztemplate = _.template('<div class="frise-segment" data-segment-id="<%= segmentid %>" style="background-color:<%= color %>; left:<%= left %>%; width:<%= width %>%;"></div>'),
    31         intervaltemplate = _.template('<span class="frise-indication" style="left:<%= left %>%;"><%= time.toString() %></span>'),
    37         intervaltemplate = _.template('<span class="frise-indication" style="left:<%= left %>%;"><%= time.toString() %></span>'),
    32         mediasegmenttemplate = _.template('<div class="media-segments-list"><div class="media-segment">'
    38         mediasegmenttemplate = _.template('<div class="media-segments-list"><div class="media-segment">'
    33             + '<div class="media-section media-segment-section" style="left:<%= left %>px; width:<%= width %>px; background:<%= annotation.getMedia().color %>"></div>'
    39             + '<div class="media-section media-segment-section" style="left:<%= left %>px; width:<%= width %>px; background:<%= annotation.getMedia().color %>"></div>'
    34             + '<div class="media-section media-current-section" style="left:<%= currentleft %>px; width:<%= currentwidth %>px;"><div class="media-current-section-inner"></div></div>'
    40             + '<div class="media-section media-current-section" style="left:<%= currentleft %>px; width:<%= currentwidth %>px;"><div class="media-current-section-inner"></div></div>'
    35             + '<div class="popin media-segment-popin" style="left:<%= popleft %>px"><img style="left:<%= pointerpos %>px;" class="pointer" src="img/popin-triangle.png" alt="" /><div class="popin-content">'
    41             + '<div class="popin media-segment-popin" style="left:<%= popleft %>px"><img style="left:<%= pointerpos %>px;" class="pointer" src="img/popin-triangle.png" alt="" /><div class="popin-content">'
    36             + '<h3><%= annotation.title %></h3><a href="#" class="button reprendre-segment" data-segment-id="<%= annotation.id %>">Cloner le segment</a>'
    42             + '<h3><%= annotation.title %></h3><a href="#" class="button reprendre-segment" data-segment-id="<%= annotation.id %>"><%= IriSP.hc_messages.clone_segment %></a>'
    37             + '<p>De: <span><%= annotation.begin.toString() %></span> à <span><%= annotation.end.toString() %></span> (durée: <span><%= annotation.getDuration().toString() %></span>)</p>'
    43             + '<p><%= IriSP.hc_messages.From_ %> <span><%= annotation.begin.toString() %></span> <%= IriSP.hc_messages.to_ %> <span><%= annotation.end.toString() %></span> (<%= IriSP.hc_messages.duration_ %> <span><%= annotation.getDuration().toString() %></span>)</p>'
    38             + '</div></div></div></div>');
    44             + '</div></div></div></div>');
       
    45     
       
    46     /* Validation of segments and mashup */
       
    47     
       
    48     var segmentcritical = [
       
    49         {
       
    50             validate: function(_s) {
       
    51                 var _d = _s.getDuration();
       
    52                 return (_d > 1000 && _d < 180000);
       
    53             },
       
    54             message: "La durée du segment doit être comprise entre 1 seconde et trois minutes"
       
    55         },
       
    56         {
       
    57             validate: function(_s) {
       
    58                 return (!!_s.title && _s.title !== IriSP.hc_messages.segment_title_placeholder);
       
    59             },
       
    60             message: "Un titre doit être donné au segment"
       
    61         }
       
    62     ];
       
    63     var segmentwarning = [
       
    64         {
       
    65             validate: function(_s) {
       
    66                 return (_s.description);
       
    67             },
       
    68             message: "Il est recommandé de donner une description au segment"
       
    69         }
       
    70     ];
       
    71     
       
    72     var mashupcritical = [
       
    73         {
       
    74             validate: function(_m) {
       
    75                 return _m.segments.length > 2;
       
    76             },
       
    77             message: "Un hashcut doit être composé d'au moins trois segments"
       
    78         },
       
    79         {
       
    80             validate: function(_m) {
       
    81                 return (!!_m.title && _m.title !== IriSP.hc_messages.mashup_title_placeholder);
       
    82             },
       
    83             message: "Un titre doit être donné au hashcut"
       
    84         }
       
    85     ];
       
    86     var mashupwarning = [
       
    87         {
       
    88             validate: function(_m) {
       
    89                 return !!_m.description
       
    90             },
       
    91             message: "Il est recommandé de donner une description au hashcut"
       
    92         }
       
    93     ];
    39 
    94 
    40     /* Fill left column with Media List */
    95     /* Fill left column with Media List */
    41 
    96 
    42     project.onLoad(function() {
    97     project.onLoad(function() {
    43         var html = '';
    98         var html = '';
    82         }
   137         }
    83     }
   138     }
    84     
   139     
    85     function updateMashupUI() {
   140     function updateMashupUI() {
    86         var listhtml = '', vizhtml = '', t = 0, k = mashup.duration ? (100 / mashup.duration) : 0;
   141         var listhtml = '', vizhtml = '', t = 0, k = mashup.duration ? (100 / mashup.duration) : 0;
       
   142         var critical = false, warning = false, messages = [];
    87         mashup.segments.forEach(function(_s) {
   143         mashup.segments.forEach(function(_s) {
    88             listhtml += segmenttemplate(_s);
   144             listhtml += segmenttemplate(_s);
    89             var vizdata = {
   145             var vizdata = {
    90                 left: k * t,
   146                 left: k * t,
    91                 width: k * _s.duration,
   147                 width: k * _s.duration,
    92                 color: _s.getMedia().color,
   148                 color: _s.getMedia().color,
    93                 segmentid: _s.annotation.id
   149                 segmentid: _s.annotation.id
    94             }
   150             }
    95             vizhtml += viztemplate(vizdata);
   151             vizhtml += viztemplate(vizdata);
       
   152             if (_s.annotation.status === "critical") {
       
   153                 critical = true;
       
   154             }
    96             t += _s.duration.milliseconds;
   155             t += _s.duration.milliseconds;
    97         });
   156         });
       
   157         if (critical) {
       
   158             messages.push("Certains segments ne sont pas valides");
       
   159         }
       
   160         
       
   161         _(mashupcritical).each(function(sc) {
       
   162             if (!sc.validate(mashup)) {
       
   163                 critical = true;
       
   164                 messages.push(sc.message);
       
   165             }
       
   166         });
       
   167         _(mashupwarning).each(function(sc) {
       
   168             if (!sc.validate(mashup)) {
       
   169                 warning = true;
       
   170                 messages.push(sc.message);
       
   171             }
       
   172         });
       
   173         mashup.status = critical ? "critical" : (warning ? "warning" : "valid");
       
   174         if (!messages.length) {
       
   175             messages.push("Le hashcut est valide !");
       
   176         }
       
   177         $(".publier-button").toggleClass("disable", critical);
       
   178         
       
   179         $(".liste-segment .validate").removeClass("critical warning valid").addClass(mashup.status);
       
   180         $(".liste-segment .validate-tooltip").html("<ul><li>" + messages.join("</li><li>")+"</li></ul>");
    98         
   181         
    99         var intervals = [ 1000, 2000, 5000, 10000, 30000, 60000, 120000, 300000, 600000, 900000, 1800000, 3600000, 7200000 ];
   182         var intervals = [ 1000, 2000, 5000, 10000, 30000, 60000, 120000, 300000, 600000, 900000, 1800000, 3600000, 7200000 ];
   100         
   183         
   101         function createIntervals(maxn) {
   184         function createIntervals(maxn) {
   102             for (var i = 0; i < intervals.length; i++) {
   185             for (var i = 0; i < intervals.length; i++) {
   433     
   516     
   434     /* Set current Media */
   517     /* Set current Media */
   435    
   518    
   436     var currentMedia, currentSegment;
   519     var currentMedia, currentSegment;
   437     
   520     
   438     function updateSliderAndTangles() {
   521     function updateSegmentUI() {
   439         if (currentMedia && currentSegment) {
   522         if (currentMedia && currentSegment) {
   440             var start = currentSegment.begin,
   523             var start = currentSegment.begin,
   441                 end = currentSegment.end,
   524                 end = currentSegment.end,
   442                 dur = currentSegment.getDuration(),
   525                 dur = currentSegment.getDuration(),
   443                 f = slidersRange / currentMedia.duration,
   526                 f = slidersRange / currentMedia.duration,
   448                 p = k * (start + end) / 2;
   531                 p = k * (start + end) / 2;
   449             sliceSlider.slider( "values", [ f * start, f * end ] );
   532             sliceSlider.slider( "values", [ f * start, f * end ] );
   450             tangleStart.text(start.toString(tangleStart.hasClass("active"))).attr("data-milliseconds",start.milliseconds);
   533             tangleStart.text(start.toString(tangleStart.hasClass("active"))).attr("data-milliseconds",start.milliseconds);
   451             tangleEnd.text(end.toString(tangleEnd.hasClass("active"))).attr("data-milliseconds",end.milliseconds);
   534             tangleEnd.text(end.toString(tangleEnd.hasClass("active"))).attr("data-milliseconds",end.milliseconds);
   452             tangleDuration.text(dur.toString(tangleDuration.hasClass("active"))).attr("data-milliseconds",dur.milliseconds);
   535             tangleDuration.text(dur.toString(tangleDuration.hasClass("active"))).attr("data-milliseconds",dur.milliseconds);
   453             $(".segment-info .pointer").css("left", p + "%");
   536             $(".segmentation .pointer").css("left", p + "%");
   454             $(".media-current-section").css({
   537             $(".media-current-section").css({
   455                 left: (k * start) + "%",
   538                 left: (k * start) + "%",
   456                 width: (k * dur) + "%"
   539                 width: (k * dur) + "%"
   457             })
   540             });
       
   541             var messages = [],
       
   542                 critical = false,
       
   543                 warning = false;
       
   544             _(segmentcritical).each(function(sc) {
       
   545                 if (!sc.validate(currentSegment)) {
       
   546                     critical = true;
       
   547                     messages.push(sc.message);
       
   548                 }
       
   549             });
       
   550             _(segmentwarning).each(function(sc) {
       
   551                 if (!sc.validate(currentSegment)) {
       
   552                     warning = true;
       
   553                     messages.push(sc.message);
       
   554                 }
       
   555             });
       
   556             currentSegment.status = critical ? "critical" : (warning ? "warning" : "valid");
       
   557             if (!messages.length) {
       
   558                 messages.push("Le segment est valide !")
       
   559             }
       
   560             currentSegment.status_messages = messages;
       
   561             
       
   562             $(".segmentation .validate").removeClass("critical warning valid").addClass(currentSegment.status);
       
   563             $(".segmentation .validate-tooltip").html("<ul><li>" + currentSegment.status_messages.join("</li><li>")+"</li></ul>");
   458         }
   564         }
   459     }
   565     }
   460     
   566     
   461     var addMode;
   567     var addMode;
   462     
   568     
   482             if (!currentSegment) {
   588             if (!currentSegment) {
   483                 currentSegment = new IriSP.Model.Annotation(false, project);
   589                 currentSegment = new IriSP.Model.Annotation(false, project);
   484                 currentSegment.setMedia(currentMedia.id);
   590                 currentSegment.setMedia(currentMedia.id);
   485                 currentSegment.setBegin(0);
   591                 currentSegment.setBegin(0);
   486                 currentSegment.setEnd(currentMedia.duration);
   592                 currentSegment.setEnd(currentMedia.duration);
   487                 currentSegment.title = "Segment sans titre";
   593                 currentSegment.title = IriSP.hc_messages.segment_title_placeholder;
   488                 currentSegment.description = "Extrait de « " + currentMedia.title + " »";
   594                 currentSegment.description = "";
   489                 currentSegment.on("change-begin", function() {
   595                 currentSegment.on("change-begin", function() {
   490                     if (currentMedia && currentSegment === this) {
   596                     if (currentMedia && currentSegment === this) {
   491                         currentMedia.setCurrentTime(this.begin);
   597                         currentMedia.setCurrentTime(this.begin);
   492                         updateSliderAndTangles();
   598                         updateSegmentUI();
   493                     }
   599                     }
   494                 });
   600                 });
   495                 currentSegment.on("change-end", function() {
   601                 currentSegment.on("change-end", function() {
   496                     if (currentMedia && currentSegment === this) {
   602                     if (currentMedia && currentSegment === this) {
   497                         currentMedia.setCurrentTime(this.end);
   603                         currentMedia.setCurrentTime(this.end);
   498                         updateSliderAndTangles();
   604                         updateSegmentUI();
   499                     }
   605                     }
   500                 });
   606                 });
   501                 currentSegment.on("enter", function() {
   607                 currentSegment.on("enter", function() {
   502                     if (currentMedia === mashup) {
   608                     if (currentMedia === mashup) {
   503                         $(".annotation-title").text(this.title);
   609                         $(".annotation-title").text(this.title);
   513             if (currentMedia.loaded) {
   619             if (currentMedia.loaded) {
   514                 currentMedia.setCurrentTime(currentSegment.begin);
   620                 currentMedia.setCurrentTime(currentSegment.begin);
   515             }
   621             }
   516             $(".add-segment").val(addMode ? "Ajouter au Hashcut" : "Sauvegarder");
   622             $(".add-segment").val(addMode ? "Ajouter au Hashcut" : "Sauvegarder");
   517             $(".create-or-edit").text(addMode ? "Créer un nouveau segment" : "Modifier le segment");
   623             $(".create-or-edit").text(addMode ? "Créer un nouveau segment" : "Modifier le segment");
   518             updateSliderAndTangles();
   624             updateSegmentUI();
   519             media.show();
   625             media.show();
   520             $("#segment-title").val(currentSegment.title);
   626             $("#segment-title").val(currentSegment.title);
   521             $("#segment-description").val(currentSegment.description);
   627             $("#segment-description").val(currentSegment.description);
   522             $("#segment-tags").val("");
   628             $("#segment-tags").val("");
   523             var relatedSegments = mashup.segments.filter(function(_s) {
   629             var relatedSegments = mashup.segments.filter(function(_s) {
   798     /* Segment Form interaction */
   904     /* Segment Form interaction */
   799    
   905    
   800     $("#segment-title").on("keyup change input paste", function() {
   906     $("#segment-title").on("keyup change input paste", function() {
   801         if (currentMedia && currentSegment) {
   907         if (currentMedia && currentSegment) {
   802             currentSegment.title = $(this).val();
   908             currentSegment.title = $(this).val();
       
   909             updateSegmentUI();
   803             updateMashupUI();
   910             updateMashupUI();
   804         }
   911         }
   805     });
   912     });
   806     $("#segment-description").on("keyup change input paste", function() {
   913     $("#segment-description").on("keyup change input paste", function() {
   807         if (currentMedia && currentSegment) {
   914         if (currentMedia && currentSegment) {
   808             currentSegment.description = $(this).val();
   915             currentSegment.description = $(this).val();
       
   916             updateSegmentUI();
   809         }
   917         }
   810     });
   918     });
   811     $("#segment-form").submit(function() {
   919     $("#segment-form").submit(function() {
   812         if (addMode) {
   920         if (addMode) {
   813             mashup.addAnnotation(currentSegment);
   921             mashup.addAnnotation(currentSegment);
  1019         currentSegment.setEnd(s.end);
  1127         currentSegment.setEnd(s.end);
  1020         return false;
  1128         return false;
  1021     });
  1129     });
  1022     
  1130     
  1023     /* Changing Hashcut Title and description */
  1131     /* Changing Hashcut Title and description */
  1024    
  1132     
       
  1133     mashup.title = IriSP.hc_messages.mashup_title_placeholder;
       
  1134     $(".title-video-wrap a").text(mashup.title);
       
  1135     $("#hashcut-title").val(mashup.title);
       
  1136     
  1025     $("#hashcut-title").on("keyup change input paste", function() {
  1137     $("#hashcut-title").on("keyup change input paste", function() {
  1026         mashup.title = $(this).val();
  1138         mashup.title = $(this).val();
  1027         $(".title-video-wrap a").text(mashup.title);
  1139         $(".title-video-wrap a").text(mashup.title);
  1028     });
  1140         updateMashupUI();
  1029     
  1141     });
       
  1142     
       
  1143     $("#hashcut-description").on("keyup change input paste", function() {
       
  1144         mashup.description = $(this).val();
       
  1145         updateMashupUI();
       
  1146     });
       
  1147     
       
  1148     updateMashupUI();
  1030 }
  1149 }