src/widgets/CreateAnnotation.js
changeset 1068 7623f9af9272
parent 1067 539c9bee5372
child 1069 2409cb4cebaf
equal deleted inserted replaced
1067:539c9bee5372 1068:7623f9af9272
     1 /* TODO: Add Social Network Sharing */
     1 /* TODO: Add Social Network Sharing */
     2 
     2 
     3 IriSP.Widgets.CreateAnnotation = function(player, config) {
     3 IriSP.Widgets.CreateAnnotation = function(player, config) {
     4     IriSP.Widgets.Widget.call(this, player, config);
     4     IriSP.Widgets.Widget.call(this, player, config);
       
     5     if (_this.editable_storage != '' && window.localStorage[_this.editable_storage]) {
       
     6         this.source.onLoad(function () {
       
     7             var _export = _this.player.sourceManager.newLocalSource({serializer: IriSP.serializers['ldt_localstorage']});
       
     8             _export.deSerialize(window.localStorage[_this.editable_storage]);
       
     9             _this.source.merge(_export);
       
    10         });
       
    11     };
     5 };
    12 };
     6 
    13 
     7 IriSP.Widgets.CreateAnnotation.prototype = new IriSP.Widgets.Widget();
    14 IriSP.Widgets.CreateAnnotation.prototype = new IriSP.Widgets.Widget();
     8 
    15 
     9 IriSP.Widgets.CreateAnnotation.prototype.defaults = {
    16 IriSP.Widgets.CreateAnnotation.prototype.defaults = {
    46     post_at_segment_time: false,
    53     post_at_segment_time: false,
    47     segment_annotation_type: "chap",
    54     segment_annotation_type: "chap",
    48     api_serializer: "ldt_annotate",
    55     api_serializer: "ldt_annotate",
    49     api_endpoint_template: "",
    56     api_endpoint_template: "",
    50     api_method: "POST",
    57     api_method: "POST",
       
    58     // Id that will be used as localStorage key
       
    59     editable_storage: "",
    51     project_id: "",
    60     project_id: "",
    52     after_send_timeout: 0,
    61     after_send_timeout: 0,
    53     close_after_send: false,
    62     close_after_send: false,
    54     tag_prefix: "#",
    63     tag_prefix: "#",
    55     pause_when_displaying: false,
    64     pause_when_displaying: false,
    67         preview_submit: "You cannot submit annotations in preview mode",
    76         preview_submit: "You cannot submit annotations in preview mode",
    68         cancel: "Cancel",
    77         cancel: "Cancel",
    69         add_keywords_: "Add keywords:",
    78         add_keywords_: "Add keywords:",
    70         add_polemic_keywords_: "Add polemic attributes :",
    79         add_polemic_keywords_: "Add polemic attributes :",
    71         your_name_: "Your name:",
    80         your_name_: "Your name:",
    72         annotate_video: "Annotate this video",
    81         annotate_video: "New note",
    73         type_title: "Annotation title",
    82         type_title: "Annotation title",
    74         type_description: "Type the full contents of your annotation here.",
    83         type_description: "Enter a new note...",
    75         wait_while_processing: "Please wait while your annotation is being processed...",
    84         wait_while_processing: "Please wait while your annotation is being processed...",
    76         error_while_contacting: "An error happened while contacting the server. Your annotation has not been saved.",
    85         error_while_contacting: "An error happened while contacting the server. Your annotation has not been saved.",
    77         annotation_saved: "Thank you, your annotation has been saved.",
    86         annotation_saved: "Thank you, your annotation has been saved.",
    78         share_annotation: "Would you like to share it on social networks ?",
    87         share_annotation: "Would you like to share it on social networks ?",
    79         close_widget: "Hide the annotation form",
    88         close_widget: "Hide the annotation form",
    80         "polemic++": "Agree",
    89         "polemic++": "Agree",
    81         "polemic--": "Disagree",
    90         "polemic--": "Disagree",
    82         "polemic??": "Question",
    91         "polemic??": "Question",
    83         "polemic==": "Reference"
    92         "polemic==": "Reference",
       
    93         "in_tooltip": "Set begin time to current player time",
       
    94         "out_tooltip": "Set begin time to current player time",
       
    95         "play_tooltip": "Play the fragment"
    84     },
    96     },
    85     fr: {
    97     fr: {
    86         from_time: "de",
    98         from_time: "de",
    87         to_time: "à",
    99         to_time: "à",
    88         at_time: "à",
   100         at_time: "à",
    90         preview_submit: "Vous ne pouvez pas envoyer d'annotation en mode aperçu",
   102         preview_submit: "Vous ne pouvez pas envoyer d'annotation en mode aperçu",
    91         cancel: "Annuler",
   103         cancel: "Annuler",
    92         add_keywords_: "Ajouter des mots-clés\u00a0:",
   104         add_keywords_: "Ajouter des mots-clés\u00a0:",
    93         add_polemic_keywords_: "Ajouter des attributs polémiques\u00a0:",
   105         add_polemic_keywords_: "Ajouter des attributs polémiques\u00a0:",
    94         your_name_: "Votre nom\u00a0:",
   106         your_name_: "Votre nom\u00a0:",
    95         annotate_video: "Annoter cette vidéo",
   107         annotate_video: "Entrez une nouvelle note...",
    96         type_title: "Titre de l'annotation",
   108         type_title: "Titre de l'annotation",
    97         type_description: "Rédigez ici le contenu de votre annotation.",
   109         type_description: "Prenez vos notes...",
    98         wait_while_processing: "Veuillez patienter pendant le traitement de votre annotation...",
   110         wait_while_processing: "Veuillez patienter pendant le traitement de votre annotation...",
    99         error_while_contacting: "Une erreur s'est produite en contactant le serveur. Votre annotation n'a pas été enregistrée.",
   111         error_while_contacting: "Une erreur s'est produite en contactant le serveur. Votre annotation n'a pas été enregistrée.",
   100         annotation_saved: "Merci, votre annotation a été enregistrée.",
   112         annotation_saved: "Merci, votre annotation a été enregistrée.",
   101         share_annotation: "Souhaitez-vous la partager sur les réseaux sociaux ?",
   113         share_annotation: "Souhaitez-vous la partager sur les réseaux sociaux ?",
   102         close_widget: "Cacher le formulaire de création d'annotations",
   114         close_widget: "Cacher le formulaire de création d'annotations",
   103         "polemic++": "Accord",
   115         "polemic++": "Accord",
   104         "polemic--": "Désaccord",
   116         "polemic--": "Désaccord",
   105         "polemic??": "Question",
   117         "polemic??": "Question",
   106         "polemic==": "Référence"
   118         "polemic==": "Référence",
       
   119         "in_tooltip": "Utiliser le temps courant comme début",
       
   120         "out_tooltip": "Utiliser le temps courant comme fin",
       
   121         "play_tooltip": "Jouer le fragment"
   107     }
   122     }
   108 };
   123 };
   109 
   124 
   110 IriSP.Widgets.CreateAnnotation.prototype.template =
   125 IriSP.Widgets.CreateAnnotation.prototype.template =
   111     '{{#show_slice}}<div class="Ldt-CreateAnnotation-Slice"></div>{{/show_slice}}'
   126     '{{#show_slice}}<div class="Ldt-CreateAnnotation-Slice Ldt-TraceMe"></div>{{/show_slice}}'
   112     + '{{^show_slice}}{{#show_arrow}}<div class="Ldt-CreateAnnotation-Arrow"></div>{{/show_arrow}}{{/show_slice}}'
   127     + '{{^show_slice}}{{#show_arrow}}<div class="Ldt-CreateAnnotation-Arrow"></div>{{/show_arrow}}{{/show_slice}}'
   113     + '<div class="Ldt-CreateAnnotation"><div class="Ldt-CreateAnnotation-Inner">'
   128     + '<div class="Ldt-CreateAnnotation"><div class="Ldt-CreateAnnotation-Inner">'
   114     + '<form class="Ldt-CreateAnnotation-Screen Ldt-CreateAnnotation-Main">'
   129     + '<form class="Ldt-CreateAnnotation-Screen Ldt-CreateAnnotation-Main">'
   115     + '<h3><span class="Ldt-CreateAnnotation-h3Left">{{l10n.annotate_video}}{{#show_title_field}}</span></h3>'
   130     + '<h3><span class="Ldt-CreateAnnotation-h3Left">{{l10n.annotate_video}}{{#show_title_field}}</span></h3>'
   116     + '<h3><span class="Ldt-CreateAnnotation-h3Left"><input class="Ldt-CreateAnnotation-Title empty" placeholder="{{l10n.type_title}}" />{{/show_title_field}}'
   131     + '<h3><span class="Ldt-CreateAnnotation-h3Left"><input class="Ldt-CreateAnnotation-Title empty" placeholder="{{l10n.type_title}}" />{{/show_title_field}}'
   117     + '{{#show_time}}<span class="Ldt-CreateAnnotation-Times"> {{#show_slice}}{{l10n.from_time}} {{/show_slice}}{{^show_slice}}{{l10n.at_time}} {{/show_slice}} <span class="Ldt-CreateAnnotation-Begin">00:00</span>{{/show_time}}'
   132     + '{{#show_time}}<span class="Ldt-CreateAnnotation-Times"> {{#show_slice}}{{l10n.from_time}} {{/show_slice}}{{^show_slice}}{{l10n.at_time}} {{/show_slice}} <span class="Ldt-CreateAnnotation-Begin">00:00</span>{{/show_time}}'
   118     + '{{#show_slice}} {{l10n.to_time}} <span class="Ldt-CreateAnnotation-End">{{end}}</span>{{/show_slice}}</span></span>'
   133     + '{{#show_slice}} {{l10n.to_time}} <span class="Ldt-CreateAnnotation-End">{{end}}</span>{{/show_slice}}</span></span>'
   119     + '{{#show_creator_field}}{{l10n.your_name_}} <input class="Ldt-CreateAnnotation-Creator empty" value="{{creator_name}}" {{#creator_field_readonly}}readonly{{/creator_field_readonly}}/>{{/show_creator_field}}</h3>'
   134     + '{{#show_creator_field}}{{l10n.your_name_}} <input class="Ldt-CreateAnnotation-Creator empty" value="{{creator_name}}" {{#creator_field_readonly}}readonly{{/creator_field_readonly}}/>{{/show_creator_field}}</h3>'
   120     + '<textarea class="Ldt-CreateAnnotation-Description empty" placeholder="{{l10n.type_description}}"></textarea>'
   135     + '{{#show_controls}}<div class="Ldt-CreateAnnotation-Controls">'
   121     + '<div class="Ldt-CreateAnnotation-Avatar"><img src="{{creator_avatar}}" title="{{creator_name}}"></img></div>'
   136     +   '<span title="{{l10n.in_tooltip}}" class="Ldt-CreateAnnotation-Control-In">In</span>'
       
   137     +   '<span title="{{l10n.out_tooltip}}" class="Ldt-CreateAnnotation-Control-Out">Out</span>'
       
   138     +   '<span title="{{l10n.play_tooltip}}" class="Ldt-CreateAnnotation-Control-Play">Play</span>'
       
   139     + '</div>{{/show_controls}}'
       
   140     + '<textarea class="Ldt-CreateAnnotation-Description Ldt-TraceMe empty" placeholder="{{l10n.type_description}}"></textarea>'
       
   141     + '{{#show_creator_field}}<div class="Ldt-CreateAnnotation-Avatar"><img src="{{creator_avatar}}" title="{{creator_name}}"></img></div>{{/show_creator_field}}'
       
   142     + '<div class="Ldt-CreateAnnotation-SubmitArea Ldt-TraceMe">'
   122     + '{{#preview_mode}}<input type="button" class="Ldt-CreateAnnotation-PreviewSubmit" title="{{l10n.preview_submit}}" value="{{#custom_send_button}}{{custom_send_button}}{{/custom_send_button}}{{^custom_send_button}}{{l10n.submit}}{{/custom_send_button}}" />{{/preview_mode}}'
   143     + '{{#preview_mode}}<input type="button" class="Ldt-CreateAnnotation-PreviewSubmit" title="{{l10n.preview_submit}}" value="{{#custom_send_button}}{{custom_send_button}}{{/custom_send_button}}{{^custom_send_button}}{{l10n.submit}}{{/custom_send_button}}" />{{/preview_mode}}'
   123     + '{{^preview_mode}}<input type="submit" class="Ldt-CreateAnnotation-Submit" value="{{#custom_send_button}}{{custom_send_button}}{{/custom_send_button}}{{^custom_send_button}}{{l10n.submit}}{{/custom_send_button}}" />{{/preview_mode}}'
   144     + '{{^preview_mode}}<input type="submit" class="Ldt-CreateAnnotation-Submit" value="{{#custom_send_button}}{{custom_send_button}}{{/custom_send_button}}{{^custom_send_button}}{{l10n.submit}}{{/custom_send_button}}" />{{/preview_mode}}'
   124     + '<input type="button" class="Ldt-CreateAnnotation-Cancel" value="{{#custom_cancel_button}}{{custom_cancel_button}}{{/custom_cancel_button}}{{^custom_cancel_button}}{{l10n.cancel}}{{/custom_cancel_button}}" />'
   145     + '<input type="button" class="Ldt-CreateAnnotation-Cancel" value="{{#custom_cancel_button}}{{custom_cancel_button}}{{/custom_cancel_button}}{{^custom_cancel_button}}{{l10n.cancel}}{{/custom_cancel_button}}" />'
       
   146     +   '<div class="Ldt-CreateAnnotation-Begin Ldt-CreateAnnotation-Times">00:00</div>'
       
   147     + '</div>'
   125     + '{{#show_mic_record}}<div class="Ldt-CreateAnnotation-RecBlock"><div class="Ldt-CreateAnnotation-RecLabel">Add voice annotation</div>'
   148     + '{{#show_mic_record}}<div class="Ldt-CreateAnnotation-RecBlock"><div class="Ldt-CreateAnnotation-RecLabel">Add voice annotation</div>'
   126     + '    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="220" height="160">'
   149     + '    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="220" height="160">'
   127     + '        <param name="movie" value="{{record_swf}}" />'
   150     + '        <param name="movie" value="{{record_swf}}" />'
   128     + '        <param name="quality" value="high" />'
   151     + '        <param name="quality" value="high" />'
   129     + '        <param name="bgcolor" value="#ffffff" />'
   152     + '        <param name="bgcolor" value="#ffffff" />'
   210             {
   233             {
   211                 type: "Slice",
   234                 type: "Slice",
   212                 show_arrow: this.show_arrow,
   235                 show_arrow: this.show_arrow,
   213                 annotation_type: this.slice_annotation_type,
   236                 annotation_type: this.slice_annotation_type,
   214                 onBoundsChanged: function(_from, _to) {
   237                 onBoundsChanged: function(_from, _to) {
   215                     _this.begin = new IriSP.Model.Time(_from || 0);
   238                     this.setBeginEnd(_from, _to);
   216                     _this.end = new IriSP.Model.Time(_to || 0);
       
   217                     _this.$.find(".Ldt-CreateAnnotation-Begin").html(_this.begin.toString());
       
   218                     _this.$.find(".Ldt-CreateAnnotation-End").html(_this.end.toString());
       
   219                 }
   239                 }
   220             },
   240             },
   221             "slice"
   241             "slice"
   222         );
   242         );
   223     } else {
   243     } else {
   224         if (this.show_arrow) {
   244         if (this.show_arrow) {
   225             this.insertSubwidget(this.$.find(".Ldt-CreateAnnotation-Arrow"), {type: "Arrow"},"arrow");
   245             this.insertSubwidget(this.$.find(".Ldt-CreateAnnotation-Arrow"), {type: "Arrow"},"arrow");
   226         }
   246         }
   227         this.onMediaEvent("timeupdate", function(_time) {
   247         this.onMediaEvent("timeupdate", function(_time) {
   228             _this.begin = new IriSP.Model.Time(_time || 0);
   248             // Do not update timecode if description is not empty
   229             _this.end = new IriSP.Model.Time(_time || 0);
   249             if (_this.$.find(".Ldt-CreateAnnotation-Description").val().trim() == "") {
   230             _this.$.find(".Ldt-CreateAnnotation-Begin").html(_this.begin.toString());
   250                 _this.setBeginEnd(_time, _time);
   231             if (_this.arrow) {
   251                 if (_this.arrow) {
   232                 _this.arrow.moveToTime(_time);
   252                     _this.arrow.moveToTime(_time);
   233             }
   253                 }
       
   254             };
   234         });
   255         });
   235     }
   256     }
   236     this.$.find(".Ldt-CreateAnnotation-Cancel").click(function() {
   257     this.$.find(".Ldt-CreateAnnotation-Cancel").click(function() {
   237         _this.player.trigger("CreateAnnotation.hide");
   258         _this.player.trigger("CreateAnnotation.hide");
   238     });
   259     });
   259         this.$.find(".Ldt-CreateAnnotation-Title").bind("change keyup input paste", this.functionWrapper("onTitleChange"));
   280         this.$.find(".Ldt-CreateAnnotation-Title").bind("change keyup input paste", this.functionWrapper("onTitleChange"));
   260     }
   281     }
   261     if (this.show_creator_field) {
   282     if (this.show_creator_field) {
   262         this.$.find(".Ldt-CreateAnnotation-Creator").bind("change keyup input paste", this.functionWrapper("onCreatorChange"));
   283         this.$.find(".Ldt-CreateAnnotation-Creator").bind("change keyup input paste", this.functionWrapper("onCreatorChange"));
   263     }
   284     }
   264     
   285     this.$.find("[class^='Ldt-CreateAnnotation-Control-']").click(function() {
       
   286         var action = this.className.replace('Ldt-CreateAnnotation-Control-', '');
       
   287         switch (action) {
       
   288             case "In":
       
   289                // Set In bound to current player time
       
   290                this.setBegin(_this.media.getCurrentTime());
       
   291                break;
       
   292             case "Out":
       
   293                // Set In bound to current player time
       
   294                this.setEnd(_this.media.getCurrentTime() || _this.media.duration);
       
   295                break;
       
   296             case "Play":
       
   297                this.media.setCurrentTime(_this.begin);
       
   298                this.media.play();
       
   299                break;
       
   300         }
       
   301         return false;
       
   302     });
       
   303 
   265     if (this.start_visible) {
   304     if (this.start_visible) {
   266         this.show();
   305         this.show();
   267     } else {
   306     } else {
   268         this.$.hide();
   307         this.$.hide();
   269         this.hide();
   308         this.hide();
   273     this.onMdpEvent("CreateAnnotation.hide", "hide");
   312     this.onMdpEvent("CreateAnnotation.hide", "hide");
   274     this.onMdpEvent("CreateAnnotation.show", "show");
   313     this.onMdpEvent("CreateAnnotation.show", "show");
   275     this.$.find("form").submit(this.functionWrapper("onSubmit"));
   314     this.$.find("form").submit(this.functionWrapper("onSubmit"));
   276 };
   315 };
   277 
   316 
       
   317 IriSP.Widgets.CreateAnnotation.prototype.setBegin = function (t) {
       
   318     this.begin = new IriSP.Model.Time(t || 0);
       
   319     this.$.find(".Ldt-CreateAnnotation-Begin").html(this.begin.toString());
       
   320 };
       
   321 
       
   322 IriSP.Widgets.CreateAnnotation.prototype.setEnd = function (t) {
       
   323     this.end = new IriSP.Model.Time(t || 0);
       
   324     this.$.find(".Ldt-CreateAnnotation-End").html(this.end.toString());
       
   325 };
       
   326 
       
   327 IriSP.Widgets.CreateAnnotation.prototype.setBeginEnd = function (begin, end) {
       
   328     this.setBegin(begin);
       
   329     this.setEnd(end);
       
   330 };
       
   331 
   278 IriSP.Widgets.CreateAnnotation.prototype.showScreen = function(_screenName) {
   332 IriSP.Widgets.CreateAnnotation.prototype.showScreen = function(_screenName) {
   279     this.$.find('.Ldt-CreateAnnotation-' + _screenName).show()
   333     this.$.find('.Ldt-CreateAnnotation-' + _screenName).show()
   280         .siblings().hide();
   334         .siblings().hide();
   281 }
   335 };
   282 
   336 
   283 IriSP.Widgets.CreateAnnotation.prototype.show = function() {
   337 IriSP.Widgets.CreateAnnotation.prototype.show = function() {
   284     if (!this.visible){
   338     if (!this.visible){
   285         this.visible = true;
   339         this.visible = true;
   286         if (this.pause_when_displaying){
   340         if (this.pause_when_displaying){
   323 IriSP.Widgets.CreateAnnotation.prototype.toggle = function() {
   377 IriSP.Widgets.CreateAnnotation.prototype.toggle = function() {
   324     if (!this.always_visible) {
   378     if (!this.always_visible) {
   325         if (this.visible) {
   379         if (this.visible) {
   326             this.hide();
   380             this.hide();
   327         } else {
   381         } else {
       
   382             var t = _this.media.getCurrentTime() || 0;
       
   383             _this.setBeginEnd(t, t);
       
   384             if (_this.slice_widget) {
       
   385                 _this.slice_widget.setBounds(_this.begin, _this.end);
       
   386             }
   328             this.show();
   387             this.show();
       
   388             // Set focus on textarea
       
   389             _this.$.find(".Ldt-CreateAnnotation-Description").focus();
   329         }
   390         }
   330     }
   391     }
   331 };
   392 };
   332 
   393 
   333 IriSP.Widgets.CreateAnnotation.prototype.addKeyword = function(_keyword) {
   394 IriSP.Widgets.CreateAnnotation.prototype.addKeyword = function(_keyword) {
   346     if (this.pause_on_write && !this.media.getPaused()) {
   407     if (this.pause_on_write && !this.media.getPaused()) {
   347         this.media.pause();
   408         this.media.pause();
   348     }
   409     }
   349 };
   410 };
   350 
   411 
   351 IriSP.Widgets.CreateAnnotation.prototype.onDescriptionChange = function() {
   412 IriSP.Widgets.CreateAnnotation.prototype.onDescriptionChange = function(e) {
       
   413     if (e !== undefined && e.keyCode == 13 && !e.shiftKey) {
       
   414         // Return: submit. Use shift-Return to insert a LF
       
   415         this.onSubmit();
       
   416         return true;
       
   417     }
   352     var _field = this.$.find(".Ldt-CreateAnnotation-Description"),
   418     var _field = this.$.find(".Ldt-CreateAnnotation-Description"),
   353         _contents = _field.val();
   419         _contents = _field.val();
   354     _field.css("border-color", !!_contents ? "#666666" : "#ff0000");
   420     _field.css("border-color", !!_contents ? "#666666" : "#ff0000");
   355     if (!!_contents) {
   421     if (!!_contents) {
   356         _field.removeClass("empty");
   422         _field.removeClass("empty");
   407     }
   473     }
   408     
   474     
   409     var _this = this,
   475     var _this = this,
   410         _exportedAnnotations = new IriSP.Model.List(this.player.sourceManager), /* We create a List to send to the server that will contains the annotation */
   476         _exportedAnnotations = new IriSP.Model.List(this.player.sourceManager), /* We create a List to send to the server that will contains the annotation */
   411         _export = this.player.sourceManager.newLocalSource({serializer: IriSP.serializers[this.api_serializer]}), /* We create a source object using a specific serializer for export */
   477         _export = this.player.sourceManager.newLocalSource({serializer: IriSP.serializers[this.api_serializer]}), /* We create a source object using a specific serializer for export */
       
   478         _local_export = this.player.sourceManager.newLocalSource({serializer: IriSP.serializers['ldt_localstorage']}), /* Source object using a specific serializer for local export */
   412         _annotation = new IriSP.Model.Annotation(false, _export), /* We create an annotation in the source with a generated ID (param. false) */
   479         _annotation = new IriSP.Model.Annotation(false, _export), /* We create an annotation in the source with a generated ID (param. false) */
   413         _annotationTypes = this.source.getAnnotationTypes().searchByTitle(this.annotation_type, true), /* We get the AnnotationType in which the annotation will be added */
   480         _annotationTypes = this.source.getAnnotationTypes().searchByTitle(this.annotation_type, true), /* We get the AnnotationType in which the annotation will be added */
   414         _annotationType = (_annotationTypes.length ? _annotationTypes[0] : new IriSP.Model.AnnotationType(false, _export)), /* If it doesn't already exists, we create it */
   481         _annotationType = (_annotationTypes.length ? _annotationTypes[0] : new IriSP.Model.AnnotationType(false, _export)), /* If it doesn't already exists, we create it */
   415         _url = Mustache.to_html(this.api_endpoint_template, {id: this.source.projectId}); /* We make the url to send the request to, must include project id */
   482         _url = Mustache.to_html(this.api_endpoint_template, {id: this.source.projectId}); /* We make the url to send the request to, must include project id */
   416     
   483     
   442             _annotation.setBegin(_currentSegments[0].begin); /* Segment starting timecode */
   509             _annotation.setBegin(_currentSegments[0].begin); /* Segment starting timecode */
   443             _annotation.setEnd(_currentSegments[0].end); /* Segment end timecode */
   510             _annotation.setEnd(_currentSegments[0].end); /* Segment end timecode */
   444         }
   511         }
   445     }
   512     }
   446     else {
   513     else {
   447         _annotation.setBegin(this.begin); /* Widget starting timecode */
   514         _annotation.setBeginEnd(this.begin, this.end); /* Widget end/start timecodes */
   448         _annotation.setEnd(this.end); /* Widget end timecode */
       
   449     }
   515     }
   450     _annotation.setAnnotationType(_annotationType.id); /* Annotation type ID */
   516     _annotation.setAnnotationType(_annotationType.id); /* Annotation type ID */
   451     if (this.show_title_field) {
   517     if (this.show_title_field) {
   452         /* Title field, only if it's visible */
   518         /* Title field, only if it's visible */
   453         _annotation.title = this.$.find(".Ldt-CreateAnnotation-Title").val();
   519         _annotation.title = this.$.find(".Ldt-CreateAnnotation-Title").val();
   458     _annotation.created = new Date(); /* Annotation creation date */
   524     _annotation.created = new Date(); /* Annotation creation date */
   459     _annotation.description = this.$.find(".Ldt-CreateAnnotation-Description").val(); /* Description field */
   525     _annotation.description = this.$.find(".Ldt-CreateAnnotation-Description").val(); /* Description field */
   460    
   526    
   461     var tagIds = Array.prototype.map.call(
   527     var tagIds = Array.prototype.map.call(
   462         this.$.find(".Ldt-CreateAnnotation-TagLi.selected"),
   528         this.$.find(".Ldt-CreateAnnotation-TagLi.selected"),
   463         function(el) { return IriSP.jQuery(el).attr("tag-id")}
   529         function(el) { return IriSP.jQuery(el).attr("tag-id"); }
   464     );
   530     );
   465         
   531         
   466     IriSP._(_annotation.description.match(/#[^\s#.,;]+/g)).each(function(_tt) {
   532     IriSP._(_annotation.description.match(/#[^\s#.,;]+/g)).each(function(_tt) {
   467         var _tag,
   533         var _tag,
   468             _tag_title = _tt.replace(/^#/,''),
   534             _tag_title = _tt.replace(/^#/,''),
   475             _tag.title = _tag_title;
   541             _tag.title = _tag_title;
   476         }
   542         }
   477         if (tagIds.indexOf(_tag.id) === -1) {
   543         if (tagIds.indexOf(_tag.id) === -1) {
   478             tagIds.push(_tag.id);
   544             tagIds.push(_tag.id);
   479         }
   545         }
   480         
   546     });
   481     })
       
   482    
       
   483     _annotation.setTags(IriSP._(tagIds).uniq()); /* Tag ids list */
   547     _annotation.setTags(IriSP._(tagIds).uniq()); /* Tag ids list */
   484     if (this.audio_url) {
   548     if (this.audio_url) {
   485         _annotation.audio = {
   549         _annotation.audio = {
   486             src: "mic",
   550             src: "mic",
   487             mimetype: "audio/mp3",
   551             mimetype: "audio/mp3",
   491     if (this.show_creator_field) {
   555     if (this.show_creator_field) {
   492         _annotation.creator = this.$.find(".Ldt-CreateAnnotation-Creator").val();
   556         _annotation.creator = this.$.find(".Ldt-CreateAnnotation-Creator").val();
   493     } else {
   557     } else {
   494         _annotation.creator = this.creator_name;
   558         _annotation.creator = this.creator_name;
   495     }
   559     }
   496     _exportedAnnotations.push(_annotation); /* We add the annotation in the list to export */
   560     _exportedAnnotations.push(_annotation); /* Ajout de l'annotation à la liste à exporter */
   497     _export.addList("annotation",_exportedAnnotations); /* We add the list to the source object */ 
   561     
   498     var _this = this;
   562     if (this.editable_storage != '') {
   499     /* We send the AJAX request to the server ! */
   563         // Append to localStorage annotations
   500     IriSP.jQuery.ajax({
   564 
   501         url: _url,
   565         // FIXME: handle movie ids
   502         type: this.api_method,
   566         _local_export.addList("annotation", _exportedAnnotations); /* Ajout de la liste à exporter à l'objet Source */
   503         contentType: 'application/json',
   567         _this.source.merge(_local_export); /* On ajoute la nouvelle annotation au recueil original */
   504         data: _export.serialize(), /* Source is serialized */
   568         // Import previously saved local annotations
   505         success: function(_data) {
   569         if (window.localStorage[this.editable_storage]) {
   506             _this.showScreen('Saved'); 
   570             _local_export.deSerialize(window.localStorage[this.editable_storage]);
   507             if (_this.after_send_timeout) { 
   571         }
   508                 window.setTimeout(
   572         // Save everything back
   509                     function() {
   573         window.localStorage[_this.editable_storage] = _local_export.serialize();
   510                         _this.close_after_send
   574         _this.player.trigger("AnnotationsList.refresh"); /* On force le rafraîchissement du widget AnnotationsList */
   511                         ? _this.player.trigger("CreateAnnotation.hide")
   575         _this.player.trigger("Annotation.create", _annotation);
   512                         : _this.player.trigger("CreateAnnotation.show");
   576         _this.$.find(".Ldt-CreateAnnotation-Description").val("");
   513                     },
   577     }
   514                     _this.after_send_timeout
   578     
   515                 );
   579     if (_url !== "") {
       
   580         _exportedAnnotations.push(_annotation); /* We add the annotation in the list to export */
       
   581         _export.addList("annotation",_exportedAnnotations); /* We add the list to the source object */ 
       
   582         var _this = this;
       
   583         /* We send the AJAX request to the server ! */
       
   584         IriSP.jQuery.ajax({
       
   585             url: _url,
       
   586             type: this.api_method,
       
   587             contentType: 'application/json',
       
   588             data: _export.serialize(), /* Source is serialized */
       
   589             success: function(_data) {
       
   590                 _this.showScreen('Saved'); 
       
   591                 if (_this.after_send_timeout) { 
       
   592                     window.setTimeout(
       
   593                         function() {
       
   594                             _this.close_after_send
       
   595                                 ? _this.player.trigger("CreateAnnotation.hide")
       
   596                                 : _this.player.trigger("CreateAnnotation.show");
       
   597                         },
       
   598                         _this.after_send_timeout
       
   599                     );
       
   600                 }
       
   601                 _export.getAnnotations().removeElement(_annotation, true); /* We delete the sent annotation to avoid redundancy */
       
   602                 _export.deSerialize(_data); /* Data deserialization */
       
   603                 _this.source.merge(_export); /* We merge the deserialized data with the current source data */
       
   604                 if (_this.pause_on_write && _this.media.getPaused()) {
       
   605                     _this.media.play();
       
   606                 }
       
   607                 _this.player.trigger("AnnotationsList.refresh"); 
       
   608             },
       
   609             error: function(_xhr, _error, _thrown) {
       
   610                 IriSP.log("Error when sending annotation", _thrown);
       
   611                 _export.getAnnotations().removeElement(_annotation, true);
       
   612                 _this.showScreen('Error');
       
   613                 window.setTimeout(function(){
       
   614                     _this.showScreen("Main")
       
   615                 },
       
   616                                   (_this.after_send_timeout || 5000));
   516             }
   617             }
   517             _export.getAnnotations().removeElement(_annotation, true); /* We delete the sent annotation to avoid redundancy */
   618         });
   518             _export.deSerialize(_data); /* Data deserialization */
   619         this.showScreen('Wait');
   519             _this.source.merge(_export); /* We merge the deserialized data with the current source data */
   620     };
   520             if (_this.pause_on_write && _this.media.getPaused()) {
       
   521                 _this.media.play();
       
   522             }
       
   523             _this.player.trigger("AnnotationsList.refresh"); 
       
   524         },
       
   525         error: function(_xhr, _error, _thrown) {
       
   526             IriSP.log("Error when sending annotation", _thrown);
       
   527             _export.getAnnotations().removeElement(_annotation, true);
       
   528             _this.showScreen('Error');
       
   529             window.setTimeout(function(){
       
   530                 _this.showScreen("Main")
       
   531             },
       
   532             (_this.after_send_timeout || 5000));
       
   533         }
       
   534     });
       
   535     this.showScreen('Wait');
       
   536     
       
   537     return false;
   621     return false;
   538 };
   622 };
   539 
   623