web/lib/metadataplayer/CreateAnnotation.js
changeset 0 7f8907368bd5
equal deleted inserted replaced
-1:000000000000 0:7f8907368bd5
       
     1 /* TODO: Add Social Network Sharing */
       
     2 
       
     3 IriSP.Widgets.CreateAnnotation = function(player, config) {
       
     4     IriSP.Widgets.Widget.call(this, player, config);
       
     5 };
       
     6 
       
     7 IriSP.Widgets.CreateAnnotation.prototype = new IriSP.Widgets.Widget();
       
     8 
       
     9 IriSP.Widgets.CreateAnnotation.prototype.defaults = {
       
    10     show_title_field : true,
       
    11     show_creator_field : true,
       
    12     start_visible : true,
       
    13     always_visible : false,
       
    14     show_slice : true,
       
    15     show_arrow : true,
       
    16     show_mic_record: false,
       
    17     show_mic_play: false,
       
    18     minimize_annotation_widget : true,
       
    19     creator_name : "",
       
    20     creator_avatar : "",
       
    21     tags : false,
       
    22     tag_titles : false,
       
    23     pause_on_write : true,
       
    24     max_tags : 8,
       
    25     polemics : [{
       
    26         keyword: "++",
       
    27         background_color: "#00a000",
       
    28         text_color: "#ffffff"
       
    29     },{
       
    30         keyword: "--",
       
    31         background_color: "#c00000",
       
    32         text_color: "#ffffff"
       
    33     },{
       
    34         keyword: "??",
       
    35         background_color: "#0000e0",
       
    36         text_color: "#ffffff"
       
    37     },{
       
    38         keyword: "==",
       
    39         background_color: "#f0e000",
       
    40         text_color: "#000000"
       
    41     }],
       
    42     slice_annotation_type: "chap",
       
    43     annotation_type: "Contributions",
       
    44     api_serializer: "ldt_annotate",
       
    45     api_endpoint_template: "",
       
    46     api_method: "POST",
       
    47     after_send_timeout: 0,
       
    48     close_after_send: false,
       
    49     tag_prefix: "#"
       
    50 };
       
    51 
       
    52 IriSP.Widgets.CreateAnnotation.prototype.messages = {
       
    53     en: {
       
    54         from_time: "from",
       
    55         to_time: "to",
       
    56         at_time: "at",
       
    57         submit: "Submit",
       
    58         add_keywords_: "Add keywords:",
       
    59         add_polemic_keywords_: "Add polemic attributes :",
       
    60         your_name_: "Your name:",
       
    61         annotate_video: "Annotate this video",
       
    62         type_title: "Annotation title",
       
    63         type_description: "Type the full contents of your annotation here.",
       
    64         wait_while_processing: "Please wait while your annotation is being processed...",
       
    65         error_while_contacting: "An error happened while contacting the server. Your annotation has not been saved.",
       
    66         annotation_saved: "Thank you, your annotation has been saved.",
       
    67         share_annotation: "Would you like to share it on social networks ?",
       
    68         close_widget: "Hide the annotation form",
       
    69         "polemic++": "Agree",
       
    70         "polemic--": "Disagree",
       
    71         "polemic??": "Question",
       
    72         "polemic==": "Reference"
       
    73     },
       
    74     fr: {
       
    75         from_time: "de",
       
    76         to_time: "à",
       
    77         at_time: "à",
       
    78         submit: "Envoyer",
       
    79         add_keywords_: "Ajouter des mots-clés\u00a0:",
       
    80         add_polemic_keywords_: "Ajouter des attributs polémiques\u00a0:",
       
    81         your_name_: "Votre nom\u00a0:",
       
    82         annotate_video: "Annoter cette vidéo",
       
    83         type_title: "Titre de l'annotation",
       
    84         type_description: "Rédigez ici le contenu de votre annotation.",
       
    85         wait_while_processing: "Veuillez patienter pendant le traitement de votre annotation...",
       
    86         error_while_contacting: "Une erreur s'est produite en contactant le serveur. Votre annotation n'a pas été enregistrée.",
       
    87         annotation_saved: "Merci, votre annotation a été enregistrée.",
       
    88         share_annotation: "Souhaitez-vous la partager sur les réseaux sociaux ?",
       
    89         close_widget: "Cacher le formulaire de création d'annotations",
       
    90         "polemic++": "Accord",
       
    91         "polemic--": "Désaccord",
       
    92         "polemic??": "Question",
       
    93         "polemic==": "Référence"
       
    94     }
       
    95 };
       
    96 
       
    97 IriSP.Widgets.CreateAnnotation.prototype.template =
       
    98     '{{#show_slice}}<div class="Ldt-CreateAnnotation-Slice"></div>{{/show_slice}}'
       
    99     + '{{^show_slice}}{{#show_arrow}}<div class="Ldt-CreateAnnotation-Arrow"></div>{{/show_arrow}}{{/show_slice}}'
       
   100     + '<div class="Ldt-CreateAnnotation"><div class="Ldt-CreateAnnotation-Inner">'
       
   101     + '<form class="Ldt-CreateAnnotation-Screen Ldt-CreateAnnotation-Main">'
       
   102     + '<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}}'
       
   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>'
       
   105     + '{{#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>'
       
   107     + '<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>'
       
   109     + '<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>'
       
   111     + '    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="220" height="160">'
       
   112     + '        <param name="movie" value="{{record_swf}}" />'
       
   113     + '        <param name="quality" value="high" />'
       
   114     + '        <param name="bgcolor" value="#ffffff" />'
       
   115     + '        <param name="play" value="true" />'
       
   116     + '        <param name="loop" value="true" />'
       
   117     + '        <param name="wmode" value="transparent" />'
       
   118     + '        <param name="scale" value="showall" />'
       
   119     + '        <param name="menu" value="true" />'
       
   120     + '        <param name="devicefont" value="false" />'
       
   121     + '        <param name="salign" value="" />'
       
   122     + '        <param name="allowScriptAccess" value="always" />'
       
   123     + '        <param name="allowFullScreen" value="true" />'
       
   124     + '        <param name="flashvars" value="playVisible={{show_mic_play}}">'
       
   125     + '        <embed src="{{record_swf}}"" quality="high" bgcolor="#ffffff"'
       
   126     + '             width="220" height="160" name="ExternalInterfaceExample" align="middle"'
       
   127     + '             play="true" loop="false" quality="high" allowScriptAccess="always" '
       
   128     + '             type="application/x-shockwave-flash" allowFullScreen="true" wmode="transparent" '
       
   129     + '             flashvars="playVisible={{show_mic_play}}"'
       
   130     + '             pluginspage="http://www.macromedia.com/go/getflashplayer">'
       
   131     + '        </embed>'
       
   132     + '    </object>'
       
   133     + '</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">'
       
   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}}'
       
   136     + '{{#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}}'
       
   138     + '<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>'
       
   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>'
       
   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>'
       
   142     + '</div></div>';
       
   143     
       
   144 IriSP.Widgets.CreateAnnotation.prototype.draw = function() {
       
   145     var _this = this;
       
   146     
       
   147     this.begin = new IriSP.Model.Time();
       
   148     this.end = this.source.getDuration();
       
   149     
       
   150     this.tag_prefix = this.tag_prefix || "";
       
   151     
       
   152     if (this.tag_titles && !this.tags) {
       
   153 		if(!(this.tag_titles.length==1 && this.tag_titles[0]=="")){
       
   154 			this.tags = IriSP._(this.tag_titles).map(function(_tag_title) {
       
   155 				var _tag,
       
   156 					_tags = _this.source.getTags().searchByTitle(_tag_title, true);
       
   157 				if (_tags.length) {
       
   158 					_tag = _tags[0];
       
   159 				} else {
       
   160 					_tag = new IriSP.Model.Tag(false, _this.source);
       
   161 					_this.source.getTags().push(_tag);
       
   162 					_tag.title = _tag_title;
       
   163 				}
       
   164 				return _tag;
       
   165 			});
       
   166         }
       
   167         else{
       
   168         	// we forced no tags if this.tag_titles = [''] (and not false)
       
   169         	this.tags = true;
       
   170         }
       
   171     }
       
   172     if (!this.tags) {
       
   173         this.tags = this.source.getTags()
       
   174             .sortBy(function (_tag) {
       
   175                 return -_tag.getAnnotations().length;
       
   176             })
       
   177             .slice(0, this.max_tags)
       
   178             .map(function(_tag) {
       
   179                 return _tag;
       
   180             });
       
   181         /* We have to use the map function because Mustache doesn't like our tags object */
       
   182     }
       
   183     this.record_swf = IriSP.getLib("recordMicSwf");
       
   184     this.renderTemplate();
       
   185     if (this.show_mic_record) {
       
   186         this.recorder = this.$.find("embed")[0];
       
   187         
       
   188         window.setAudioUrl = function(_url) {
       
   189             _this.audio_url = _url;
       
   190         }
       
   191     }
       
   192     if (this.show_slice) {
       
   193         this.insertSubwidget(
       
   194             this.$.find(".Ldt-CreateAnnotation-Slice"),
       
   195             {
       
   196                 type: "Slice",
       
   197                 show_arrow: this.show_arrow,
       
   198                 annotation_type: this.slice_annotation_type,
       
   199                 onBoundsChanged: function(_from, _to) {
       
   200                     _this.begin = new IriSP.Model.Time(_from || 0);
       
   201                     _this.end = new IriSP.Model.Time(_to || 0);
       
   202                     _this.$.find(".Ldt-CreateAnnotation-Begin").html(_this.begin.toString());
       
   203                     _this.$.find(".Ldt-CreateAnnotation-End").html(_this.end.toString());
       
   204                 }
       
   205             },
       
   206             "slice"
       
   207         );
       
   208     } else {
       
   209         if (this.show_arrow) {
       
   210             this.insertSubwidget(this.$.find(".Ldt-CreateAnnotation-Arrow"), {type: "Arrow"},"arrow");
       
   211         }
       
   212         this.onMediaEvent("timeupdate", function(_time) {
       
   213             _this.begin = new IriSP.Model.Time(_time || 0);
       
   214             _this.end = new IriSP.Model.Time(_time || 0);
       
   215             _this.$.find(".Ldt-CreateAnnotation-Begin").html(_this.begin.toString());
       
   216             if (_this.arrow) {
       
   217                 _this.arrow.moveToTime(_time);
       
   218             }
       
   219         });
       
   220     }
       
   221     this.$.find(".Ldt-CreateAnnotation-Close").click(function() {
       
   222         _this.close_after_send
       
   223         ? _this.hide()
       
   224         : _this.showScreen("Main");
       
   225         return false;
       
   226     });
       
   227     this.$.find(".Ldt-CreateAnnotation-TagLi, .Ldt-CreateAnnotation-PolemicLi").click(function() {
       
   228         _this.addKeyword(IriSP.jQuery(this).attr("data-text"));
       
   229         return false;
       
   230     });
       
   231     this.$.find(".Ldt-CreateAnnotation-PolemicLi").each(function() {
       
   232         var _el = IriSP.jQuery(this),
       
   233             _kw = _el.attr("data-text"),
       
   234             _msg = _this.l10n["polemic" + _kw];
       
   235         if (_msg) {
       
   236             _el.attr("title",_msg);
       
   237         }
       
   238     });
       
   239     this.$.find(".Ldt-CreateAnnotation-Description").bind("change keyup input paste", this.functionWrapper("onDescriptionChange"));
       
   240     if (this.show_title_field) {
       
   241         this.$.find(".Ldt-CreateAnnotation-Title").bind("change keyup input paste", this.functionWrapper("onTitleChange"));
       
   242     }
       
   243     if (this.show_creator_field) {
       
   244         this.$.find(".Ldt-CreateAnnotation-Creator").bind("change keyup input paste", this.functionWrapper("onCreatorChange"));
       
   245     }
       
   246     
       
   247     if (this.start_visible) {
       
   248         this.show();
       
   249     } else {
       
   250         this.$.hide();
       
   251         this.hide();
       
   252     }
       
   253     
       
   254     this.onMdpEvent("CreateAnnotation.toggle","toggle");
       
   255     this.$.find("form").submit(this.functionWrapper("onSubmit"));
       
   256 };
       
   257 
       
   258 IriSP.Widgets.CreateAnnotation.prototype.showScreen = function(_screenName) {
       
   259     this.$.find('.Ldt-CreateAnnotation-' + _screenName).show()
       
   260         .siblings().hide();
       
   261 }
       
   262 
       
   263 IriSP.Widgets.CreateAnnotation.prototype.show = function() {
       
   264     this.visible = true;
       
   265     this.showScreen('Main');
       
   266     this.$.find(".Ldt-CreateAnnotation-Description").val("").css("border-color", "#666666").addClass("empty");
       
   267     if (this.show_title_field) {
       
   268         this.$.find(".Ldt-CreateAnnotation-Title").val("").css("border-color", "#666666").addClass("empty");
       
   269     }
       
   270     if (this.show_creator_field) {
       
   271         this.$.find(".Ldt-CreateAnnotation-Creator").val(this.creator_name).css("border-color", "#666666");
       
   272         if (!this.creator_name) {
       
   273             this.$.find(".Ldt-CreateAnnotation-Creator").addClass("empty");
       
   274         }
       
   275     }
       
   276     this.$.find(".Ldt-CreateAnnotation-TagLi, .Ldt-CreateAnnotation-PolemicLi").removeClass("selected");
       
   277     this.$.slideDown();
       
   278     if (this.minimize_annotation_widget) {
       
   279         this.player.trigger("Annotation.minimize");
       
   280     }
       
   281 };
       
   282 
       
   283 IriSP.Widgets.CreateAnnotation.prototype.hide = function() {
       
   284     if (this.recorder) {
       
   285         this.recorder.stopRecord();
       
   286     }
       
   287     if (!this.always_visible) {
       
   288         this.visible = false;
       
   289         this.$.slideUp();
       
   290         if (this.minimize_annotation_widget) {
       
   291             this.player.trigger("Annotation.maximize");
       
   292         }
       
   293     }
       
   294 };
       
   295 
       
   296 IriSP.Widgets.CreateAnnotation.prototype.toggle = function() {
       
   297     if (!this.always_visible) {
       
   298         if (this.visible) {
       
   299             this.hide();
       
   300         } else {
       
   301             this.show();
       
   302         }
       
   303     }
       
   304 };
       
   305 
       
   306 IriSP.Widgets.CreateAnnotation.prototype.addKeyword = function(_keyword) {
       
   307     var _field = this.$.find(".Ldt-CreateAnnotation-Description"),
       
   308         _rx = IriSP.Model.regexpFromTextOrArray(_keyword),
       
   309         _contents = _field.val();
       
   310     _contents = ( !!_contents.match(_rx)
       
   311         ? _contents.replace(_rx,"")
       
   312         : _contents + " " + _keyword
       
   313     );
       
   314     _field.val(_contents.replace(/\s{2,}/g,' ').replace(/(^\s+|\s+$)/g,''));
       
   315     this.onDescriptionChange();
       
   316 };
       
   317 
       
   318 IriSP.Widgets.CreateAnnotation.prototype.pauseOnWrite = function() {
       
   319     if (this.pause_on_write && !this.media.getPaused()) {
       
   320         this.media.pause();
       
   321     }
       
   322 };
       
   323 
       
   324 IriSP.Widgets.CreateAnnotation.prototype.onDescriptionChange = function() {
       
   325     var _field = this.$.find(".Ldt-CreateAnnotation-Description"),
       
   326         _contents = _field.val();
       
   327     _field.css("border-color", !!_contents ? "#666666" : "#ff0000");
       
   328     if (!!_contents) {
       
   329         _field.removeClass("empty");
       
   330     } else {
       
   331         _field.addClass("empty");
       
   332     }
       
   333     this.$.find(".Ldt-CreateAnnotation-TagLi, .Ldt-CreateAnnotation-PolemicLi").each(function() {
       
   334         var _rx = IriSP.Model.regexpFromTextOrArray(IriSP.jQuery(this).attr("data-text"));
       
   335         if (_contents.match(_rx)) {
       
   336             IriSP.jQuery(this).addClass("selected");
       
   337         } else {
       
   338             IriSP.jQuery(this).removeClass("selected");
       
   339         }
       
   340     });
       
   341     this.pauseOnWrite();
       
   342     return !!_contents;
       
   343 };
       
   344 
       
   345 IriSP.Widgets.CreateAnnotation.prototype.onTitleChange = function() {
       
   346     var _field = this.$.find(".Ldt-CreateAnnotation-Title"),
       
   347         _contents = _field.val();
       
   348     _field.css("border-color", !!_contents ? "#666666" : "#ff0000");
       
   349     if (!!_contents) {
       
   350         _field.removeClass("empty");
       
   351     } else {
       
   352         _field.addClass("empty");
       
   353     }
       
   354     this.pauseOnWrite();
       
   355     return !!_contents;
       
   356 };
       
   357 
       
   358 
       
   359 IriSP.Widgets.CreateAnnotation.prototype.onCreatorChange = function() {
       
   360     var _field = this.$.find(".Ldt-CreateAnnotation-Creator"),
       
   361         _contents = _field.val();
       
   362     _field.css("border-color", !!_contents ? "#666666" : "#ff0000");
       
   363     if (!!_contents) {
       
   364         _field.removeClass("empty");
       
   365     } else {
       
   366         _field.addClass("empty");
       
   367     }
       
   368     this.pauseOnWrite();
       
   369     return !!_contents;
       
   370 };
       
   371 
       
   372 /* Fonction effectuant l'envoi des annotations */
       
   373 IriSP.Widgets.CreateAnnotation.prototype.onSubmit = function() {
       
   374     /* 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())) {
       
   376         return false;
       
   377     }
       
   378     
       
   379     if (this.recorder) {
       
   380         this.recorder.stopRecord();
       
   381     }
       
   382     
       
   383     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 */
       
   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 */
       
   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) */
       
   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 */
       
   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 */
       
   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 */
       
   390     
       
   391     /* Si nous avons dû générer un ID d'annotationType à la volée... */
       
   392     if (!_annotationTypes.length) {
       
   393         /* Il ne faudra pas envoyer l'ID généré au serveur */
       
   394         _annotationType.dont_send_id = true;
       
   395         /* Il faut inclure le titre dans le type d'annotation */
       
   396         _annotationType.title = this.annotation_type;
       
   397     }
       
   398     
       
   399     /*
       
   400      * 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
       
   402      * */
       
   403     _annotation.setMedia(this.source.currentMedia.id); /* Id du média annoté */
       
   404     _annotation.setBegin(this.begin); /*Timecode de début */
       
   405     _annotation.setEnd(this.end); /* Timecode de fin */
       
   406    
       
   407     _annotation.setAnnotationType(_annotationType.id); /* Id du type d'annotation */
       
   408     if (this.show_title_field) {
       
   409         /* Champ titre, seulement s'il est visible */
       
   410         _annotation.title = this.$.find(".Ldt-CreateAnnotation-Title").val();
       
   411     }
       
   412     _annotation.created = new Date(); /* Date de création de l'annotation */
       
   413     _annotation.description = this.$.find(".Ldt-CreateAnnotation-Description").val(); /* Champ description */
       
   414    
       
   415     var tagIds = Array.prototype.map.call(
       
   416         this.$.find(".Ldt-CreateAnnotation-TagLi.selected"),
       
   417         function(el) { return IriSP.jQuery(el).attr("tag-id")}
       
   418     );
       
   419         
       
   420     IriSP._(_annotation.description.match(/#[^\s#.,;]+/g)).each(function(_tt) {
       
   421         var _tag,
       
   422             _tag_title = _tt.replace(/^#/,''),
       
   423             _tags = _this.source.getTags().searchByTitle(_tag_title, true);
       
   424         if (_tags.length) {
       
   425             _tag = _tags[0];
       
   426         } else {
       
   427             _tag = new IriSP.Model.Tag(false, _this.source);
       
   428             _this.source.getTags().push(_tag);
       
   429             _tag.title = _tag_title;
       
   430         }
       
   431         if (tagIds.indexOf(_tag.id) === -1) {
       
   432             tagIds.push(_tag.id);
       
   433         }
       
   434         
       
   435     })
       
   436    
       
   437     _annotation.setTags(IriSP._(tagIds).uniq()); /*Liste des ids de tags */
       
   438     if (this.audio_url) {
       
   439         _annotation.audio = {
       
   440             src: "mic",
       
   441             mimetype: "audio/mp3",
       
   442             href: this.audio_url
       
   443         };
       
   444     }
       
   445     if (this.show_creator_field) {
       
   446         _annotation.creator = this.$.find(".Ldt-CreateAnnotation-Creator").val();
       
   447     } else {
       
   448         _annotation.creator = this.creator_name;
       
   449     }
       
   450     _exportedAnnotations.push(_annotation); /* Ajout de l'annotation à la liste à exporter */
       
   451     _export.addList("annotation",_exportedAnnotations); /* Ajout de la liste à exporter à l'objet Source */
       
   452     
       
   453     var _this = this;
       
   454     /* Envoi de l'annotation via AJAX au serveur ! */
       
   455     IriSP.jQuery.ajax({
       
   456         url: _url,
       
   457         type: this.api_method,
       
   458         contentType: 'application/json',
       
   459         data: _export.serialize(), /* L'objet Source est sérialisé */
       
   460         success: function(_data) {
       
   461             _this.showScreen('Saved'); /* Si l'appel a fonctionné, on affiche l'écran "Annotation enregistrée" */
       
   462             if (_this.after_send_timeout) { /* Selon les options de configuration, on revient à l'écran principal ou on ferme le widget, ou rien */
       
   463                 window.setTimeout(
       
   464                     function() {
       
   465                         _this.close_after_send
       
   466                         ? _this.hide()
       
   467                         : _this.show();
       
   468                     },
       
   469                     _this.after_send_timeout
       
   470                 );
       
   471             }
       
   472             _export.getAnnotations().removeElement(_annotation, true); /* Pour éviter les doublons, on supprime l'annotation qui a été envoyée */
       
   473             _export.deSerialize(_data); /* On désérialise les données reçues pour les réinjecter */
       
   474             _this.source.merge(_export); /* On récupère les données réimportées dans l'espace global des données */
       
   475             if (_this.pause_on_write && _this.media.getPaused()) {
       
   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;
       
   493 };
       
   494