integration/js/editor.js
changeset 49 a21b851538b2
parent 45 f39df810caab
child 50 89e152523cb6
equal deleted inserted replaced
48:2774e46c3e9d 49:a21b851538b2
     1 
       
     2 IriSP.hc_messages = {
       
     3     Duration_ : "Durée :",
       
     4     duration_ : "durée :",
       
     5     edit_segment: "Éditer le segment",
       
     6     segment_down: "Descendre le segment",
       
     7     segment_up: "Remonter 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",
       
    14     copy_of_: "Copie de ",
       
    15 }
       
    16 
       
    17 IriSP.editor = function(options) {
     1 IriSP.editor = function(options) {
    18     
     2     
    19     /* Load Media List */
     3     /* Load Media List */
    20     
     4     
    21     var directory = new IriSP.Model.Directory(),
     5     var directory = new IriSP.Model.Directory(),
    22         apidirectory = new IriSP.Model.Directory(),
     6         apidirectory = new IriSP.Model.Directory(),
    23         project = directory.remoteSource({
     7         project = directory.remoteSource({
       
     8             url: IriSP.endpoints.content,
       
     9             url_params: _({}).extend(options.filter),
       
    10             serializer: IriSP.serializers.content
       
    11         }),
       
    12 /*        project = directory.remoteSource({
    24             url: options.url,
    13             url: options.url,
    25             serializer: IriSP.serializers.medialist
    14             serializer: IriSP.serializers.medialist
    26         }),
    15         }),
       
    16 */
    27         mashup = new IriSP.Model.Mashup(false, project),
    17         mashup = new IriSP.Model.Mashup(false, project),
    28         mediatemplate = _.template(
    18         mediatemplate = _.template(
    29             '<li class="item-video media" data-media-id="<%= id %>"><div class="media-count-wrap"><span class="media-count"></span></div>'
    19             '<li class="item-video media" data-media-id="<%= id %>"><div class="media-count-wrap"><span class="media-count"></span></div>'
    30             + '<img class="thumbnail" src="<%= thumbnail %>" alt="<%= title %>" />'
    20             + '<img class="thumbnail" src="<%= thumbnail %>" alt="<%= title %>" />'
    31             + '<div class="video-info"><h3 class="title-video"><%= title %></h3><p class="description"><%= description %></p>'
    21             + '<div class="video-info"><h3 class="title-video"><%= title %></h3><p class="description"><%= description %></p>'
    32             + '<p class="time-length"><%= IriSP.hc_messages.Duration_ %> <span><%= duration.toString() %></span></p></div><div class="media-found-segments"></div></li>'
    22             + '<p class="time-length"><%= IriSP.translate("Duration:") %> <span><%= duration.toString() %></span></p></div><div class="media-found-segments"></div></li>'
    33         ),
    23         ),
    34         segmenttemplate = _.template(
    24         segmenttemplate = _.template(
    35             '<li class="item-video annotation" data-segment-id="<%= annotation.id %>" data-media-id="<%= annotation.getMedia().id %>">'
    25             '<li class="item-video annotation" data-segment-id="<%= annotation.id %>" data-media-id="<%= annotation.getMedia().id %>">'
    36             + '<img class="thumbnail" src="<%= annotation.thumbnail %>" alt="<%= annotation.getMedia().title %>" />'
    26             + '<img class="thumbnail" src="<%= annotation.thumbnail %>" alt="<%= annotation.getMedia().title %>" />'
    37             + '<div class="validate <%= annotation.status %>"><div class="validate-tooltip"><ul><li><%= annotation.status_messages.join("</li><li>") %></li></ul></div></div><div class="video-info"><h3 class="title-video"><%= annotation.getMedia().title %></h3>'
    27             + '<div class="validate <%= annotation.status %>"><div class="validate-tooltip"><ul><li><%= annotation.status_messages.join("</li><li>") %></li></ul></div></div><div class="video-info"><h3 class="title-video"><%= annotation.getMedia().title %></h3>'
    38             + '<p class="subtitle"><%= annotation.title %></p><p class="duration"><%= annotation.begin.toString() %> - <%= annotation.end.toString() %> (<%= annotation.getDuration().toString() %>)</p>'
    28             + '<p class="subtitle"><%= annotation.title %></p><p class="duration"><%= annotation.begin.toString() %> - <%= annotation.end.toString() %> (<%= annotation.getDuration().toString() %>)</p>'
    39             + '<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             + '<ul class="tools"><li><a class="edit" href="#" title="<%= IriSP.translate("Edit segment") %>"></a></li><li><a class="bottom" href="#" title="<%= IriSP.translate("Move segment down") %>"></a></li>'
    40             + '<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></div></li>'
    30             + '<li><a class="top" href="#" title="<%= IriSP.translate("Move segment up") %>"></a></li><li><a class="delete" href="#" title="<%= IriSP.translate("Delete segment") %>"></a></li></ul></div></li>'
    41         ),
    31         ),
    42         mediasegmenttemplate = _.template(
    32         mediasegmenttemplate = _.template(
    43             '<div class="media-segment">'
    33             '<div class="media-segment">'
    44             + '<div class="media-segment-section" style="left:<%= left %>px; width:<%= width %>px; background:<%= color %>; top: <%= top %>px;"></div>'
    34             + '<div class="media-segment-section" style="left:<%= left %>px; width:<%= width %>px; background:<%= color %>; top: <%= top %>px;" data-segment-id="<%= annotation.id %>"></div>'
    45             + '<div class="popin media-segment-popin" style="left:<%= popleft %>px; top: <%= 5+top %>px;"><img style="left:<%= pointerpos %>px;" class="pointer" src="img/popin-triangle.png" alt="" /><div class="popin-content">'
    35             + '<div class="popin media-segment-popin" style="left:<%= popleft %>px; top: <%= 5+top %>px;"><img style="left:<%= pointerpos %>px;" class="pointer" src="img/popin-triangle.png" alt="" /><div class="popin-content">'
    46             + '<h3><%= annotation.title %></h3><a href="#" class="button reprendre-segment" data-segment-id="<%= annotation.id %>"><%= IriSP.hc_messages.clone_segment %></a>'
    36             + '<h3><%= annotation.title %></h3><a href="#" class="button reprendre-segment" data-segment-id="<%= annotation.id %>"><%= IriSP.translate("Clone segment") %></a>'
    47             + '<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>'
    37             + '<p><%= IriSP.translate("From:") %> <span><%= annotation.begin.toString() %></span> <%= IriSP.translate("to:") %> <span><%= annotation.end.toString() %></span> (<%= IriSP.translate("duration:") %> <span><%= annotation.getDuration().toString() %></span>)</p>'
    48             + '</div></div></div>'
    38             + '</div></div></div>'
    49         ),
    39         ),
    50         mediasegmentlisttemplate = _.template(
    40         mediasegmentlisttemplate = _.template(
    51             '<div class="media-segment-list" style="height: <%= height %>px"><div class="media-current-section" style="left: <%= left %>px; width: <%= width %>px;"></div><div class="media-segment-list-inner"></div><%= segments %></div>'
    41             '<div class="media-segment-list" style="height: <%= height %>px"><div class="media-current-section" style="left: <%= left %>px; width: <%= width %>px;"></div><div class="media-segment-list-inner"></div><%= segments %></div>'
    52         ),
    42         ),
    53         mediafoundtemplate = _.template(
    43         mediafoundtemplate = _.template(
    54             '<div class="media-segment"><div class="media-segment-section" style="left:<%= left %>px; width:<%= width %>px; background:<%= color %>; top: <%= top %>px;"></div>'
    44             '<div class="media-segment"><div class="media-segment-section" style="left:<%= left %>px; width:<%= width %>px; background:<%= color %>; top: <%= top %>px;"></div>'
    55             + '<div class="popin media-found-popin" style="left:<%= popleft %>px; top: <%= 5+top %>px;"><img style="left:<%= pointerpos %>px;" class="pointer" src="img/popin-triangle.png" alt="" /><div class="popin-content">'
    45             + '<div class="popin media-found-popin" style="left:<%= popleft %>px; top: <%= 5+top %>px;"><img style="left:<%= pointerpos %>px;" class="pointer" src="img/popin-triangle.png" alt="" /><div class="popin-content">'
    56             + '<h3><%= title %></h3><a href="#" class="button clone-segment" data-segment-id="<%= annotation.id %>"><%= IriSP.hc_messages.clone_segment %></a>'
    46             + '<h3><%= title %></h3><a href="#" class="button clone-segment" data-segment-id="<%= annotation.id %>"><%= IriSP.translate("Clone segment") %></a>'
    57             + '</div></div></div>'
    47             + '</div></div></div>'
    58         ),
    48         ),
    59         mediafoundlisttemplate = _.template(
    49         mediafoundlisttemplate = _.template(
    60             '<div class="media-found-list" style="height: <%= height %>px"><div class="media-segment-list-inner"></div><%= segments %></div>'
    50             '<div class="media-found-list" style="height: <%= height %>px"><div class="media-segment-list-inner"></div><%= segments %></div>'
    61         ),
    51         ),
    71     var segmentcritical = [
    61     var segmentcritical = [
    72         {
    62         {
    73             validate: function(_s) {
    63             validate: function(_s) {
    74                 return (_s.getDuration() >= 1000);
    64                 return (_s.getDuration() >= 1000);
    75             },
    65             },
    76             message: "Le segment doit durer au moins une seconde"
    66             message: "A segment must be at least one second long"
    77         },
    67         },
    78         {
    68         {
    79             validate: function(_s) {
    69             validate: function(_s) {
    80                 return (_s.getDuration() < 180000);
    70                 return (_s.getDuration() < 180000);
    81             },
    71             },
    82             message: "Le segment doit durer moins de trois minutes"
    72             message: "A segment must be at most three minutes long"
    83         },
    73         },
    84         {
    74         {
    85             validate: function(_s) {
    75             validate: function(_s) {
    86                 return (!!_s.title && _s.title !== IriSP.hc_messages.segment_title_placeholder);
    76                 return (!!_s.title && _s.title !== IriSP.translate("Untitled segment"));
    87             },
    77             },
    88             message: "Le segment doit avoir un titre"
    78             message: "A segment must have a title"
    89         }
    79         }
    90     ];
    80     ];
    91     var segmentwarning = [
    81     var segmentwarning = [
    92         {
    82         {
    93             validate: function(_s) {
    83             validate: function(_s) {
    94                 return (!!_s.description);
    84                 return (!!_s.description);
    95             },
    85             },
    96             message: "Il est recommandé de donner une description au segment"
    86             message: "A segment should have a description"
    97         },
    87         },
    98         {
    88         {
    99             validate: function(_s) {
    89             validate: function(_s) {
   100                 return (!!_s.keywords.length);
    90                 return (!!_s.keywords.length);
   101             },
    91             },
   102             message: "Il est recommandé de tagguer le segment"
    92             message: "A segment should have tags"
   103         }
    93         }
   104     ];
    94     ];
   105     
    95     
   106     var mashupcritical = [
    96     var mashupcritical = [
   107         {
    97         {
   108             validate: function(_m) {
    98             validate: function(_m) {
   109                 return _m.segments.length > 2;
    99                 return _m.segments.length > 2;
   110             },
   100             },
   111             message: "Un hashcut doit être composé d'au moins trois segments"
   101             message: "A hashcut must be made from at least three segments"
   112         },
   102         },
   113         {
   103         {
   114             validate: function(_m) {
   104             validate: function(_m) {
   115                 return (!!_m.title && _m.title !== IriSP.hc_messages.mashup_title_placeholder);
   105                 return (!!_m.title && _m.title !== IriSP.translate("Untitled Hashcut"));
   116             },
   106             },
   117             message: "Un titre doit être donné au hashcut"
   107             message: "A hashcut must have a title"
   118         }
   108         }
   119     ];
   109     ];
   120     var mashupwarning = [
   110     var mashupwarning = [
   121         {
   111         {
   122             validate: function(_m) {
   112             validate: function(_m) {
   123                 return !!_m.description
   113                 return !!_m.description
   124             },
   114             },
   125             message: "Il est recommandé de donner une description au hashcut"
   115             message: "A hashcut should have a description"
   126         }
   116         }
   127     ];
   117     ];
   128 
   118 
   129     /* Fill left column with Media List */
   119     /* Fill left column with Media List */
   130 
   120 
   134             html += mediatemplate(_m);
   124             html += mediatemplate(_m);
   135         });
   125         });
   136         $(".col-left .list-video").html(html);
   126         $(".col-left .list-video").html(html);
   137         project.getMedias().forEach(function(_m) {
   127         project.getMedias().forEach(function(_m) {
   138             apidirectory.remoteSource({
   128             apidirectory.remoteSource({
   139                 url: options.segment_api_endpoint,
   129                 url: IriSP.endpoints.segment,
   140                 url_params: {
   130                 url_params: {
   141                     iri_id: _m.id,
   131                     iri_id: _m.id,
   142                     limit: 0
   132                     limit: 0
   143                 },
   133                 },
   144                 serializer: IriSP.serializers.segmentapi
   134                 serializer: IriSP.serializers.segmentapi
   236             if (_s.annotation.status === "critical") {
   226             if (_s.annotation.status === "critical") {
   237                 critical = true;
   227                 critical = true;
   238             }
   228             }
   239         });
   229         });
   240         if (critical) {
   230         if (critical) {
   241             messages.push("Certains segments ne sont pas valides");
   231             messages.push("One or more segments are invalid");
   242         }
   232         }
   243         
   233         
   244         _(mashupcritical).each(function(sc) {
   234         _(mashupcritical).each(function(sc) {
   245             if (!sc.validate(mashup)) {
   235             if (!sc.validate(mashup)) {
   246                 critical = true;
   236                 critical = true;
   253                 messages.push(sc.message);
   243                 messages.push(sc.message);
   254             }
   244             }
   255         });
   245         });
   256         mashup.status = critical ? "critical" : (warning ? "warning" : "valid");
   246         mashup.status = critical ? "critical" : (warning ? "warning" : "valid");
   257         if (!messages.length) {
   247         if (!messages.length) {
   258             messages.push("Le hashcut est valide !");
   248             messages.push("Your hashcut is valid!");
   259         }
   249         }
   260         mashupstatus = ' - ' + messages.join('\n - ');
   250         mashupstatus = ' - ' + _(messages).map(IriSP.translate).join('\n - ');
   261         
   251         
   262         $(".publier-button").toggleClass("disable", critical);
   252         $(".publier-button").toggleClass("disable", critical);
   263         
   253         
   264         $(".liste-segment .validate").removeClass("critical warning valid").addClass(mashup.status);
   254         $(".liste-segment .validate").removeClass("critical warning valid").addClass(mashup.status);
   265         $(".liste-segment .validate-tooltip").html("<ul><li>" + messages.join("</li><li>")+"</li></ul>");
   255         $(".liste-segment .validate-tooltip").html("<ul><li>" + messages.join("</li><li>")+"</li></ul>");
   358                     messages.push(sc.message);
   348                     messages.push(sc.message);
   359                 }
   349                 }
   360             });
   350             });
   361             currentSegment.status = critical ? "critical" : (warning ? "warning" : "valid");
   351             currentSegment.status = critical ? "critical" : (warning ? "warning" : "valid");
   362             if (!messages.length) {
   352             if (!messages.length) {
   363                 messages.push("Le segment est valide !")
   353                 messages.push("This segment is valid!")
   364             }
   354             }
   365             currentSegment.status_messages = messages;
   355             currentSegment.status_messages = _(messages).map(IriSP.translate);
   366             
   356             
   367             $(".segmentation .validate").removeClass("critical warning valid").addClass(currentSegment.status);
   357             $(".segmentation .validate").removeClass("critical warning valid").addClass(currentSegment.status);
   368             $(".segmentation .validate-tooltip").html("<ul><li>" + currentSegment.status_messages.join("</li><li>")+"</li></ul>");
   358             $(".segmentation .validate-tooltip").html("<ul><li>" + currentSegment.status_messages.join("</li><li>")+"</li></ul>");
   369         }
   359         }
   370     }
   360     }
   386             if (!currentSegment) {
   376             if (!currentSegment) {
   387                 currentSegment = new IriSP.Model.Annotation(false, project);
   377                 currentSegment = new IriSP.Model.Annotation(false, project);
   388                 currentSegment.setMedia(currentMedia.id);
   378                 currentSegment.setMedia(currentMedia.id);
   389                 currentSegment.setBegin(currentMedia.getCurrentTime());
   379                 currentSegment.setBegin(currentMedia.getCurrentTime());
   390                 currentSegment.setEnd(Math.min(currentMedia.getCurrentTime() +  180000, currentMedia.duration));
   380                 currentSegment.setEnd(Math.min(currentMedia.getCurrentTime() +  180000, currentMedia.duration));
   391                 currentSegment.title = IriSP.hc_messages.segment_title_placeholder;
   381                 currentSegment.title = IriSP.translate("Untitled segment");
   392                 currentSegment.color = currentMedia.color;
   382                 currentSegment.color = currentMedia.color;
   393                 currentSegment.thumbnail = currentMedia.thumbnail;
   383                 currentSegment.thumbnail = currentMedia.thumbnail;
   394                 currentSegment.created = new Date();
   384                 currentSegment.created = new Date();
   395                 currentSegment.keywords = [];
   385                 currentSegment.keywords = [];
   396                 currentSegment.description = "";
   386                 currentSegment.description = "";
   408                 });
   398                 });
   409             }
   399             }
   410             if (currentMedia.loaded) {
   400             if (currentMedia.loaded) {
   411                 currentMedia.setCurrentTime(currentSegment.begin);
   401                 currentMedia.setCurrentTime(currentSegment.begin);
   412             }
   402             }
   413             $(".add-segment").val(addMode ? "Ajouter au Hashcut" : "Sauvegarder");
   403             $(".add-segment").val(IriSP.translate(addMode ? "Add segment to hashcut" : "Save segment"));
   414             $(".create-or-edit").text(addMode ? "Créer un nouveau segment" : "Modifier le segment");
   404             $(".create-or-edit").text(IriSP.translate(addMode ? "Create new segment" : "Edit existing segment"));
   415             media.show();
   405             media.show();
   416             $("#segment-title").val(currentSegment.title);
   406             $("#segment-title").val(currentSegment.title);
   417             $("#segment-description").val(currentSegment.description);
   407             $("#segment-description").val(currentSegment.description);
   418             var segment_tags = $("#segment-tags");
   408             var segment_tags = $("#segment-tags");
   419             segment_tags.tagit("option","onTagRemoved",function(){});
   409             segment_tags.tagit("option","onTagRemoved",function(){});
   512             updateSegmentUI();
   502             updateSegmentUI();
   513             mashup.trigger("change");
   503             mashup.trigger("change");
   514         }
   504         }
   515     });
   505     });
   516     $("#segment-title").on("focus click", function() {
   506     $("#segment-title").on("focus click", function() {
   517         if ($(this).val() === IriSP.hc_messages.segment_title_placeholder) {
   507         if ($(this).val() === IriSP.translate("Untitled segment")) {
   518             $(this).val("");
   508             $(this).val("");
   519         }
   509         }
   520     });
   510     });
   521     $("#segment-description").on("keyup change input paste", function() {
   511     $("#segment-description").on("keyup change input paste", function() {
   522         if (currentMedia && currentSegment) {
   512         if (currentMedia && currentSegment) {
   529             mashup.addAnnotation(currentSegment);
   519             mashup.addAnnotation(currentSegment);
   530             currentSegment = undefined;
   520             currentSegment = undefined;
   531             setMedia(currentMedia);
   521             setMedia(currentMedia);
   532         } else {
   522         } else {
   533             mashup.trigger("change");
   523             mashup.trigger("change");
       
   524             var segment = mashup.getAnnotation(currentSegment);
   534             currentSegment = undefined;
   525             currentSegment = undefined;
   535             setMedia(mashup);
   526             setMedia(mashup);
   536             if (segment) {
   527             if (segment) {
   537                 mashup.setCurrentTime(segment.begin);
   528                 mashup.setCurrentTime(segment.begin);
   538                 mashup.trigger("enter-annotation",segment);
   529                 mashup.trigger("enter-annotation",segment);
   733         
   724         
   734         currentSegment = new IriSP.Model.Annotation(false, project);
   725         currentSegment = new IriSP.Model.Annotation(false, project);
   735         currentSegment.setMedia(media.id);
   726         currentSegment.setMedia(media.id);
   736         currentSegment.setBegin(s.begin);
   727         currentSegment.setBegin(s.begin);
   737         currentSegment.setEnd(s.end);
   728         currentSegment.setEnd(s.end);
   738         currentSegment.title = IriSP.hc_messages.copy_of_ + s.title;
   729         currentSegment.title = IriSP.translate("Copy of ") + s.title;
   739         currentSegment.description = s.description;
   730         currentSegment.description = s.description;
   740         currentSegment.keywords = s.keywords;
   731         currentSegment.keywords = s.keywords;
   741         currentSegment.color = media.color;
   732         currentSegment.color = media.color;
   742         currentSegment.thumbnail = media.thumbnail;
   733         currentSegment.thumbnail = media.thumbnail;
   743         currentSegment.created = new Date();
   734         currentSegment.created = new Date();
   761     }).on("mouseout", ".media-segment", function() {
   752     }).on("mouseout", ".media-segment", function() {
   762         $(this).find(".media-segment-popin").hide();
   753         $(this).find(".media-segment-popin").hide();
   763     }).on("click", ".reprendre-segment", function() {
   754     }).on("click", ".reprendre-segment", function() {
   764         cloneSegment($(this).attr("data-segment-id"));
   755         cloneSegment($(this).attr("data-segment-id"));
   765         return false;
   756         return false;
       
   757     }).on("click", ".media-segment-section", function() {
       
   758         var sid = $(this).attr("data-segment-id"),
       
   759             s = directory.getElement(sid) || apidirectory.getElement(sid);
       
   760         if (s.media.id === currentMedia.id) {
       
   761             currentMedia.setCurrentTime(s.begin);
       
   762         }
   766     });
   763     });
   767     
   764     
   768     $(".col-left").on("mouseover", ".media-segment", function() {
   765     $(".col-left").on("mouseover", ".media-segment", function() {
   769         $(this).find(".media-found-popin").show();
   766         $(this).find(".media-found-popin").show();
   770     }).on("mouseout", ".media-segment", function() {
   767     }).on("mouseout", ".media-segment", function() {
   773         cloneSegment($(this).attr("data-segment-id"));
   770         cloneSegment($(this).attr("data-segment-id"));
   774         return false;
   771         return false;
   775     });
   772     });
   776     /* Changing Hashcut Title and description */
   773     /* Changing Hashcut Title and description */
   777     
   774     
   778     mashup.title = IriSP.hc_messages.mashup_title_placeholder;
   775     mashup.title = IriSP.translate("Untitled Hashcut");
   779     $(".title-video-wrap a").text(mashup.title);
   776     $(".title-video-wrap a").text(mashup.title);
   780     $("#hashcut-title").val(mashup.title);
   777     $("#hashcut-title").val(mashup.title);
   781     
   778     
   782     $("#hashcut-title").on("keyup change input paste", function() {
   779     $("#hashcut-title").on("keyup change input paste", function() {
   783         mashup.title = $(this).val();
   780         mashup.title = $(this).val();
   784         $(".title-video-wrap a").text(mashup.title);
   781         $(".title-video-wrap a").text(mashup.title);
   785         mashup.trigger("change");
   782         mashup.trigger("change");
   786     });
   783     });
   787     $("#hashcut-title").on("focus click", function() {
   784     $("#hashcut-title").on("focus click", function() {
   788         if ($(this).val() === IriSP.hc_messages.mashup_title_placeholder) {
   785         if ($(this).val() === IriSP.translate("Untitled Hashcut")) {
   789             $(this).val("");
   786             $(this).val("");
   790         }
   787         }
   791     });
   788     });
   792     
   789     
   793     $("#hashcut-description").on("keyup change input paste", function() {
   790     $("#hashcut-description").on("keyup change input paste", function() {
   800         return false;
   797         return false;
   801     })
   798     })
   802     
   799     
   803     /* Publication */
   800     /* Publication */
   804    
   801    
       
   802     function onLeave() {
       
   803         return IriSP.translate("You haven't published your hashcut yet.\nIf you leave this page, it will be lost");
       
   804     }
       
   805     
       
   806     $(window).on("beforeunload", onLeave);
       
   807    
   805     $(".publier-button").click(function() {
   808     $(".publier-button").click(function() {
   806         if ($(this).hasClass("disable")) {
   809         if ($(this).hasClass("disable")) {
   807             alert("Le Mashup ne peut pas être publié pour les raisons suivantes :\n\n"+mashupstatus);
   810             alert(IriSP.translate("The mashup can't be published because:")+"\n\n"+mashupstatus);
   808             return false;
   811             return false;
   809         }
   812         }
   810         var postproject = directory.newLocalSource(),
   813         var postproject = directory.newLocalSource(),
   811             medias = mashup.getMedias()
   814             medias = mashup.getMedias()
   812             annotations = mashup.getOriginalAnnotations();
   815             annotations = mashup.getOriginalAnnotations();
   845         postproject.modified = new Date();
   848         postproject.modified = new Date();
   846         postproject.title = mashup.title;
   849         postproject.title = mashup.title;
   847         postproject.description = mashup.description;
   850         postproject.description = mashup.description;
   848         $.ajax({
   851         $.ajax({
   849             type: "POST",
   852             type: "POST",
   850             url: options.project_api_endpoint,
   853             url: IriSP.endpoints.project,
   851             data: IriSP.serializers.ldt.serialize(postproject),
   854             data: IriSP.serializers.ldt.serialize(postproject),
   852             contentType: "application/cinelab",
   855             contentType: "application/cinelab",
   853 //            headers: {"X-CSRFToken": "{{csrf_token}}"},
   856 //            headers: {"X-CSRFToken": "{{csrf_token}}"},
   854             success: function(data, status, request){
   857             success: function(data, status, request){
   855                 console.log(request.getResponseHeader("Location"));
   858                 var location = request.getResponseHeader("Location"),
       
   859                     projid = location.match(/([^/]+)\/?$/)[1],
       
   860                     destination = IriSP.endpoints.hashcut_page + projid;
       
   861                 $(window).off("beforeunload", onLeave);
       
   862                 document.location.href = destination;
   856             },
   863             },
   857             error: function(jqXHR, textStatus, errorThrown){
   864             error: function(jqXHR, textStatus, errorThrown){
   858                 alert(errorThrown);
   865                 console.log(arguments);
   859             }
   866                 alert(IriSP.translate("Server error\nYour hashcut couldn't be published"));
   860         });
   867             }
       
   868         });
       
   869         //TODO: ADD WAITING SCREEN
       
   870         
   861         return false;
   871         return false;
   862     });
   872     });
   863     
   873     
   864     mashup.trigger("change");
   874     mashup.trigger("change");
   865 }
   875 }