src/widgets/CreateAnnotation.js
changeset 1033 c20df1c080e6
parent 1021 7253d4d06f0d
child 1038 e78b889a75e1
equal deleted inserted replaced
1032:74ac0be7655c 1033:c20df1c080e6
     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     var _this = this;
     4     IriSP.Widgets.Widget.call(this, player, config);
     5     IriSP.Widgets.Widget.call(this, player, config);
       
     6     if (_this.api_method == 'local' && window.localStorage[_this.api_endpoint_template]) {
       
     7         this.source.onLoad(function () {
       
     8             var _export = _this.player.sourceManager.newLocalSource({serializer: IriSP.serializers[_this.api_serializer]});
       
     9             _export.deSerialize(window.localStorage[_this.api_endpoint_template]);
       
    10             console.log("Loaded personal annotations", _export);
       
    11             _this.source.merge(_export);
       
    12         });
       
    13     };
     5 };
    14 };
     6 
    15 
     7 IriSP.Widgets.CreateAnnotation.prototype = new IriSP.Widgets.Widget();
    16 IriSP.Widgets.CreateAnnotation.prototype = new IriSP.Widgets.Widget();
     8 
    17 
     9 IriSP.Widgets.CreateAnnotation.prototype.defaults = {
    18 IriSP.Widgets.CreateAnnotation.prototype.defaults = {
    10     show_title_field : true,
    19     show_title_field : true,
    11     show_creator_field : true,
    20     show_creator_field : true,
    12     start_visible : true,
    21     start_visible : true,
    13     always_visible : false,
    22     always_visible : false,
    14     show_slice : true,
    23     show_slice : true,
       
    24     show_controls: false,
    15     show_arrow : true,
    25     show_arrow : true,
    16     show_mic_record: false,
    26     show_mic_record: false,
    17     show_mic_play: false,
    27     show_mic_play: false,
    18     minimize_annotation_widget : true,
    28     minimize_annotation_widget : true,
    19     creator_name : "",
    29     creator_name : "",
    44     api_serializer: "ldt_annotate",
    54     api_serializer: "ldt_annotate",
    45     api_endpoint_template: "",
    55     api_endpoint_template: "",
    46     api_method: "POST",
    56     api_method: "POST",
    47     after_send_timeout: 0,
    57     after_send_timeout: 0,
    48     close_after_send: false,
    58     close_after_send: false,
    49     tag_prefix: "#"
    59     tag_prefix: "#",
       
    60     slice_widget: null
    50 };
    61 };
    51 
    62 
    52 IriSP.Widgets.CreateAnnotation.prototype.messages = {
    63 IriSP.Widgets.CreateAnnotation.prototype.messages = {
    53     en: {
    64     en: {
    54         from_time: "from",
    65         from_time: "from",
   102     + '<h3><span class="Ldt-CreateAnnotation-h3Left">{{l10n.annotate_video}}{{#show_title_field}}</span></h3>'
   113     + '<h3><span class="Ldt-CreateAnnotation-h3Left">{{l10n.annotate_video}}{{#show_title_field}}</span></h3>'
   103     + '<h3><span class="Ldt-CreateAnnotation-h3Left"><input class="Ldt-CreateAnnotation-Title empty" placeholder="{{l10n.type_title}}" />{{/show_title_field}}'
   114     + '<h3><span class="Ldt-CreateAnnotation-h3Left"><input class="Ldt-CreateAnnotation-Title empty" placeholder="{{l10n.type_title}}" />{{/show_title_field}}'
   104     + '<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>'
   115     + '<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>'
   105     + '{{#show_slice}} {{l10n.to_time}} <span class="Ldt-CreateAnnotation-End">{{end}}</span>{{/show_slice}}</span></span>'
   116     + '{{#show_slice}} {{l10n.to_time}} <span class="Ldt-CreateAnnotation-End">{{end}}</span>{{/show_slice}}</span></span>'
   106     + '{{#show_creator_field}}{{l10n.your_name_}} <input class="Ldt-CreateAnnotation-Creator empty" value="{{creator_name}}" />{{/show_creator_field}}</h3>'
   117     + '{{#show_creator_field}}{{l10n.your_name_}} <input class="Ldt-CreateAnnotation-Creator empty" value="{{creator_name}}" />{{/show_creator_field}}</h3>'
       
   118     + '{{#show_controls}}<div class="Ldt-CreateAnnotation-Controls">'
       
   119     +   '<span class="Ldt-CreateAnnotation-Control-In">IN</span>'
       
   120     +   '<span class="Ldt-CreateAnnotation-Control-Out">OUT</span>'
       
   121     +   '<span class="Ldt-CreateAnnotation-Control-Play">Play</span>'
       
   122     + '</div>{{/show_controls}}'
   107     + '<textarea class="Ldt-CreateAnnotation-Description empty" placeholder="{{l10n.type_description}}"></textarea>'
   123     + '<textarea class="Ldt-CreateAnnotation-Description empty" placeholder="{{l10n.type_description}}"></textarea>'
   108     + '<div class="Ldt-CreateAnnotation-Avatar"><img src="{{creator_avatar}}" title="{{creator_name}}"></img></div>'
   124     + '{{#show_creator_field}}<div class="Ldt-CreateAnnotation-Avatar"><img src="{{creator_avatar}}" title="{{creator_name}}"></img></div>{{/show_creator_field}}'
   109     + '<input type="submit" class="Ldt-CreateAnnotation-Submit" value="{{l10n.submit}}" />'
   125     + '<input type="submit" class="Ldt-CreateAnnotation-Submit" value="{{l10n.submit}}" />'
   110     + '{{#show_mic_record}}<div class="Ldt-CreateAnnotation-RecBlock"><div class="Ldt-CreateAnnotation-RecLabel">Add voice annotation</div>'
   126     + '{{#show_mic_record}}<div class="Ldt-CreateAnnotation-RecBlock"><div class="Ldt-CreateAnnotation-RecLabel">Add voice annotation</div>'
   111     + '    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="220" height="160">'
   127     + '    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="220" height="160">'
   112     + '        <param name="movie" value="{{record_swf}}" />'
   128     + '        <param name="movie" value="{{record_swf}}" />'
   113     + '        <param name="quality" value="high" />'
   129     + '        <param name="quality" value="high" />'
   128     + '             type="application/x-shockwave-flash" allowFullScreen="true" wmode="transparent" '
   144     + '             type="application/x-shockwave-flash" allowFullScreen="true" wmode="transparent" '
   129     + '             flashvars="playVisible={{show_mic_play}}"'
   145     + '             flashvars="playVisible={{show_mic_play}}"'
   130     + '             pluginspage="http://www.macromedia.com/go/getflashplayer">'
   146     + '             pluginspage="http://www.macromedia.com/go/getflashplayer">'
   131     + '        </embed>'
   147     + '        </embed>'
   132     + '    </object>'
   148     + '    </object>'
   133     + '</div>{{/show_mic_record}}' 
   149     + '</div>{{/show_mic_record}}'
   134     + '{{#tags.length}}<div class="Ldt-CreateAnnotation-Tags"><div class="Ldt-CreateAnnotation-TagTitle">{{l10n.add_keywords_}}</div><ul class="Ldt-CreateAnnotation-TagList">'
   150     + '{{#tags.length}}<div class="Ldt-CreateAnnotation-Tags"><div class="Ldt-CreateAnnotation-TagTitle">{{l10n.add_keywords_}}</div><ul class="Ldt-CreateAnnotation-TagList">'
   135     + '{{#tags}}<li class="Ldt-CreateAnnotation-TagLi" tag-id="{{id}}" data-text="{{tag_prefix}}{{title}}"><span class="Ldt-CreateAnnotation-TagButton">{{title}}</span></li>{{/tags}}</ul></div>{{/tags.length}}'
   151     + '{{#tags}}<li class="Ldt-CreateAnnotation-TagLi" tag-id="{{id}}" data-text="{{tag_prefix}}{{title}}"><span class="Ldt-CreateAnnotation-TagButton">{{title}}</span></li>{{/tags}}</ul></div>{{/tags.length}}'
   136     + '{{#polemics.length}}<div class="Ldt-CreateAnnotation-Polemics"><div class="Ldt-CreateAnnotation-PolemicTitle">{{l10n.add_polemic_keywords_}}</div><ul class="Ldt-CreateAnnotation-PolemicList">'
   152     + '{{#polemics.length}}<div class="Ldt-CreateAnnotation-Polemics"><div class="Ldt-CreateAnnotation-PolemicTitle">{{l10n.add_polemic_keywords_}}</div><ul class="Ldt-CreateAnnotation-PolemicList">'
   137     + '{{#polemics}}<li class="Ldt-CreateAnnotation-PolemicLi" style="background-color: {{background_color}}; color: {{text_color}}" data-text="{{keyword}}">{{keyword}}</li>{{/polemics}}</ul></div>{{/polemics.length}}'
   153     + '{{#polemics}}<li class="Ldt-CreateAnnotation-PolemicLi" style="background-color: {{background_color}}; color: {{text_color}}" data-text="{{keyword}}">{{keyword}}</li>{{/polemics}}</ul></div>{{/polemics.length}}'
   138     + '<div style="clear: both;"></div></form>'
   154     + '<div style="clear: both;"></div></form>'
   139     + '<div class="Ldt-CreateAnnotation-Screen Ldt-CreateAnnotation-Wait"><div class="Ldt-CreateAnnotation-InnerBox">{{l10n.wait_while_processing}}</div></div>'
   155     + '<div class="Ldt-CreateAnnotation-Screen Ldt-CreateAnnotation-Wait"><div class="Ldt-CreateAnnotation-InnerBox">{{l10n.wait_while_processing}}</div></div>'
   140     + '<div class="Ldt-CreateAnnotation-Screen Ldt-CreateAnnotation-Error">{{^always_visible}}<a title="{{l10n.close_widget}}" class="Ldt-CreateAnnotation-Close" href="#"></a>{{/always_visible}}<div class="Ldt-CreateAnnotation-InnerBox">{{l10n.error_while_contacting}}</div></div>'
   156     + '<div class="Ldt-CreateAnnotation-Screen Ldt-CreateAnnotation-Error">{{^always_visible}}<a title="{{l10n.close_widget}}" class="Ldt-CreateAnnotation-Close" href="#"></a>{{/always_visible}}<div class="Ldt-CreateAnnotation-InnerBox">{{l10n.error_while_contacting}}</div></div>'
   141     + '<div class="Ldt-CreateAnnotation-Screen Ldt-CreateAnnotation-Saved">{{^always_visible}}<a title="{{l10n.close_widget}}" class="Ldt-CreateAnnotation-Close" href="#"></a>{{/always_visible}}<div class="Ldt-CreateAnnotation-InnerBox">{{l10n.annotation_saved}}</div></div>'
   157     + '<div class="Ldt-CreateAnnotation-Screen Ldt-CreateAnnotation-Saved">{{^always_visible}}<a title="{{l10n.close_widget}}" class="Ldt-CreateAnnotation-Close" href="#"></a>{{/always_visible}}<div class="Ldt-CreateAnnotation-InnerBox">{{l10n.annotation_saved}}</div></div>'
   142     + '</div></div>';
   158     + '</div></div>';
   143     
   159 
   144 IriSP.Widgets.CreateAnnotation.prototype.draw = function() {
   160 IriSP.Widgets.CreateAnnotation.prototype.draw = function() {
   145     var _this = this;
   161     var _this = this;
   146     
   162 
   147     this.begin = new IriSP.Model.Time();
   163     this.begin = new IriSP.Model.Time();
   148     this.end = this.source.getDuration();
   164     this.end = this.source.getDuration();
   149     
   165 
   150     this.tag_prefix = this.tag_prefix || "";
   166     this.tag_prefix = this.tag_prefix || "";
   151     
   167 
   152     if (this.tag_titles && !this.tags) {
   168     if (this.tag_titles && !this.tags) {
   153 		if(!(this.tag_titles.length==1 && this.tag_titles[0]=="")){
   169 		if(!(this.tag_titles.length==1 && this.tag_titles[0]=="")){
   154 			this.tags = IriSP._(this.tag_titles).map(function(_tag_title) {
   170 			this.tags = IriSP._(this.tag_titles).map(function(_tag_title) {
   155 				var _tag,
   171 				var _tag,
   156 					_tags = _this.source.getTags().searchByTitle(_tag_title, true);
   172 					_tags = _this.source.getTags().searchByTitle(_tag_title, true);
   182     }
   198     }
   183     this.record_swf = IriSP.getLib("recordMicSwf");
   199     this.record_swf = IriSP.getLib("recordMicSwf");
   184     this.renderTemplate();
   200     this.renderTemplate();
   185     if (this.show_mic_record) {
   201     if (this.show_mic_record) {
   186         this.recorder = this.$.find("embed")[0];
   202         this.recorder = this.$.find("embed")[0];
   187         
   203 
   188         window.setAudioUrl = function(_url) {
   204         window.setAudioUrl = function(_url) {
   189             _this.audio_url = _url;
   205             _this.audio_url = _url;
   190         }
   206         };
   191     }
   207     }
   192     if (this.show_slice) {
   208     if (this.show_slice) {
   193         this.insertSubwidget(
   209         this.slice_widget = this.insertSubwidget(
   194             this.$.find(".Ldt-CreateAnnotation-Slice"),
   210             this.$.find(".Ldt-CreateAnnotation-Slice"),
   195             {
   211             {
   196                 type: "Slice",
   212                 type: "Slice",
   197                 show_arrow: this.show_arrow,
   213                 show_arrow: this.show_arrow,
   198                 annotation_type: this.slice_annotation_type,
   214                 annotation_type: this.slice_annotation_type,
   241         this.$.find(".Ldt-CreateAnnotation-Title").bind("change keyup input paste", this.functionWrapper("onTitleChange"));
   257         this.$.find(".Ldt-CreateAnnotation-Title").bind("change keyup input paste", this.functionWrapper("onTitleChange"));
   242     }
   258     }
   243     if (this.show_creator_field) {
   259     if (this.show_creator_field) {
   244         this.$.find(".Ldt-CreateAnnotation-Creator").bind("change keyup input paste", this.functionWrapper("onCreatorChange"));
   260         this.$.find(".Ldt-CreateAnnotation-Creator").bind("change keyup input paste", this.functionWrapper("onCreatorChange"));
   245     }
   261     }
   246     
   262     this.$.find("[class^='Ldt-CreateAnnotation-Control-']").click(function() {
       
   263         var action = this.className.replace('Ldt-CreateAnnotation-Control-', '');
       
   264         switch (action) {
       
   265             case "In":
       
   266                // Set In bound to current player time
       
   267                _this.begin = new IriSP.Model.Time(_this.media.getCurrentTime() || 0);
       
   268                _this.$.find(".Ldt-CreateAnnotation-Begin").html(_this.begin.toString());
       
   269                break;
       
   270             case "Out":
       
   271                // Set In bound to current player time
       
   272                _this.end = new IriSP.Model.Time(_this.media.getCurrentTime() || _this.media.duration);
       
   273                _this.$.find(".Ldt-CreateAnnotation-End").html(_this.end.toString());
       
   274                break;
       
   275             case "Play":
       
   276                _this.media.setCurrentTime(_this.begin);
       
   277                _this.media.play()
       
   278                break;
       
   279         }
       
   280         return false;
       
   281     });
       
   282 
   247     if (this.start_visible) {
   283     if (this.start_visible) {
   248         this.show();
   284         this.show();
   249     } else {
   285     } else {
   250         this.$.hide();
   286         this.$.hide();
   251         this.hide();
   287         this.hide();
   252     }
   288     }
   253     
   289 
   254     this.onMdpEvent("CreateAnnotation.toggle","toggle");
   290     this.onMdpEvent("CreateAnnotation.toggle","toggle");
   255     this.$.find("form").submit(this.functionWrapper("onSubmit"));
   291     this.$.find("form").submit(this.functionWrapper("onSubmit"));
   256 };
   292 };
   257 
   293 
   258 IriSP.Widgets.CreateAnnotation.prototype.showScreen = function(_screenName) {
   294 IriSP.Widgets.CreateAnnotation.prototype.showScreen = function(_screenName) {
   292         }
   328         }
   293     }
   329     }
   294 };
   330 };
   295 
   331 
   296 IriSP.Widgets.CreateAnnotation.prototype.toggle = function() {
   332 IriSP.Widgets.CreateAnnotation.prototype.toggle = function() {
       
   333     var _this = this;
   297     if (!this.always_visible) {
   334     if (!this.always_visible) {
   298         if (this.visible) {
   335         if (this.visible) {
   299             this.hide();
   336             this.hide();
   300         } else {
   337         } else {
       
   338             _this.begin = new IriSP.Model.Time(_this.media.getCurrentTime() || 0);
       
   339             _this.end = new IriSP.Model.Time(_this.media.getCurrentTime() || 0);
       
   340             _this.$.find(".Ldt-CreateAnnotation-Begin").html(_this.begin.toString());
       
   341             _this.$.find(".Ldt-CreateAnnotation-End").html(_this.end.toString());
       
   342             if (_this.slice_widget) {
       
   343                 _this.slice_widget.setBounds(_this.begin, _this.end);
       
   344             }
   301             this.show();
   345             this.show();
   302         }
   346         }
   303     }
   347     }
   304 };
   348 };
   305 
   349 
   373 IriSP.Widgets.CreateAnnotation.prototype.onSubmit = function() {
   417 IriSP.Widgets.CreateAnnotation.prototype.onSubmit = function() {
   374     /* Si les champs obligatoires sont vides, on annule l'envoi */
   418     /* Si les champs obligatoires sont vides, on annule l'envoi */
   375     if (!this.onDescriptionChange() || (this.show_title_field && !this.onTitleChange()) || (this.show_creator_field && !this.onCreatorChange())) {
   419     if (!this.onDescriptionChange() || (this.show_title_field && !this.onTitleChange()) || (this.show_creator_field && !this.onCreatorChange())) {
   376         return false;
   420         return false;
   377     }
   421     }
   378     
   422 
   379     if (this.recorder) {
   423     if (this.recorder) {
   380         this.recorder.stopRecord();
   424         this.recorder.stopRecord();
   381     }
   425     }
   382     
   426 
   383     var _this = this,
   427     var _this = this,
   384         _exportedAnnotations = new IriSP.Model.List(this.player.sourceManager), /* Création d'une liste d'annotations contenant une annotation afin de l'envoyer au serveur */
   428         _exportedAnnotations = new IriSP.Model.List(this.player.sourceManager), /* Création d'une liste d'annotations contenant une annotation afin de l'envoyer au serveur */
   385         _export = this.player.sourceManager.newLocalSource({serializer: IriSP.serializers[this.api_serializer]}), /* Création d'un objet source utilisant un sérialiseur spécifique pour l'export */
   429         _export = this.player.sourceManager.newLocalSource({serializer: IriSP.serializers[this.api_serializer]}), /* Création d'un objet source utilisant un sérialiseur spécifique pour l'export */
   386         _annotation = new IriSP.Model.Annotation(false, _export), /* Création d'une annotation dans cette source avec un ID généré à la volée (param. false) */
   430         _annotation = new IriSP.Model.Annotation(false, _export), /* Création d'une annotation dans cette source avec un ID généré à la volée (param. false) */
   387         _annotationTypes = this.source.getAnnotationTypes().searchByTitle(this.annotation_type, true), /* Récupération du type d'annotation dans lequel l'annotation doit être ajoutée */
   431         _annotationTypes = this.source.getAnnotationTypes().searchByTitle(this.annotation_type, true), /* Récupération du type d'annotation dans lequel l'annotation doit être ajoutée */
   388         _annotationType = (_annotationTypes.length ? _annotationTypes[0] : new IriSP.Model.AnnotationType(false, _export)), /* Si le Type d'Annotation n'existe pas, il est créé à la volée */
   432         _annotationType = (_annotationTypes.length ? _annotationTypes[0] : new IriSP.Model.AnnotationType(false, _export)), /* Si le Type d'Annotation n'existe pas, il est créé à la volée */
   389         _url = Mustache.to_html(this.api_endpoint_template, {id: this.source.projectId}); /* Génération de l'URL à laquelle l'annotation doit être envoyée, qui doit inclure l'ID du projet */
   433         _url = Mustache.to_html(this.api_endpoint_template, {id: this.source.projectId}); /* Génération de l'URL à laquelle l'annotation doit être envoyée, qui doit inclure l'ID du projet */
   390     
   434 
   391     /* Si nous avons dû générer un ID d'annotationType à la volée... */
   435     /* Si nous avons dû générer un ID d'annotationType à la volée... */
   392     if (!_annotationTypes.length) {
   436     if (!_annotationTypes.length) {
   393         /* Il ne faudra pas envoyer l'ID généré au serveur */
   437         /* Il ne faudra pas envoyer l'ID généré au serveur */
   394         _annotationType.dont_send_id = true;
   438         _annotationType.dont_send_id = true;
   395         /* Il faut inclure le titre dans le type d'annotation */
   439         /* Il faut inclure le titre dans le type d'annotation */
   396         _annotationType.title = this.annotation_type;
   440         _annotationType.title = this.annotation_type;
   397     }
   441     }
   398     
   442 
   399     /*
   443     /*
   400      * Nous remplissons les données de l'annotation générée à la volée
   444      * Nous remplissons les données de l'annotation générée à la volée
   401      * ATTENTION: Si nous sommes sur un MASHUP, ces éléments doivent se référer AU MEDIA D'ORIGINE
   445      * ATTENTION: Si nous sommes sur un MASHUP, ces éléments doivent se référer AU MEDIA D'ORIGINE
   402      * */
   446      * */
   403     _annotation.setMedia(this.source.currentMedia.id); /* Id du média annoté */
   447     _annotation.setMedia(this.source.currentMedia.id); /* Id du média annoté */
   404     _annotation.setBegin(this.begin); /*Timecode de début */
   448     _annotation.setBegin(this.begin); /*Timecode de début */
   405     _annotation.setEnd(this.end); /* Timecode de fin */
   449     _annotation.setEnd(this.end); /* Timecode de fin */
   406    
   450     _annotation.created = new Date(); /* Date de création de l'annotation */
       
   451 
   407     _annotation.setAnnotationType(_annotationType.id); /* Id du type d'annotation */
   452     _annotation.setAnnotationType(_annotationType.id); /* Id du type d'annotation */
       
   453     _annotation.description = this.$.find(".Ldt-CreateAnnotation-Description").val(); /* Champ description */
   408     if (this.show_title_field) {
   454     if (this.show_title_field) {
   409         /* Champ titre, seulement s'il est visible */
   455         /* Champ titre, seulement s'il est visible */
   410         _annotation.title = this.$.find(".Ldt-CreateAnnotation-Title").val();
   456         _annotation.title = this.$.find(".Ldt-CreateAnnotation-Title").val();
   411     }
   457     } else {
   412     _annotation.created = new Date(); /* Date de création de l'annotation */
   458         _annotation.title = _annotation.description;
   413     _annotation.description = this.$.find(".Ldt-CreateAnnotation-Description").val(); /* Champ description */
   459     }
   414    
   460 
   415     var tagIds = Array.prototype.map.call(
   461     var tagIds = Array.prototype.map.call(
   416         this.$.find(".Ldt-CreateAnnotation-TagLi.selected"),
   462         this.$.find(".Ldt-CreateAnnotation-TagLi.selected"),
   417         function(el) { return IriSP.jQuery(el).attr("tag-id")}
   463         function(el) { return IriSP.jQuery(el).attr("tag-id")}
   418     );
   464     );
   419         
   465 
   420     IriSP._(_annotation.description.match(/#[^\s#.,;]+/g)).each(function(_tt) {
   466     IriSP._(_annotation.description.match(/#[^\s#.,;]+/g)).each(function(_tt) {
   421         var _tag,
   467         var _tag,
   422             _tag_title = _tt.replace(/^#/,''),
   468             _tag_title = _tt.replace(/^#/,''),
   423             _tags = _this.source.getTags().searchByTitle(_tag_title, true);
   469             _tags = _this.source.getTags().searchByTitle(_tag_title, true);
   424         if (_tags.length) {
   470         if (_tags.length) {
   429             _tag.title = _tag_title;
   475             _tag.title = _tag_title;
   430         }
   476         }
   431         if (tagIds.indexOf(_tag.id) === -1) {
   477         if (tagIds.indexOf(_tag.id) === -1) {
   432             tagIds.push(_tag.id);
   478             tagIds.push(_tag.id);
   433         }
   479         }
   434         
   480 
   435     })
   481     })
   436    
   482 
   437     _annotation.setTags(IriSP._(tagIds).uniq()); /*Liste des ids de tags */
   483     _annotation.setTags(IriSP._(tagIds).uniq()); /*Liste des ids de tags */
   438     if (this.audio_url) {
   484     if (this.audio_url) {
   439         _annotation.audio = {
   485         _annotation.audio = {
   440             src: "mic",
   486             src: "mic",
   441             mimetype: "audio/mp3",
   487             mimetype: "audio/mp3",
   446         _annotation.creator = this.$.find(".Ldt-CreateAnnotation-Creator").val();
   492         _annotation.creator = this.$.find(".Ldt-CreateAnnotation-Creator").val();
   447     } else {
   493     } else {
   448         _annotation.creator = this.creator_name;
   494         _annotation.creator = this.creator_name;
   449     }
   495     }
   450     _exportedAnnotations.push(_annotation); /* Ajout de l'annotation à la liste à exporter */
   496     _exportedAnnotations.push(_annotation); /* Ajout de l'annotation à la liste à exporter */
   451     _export.addList("annotation",_exportedAnnotations); /* Ajout de la liste à exporter à l'objet Source */
   497 
   452     
   498     if (this.api_method == 'local') {
   453     var _this = this;
   499         // Append to existing localStorage annotations
   454     /* Envoi de l'annotation via AJAX au serveur ! */
   500         // FIXME: handle movie ids
   455     IriSP.jQuery.ajax({
   501         /* Use localStorage */
   456         url: _url,
   502         /* Data will be serialized in the localStore property designated by api_endpoint_template */
   457         type: this.api_method,
   503         _export.addList("annotation", _exportedAnnotations); /* Ajout de la liste à exporter à l'objet Source */
   458         contentType: 'application/json',
   504         _this.source.merge(_export); /* On ajoute la nouvelle annotation au recueil original */
   459         data: _export.serialize(), /* L'objet Source est sérialisé */
   505         // Import previously saved local annotations
   460         success: function(_data) {
   506         if (window.localStorage[_this.api_endpoint_template]) {
   461             _this.showScreen('Saved'); /* Si l'appel a fonctionné, on affiche l'écran "Annotation enregistrée" */
   507             _export.deSerialize(window.localStorage[_this.api_endpoint_template]);
   462             if (_this.after_send_timeout) { /* Selon les options de configuration, on revient à l'écran principal ou on ferme le widget, ou rien */
   508         }
   463                 window.setTimeout(
   509         // Save everything back
   464                     function() {
   510         window.localStorage[_this.api_endpoint_template] = _export.serialize();
   465                         _this.close_after_send
   511         if (_this.pause_on_write && _this.media.getPaused()) {
   466                         ? _this.hide()
   512             _this.media.play();
   467                         : _this.show();
   513         }
   468                     },
   514         _this.player.trigger("AnnotationsList.refresh"); /* On force le rafraîchissement du widget AnnotationsList */
   469                     _this.after_send_timeout
   515         _this.$.find(".Ldt-CreateAnnotation-Description").val("");
   470                 );
   516     } else {
       
   517         _export.addList("annotation",_exportedAnnotations); /* Ajout de la liste à exporter à l'objet Source */
       
   518        /* Envoi de l'annotation via AJAX au serveur ! */
       
   519         IriSP.jQuery.ajax({
       
   520             url: _url,
       
   521             type: this.api_method,
       
   522             contentType: 'application/json',
       
   523             data: _export.serialize(), /* L'objet Source est sérialisé */
       
   524             success: function(_data) {
       
   525                 _this.showScreen('Saved'); /* Si l'appel a fonctionné, on affiche l'écran "Annotation enregistrée" */
       
   526                 if (_this.after_send_timeout) { /* Selon les options de configuration, on revient à l'écran principal ou on ferme le widget, ou rien */
       
   527                     window.setTimeout(
       
   528                         function() {
       
   529                             _this.close_after_send
       
   530                                 ? _this.hide()
       
   531                                 : _this.show();
       
   532                         },
       
   533                         _this.after_send_timeout
       
   534                     );
       
   535                 }
       
   536                 _export.getAnnotations().removeElement(_annotation, true); /* Pour éviter les doublons, on supprime l'annotation qui a été envoyée */
       
   537                 _export.deSerialize(_data); /* On désérialise les données reçues pour les réinjecter */
       
   538                 _this.source.merge(_export); /* On récupère les données réimportées dans l'espace global des données */
       
   539                 if (_this.pause_on_write && _this.media.getPaused()) {
       
   540                     _this.media.play();
       
   541                 }
       
   542                 _this.player.trigger("AnnotationsList.refresh"); /* On force le rafraîchissement du widget AnnotationsList */
       
   543             },
       
   544             error: function(_xhr, _error, _thrown) {
       
   545                 IriSP.log("Error when sending annotation", _thrown);
       
   546                 _export.getAnnotations().removeElement(_annotation, true);
       
   547                 _this.showScreen('Error');
       
   548                 window.setTimeout(function(){
       
   549                     _this.showScreen("Main")
       
   550                 },
       
   551                                   (_this.after_send_timeout || 5000));
   471             }
   552             }
   472             _export.getAnnotations().removeElement(_annotation, true); /* Pour éviter les doublons, on supprime l'annotation qui a été envoyée */
   553         });
   473             _export.deSerialize(_data); /* On désérialise les données reçues pour les réinjecter */
   554         this.showScreen('Wait');
   474             _this.source.merge(_export); /* On récupère les données réimportées dans l'espace global des données */
   555     }
   475             if (_this.pause_on_write && _this.media.getPaused()) {
   556 
   476                 _this.media.play();
       
   477             }
       
   478             _this.player.trigger("AnnotationsList.refresh"); /* On force le rafraîchissement du widget AnnotationsList */
       
   479         },
       
   480         error: function(_xhr, _error, _thrown) {
       
   481             IriSP.log("Error when sending annotation", _thrown);
       
   482             _export.getAnnotations().removeElement(_annotation, true);
       
   483             _this.showScreen('Error');
       
   484             window.setTimeout(function(){
       
   485                 _this.showScreen("Main")
       
   486             },
       
   487             (_this.after_send_timeout || 5000));
       
   488         }
       
   489     });
       
   490     this.showScreen('Wait');
       
   491     
       
   492     return false;
   557     return false;
   493 };
   558 };
   494