216 }); |
216 }); |
217 new_title = this.$.find(".Ldt-CurrentSegmentInfobox-TitleInput").val() |
217 new_title = this.$.find(".Ldt-CurrentSegmentInfobox-TitleInput").val() |
218 new_description = this.$.find(".Ldt-CurrentSegmentInfobox-DescriptionInput").val() |
218 new_description = this.$.find(".Ldt-CurrentSegmentInfobox-DescriptionInput").val() |
219 |
219 |
220 var _this = this, |
220 var _this = this, |
221 _exportedAnnotations = new IriSP.Model.List(this.player.sourceManager), /* Création d'une liste d'annotations contenant une annotation afin de l'envoyer au serveur */ |
221 _exportedAnnotations = new IriSP.Model.List(this.player.sourceManager), /* We create an Annotations List to send to the server */ |
222 _export = this.player.sourceManager.newLocalSource({serializer: IriSP.serializers[this.api_serializer]}), |
222 _export = this.player.sourceManager.newLocalSource({serializer: IriSP.serializers[this.api_serializer]}), /* We create a source object using a specific serializer for export */ |
223 _annotation = new IriSP.Model.Annotation(this.currentSegment.id, _export); /* Création d'une annotation dans cette source avec un ID généré à la volée (param. false) */ |
223 _annotation = new IriSP.Model.Annotation(this.currentSegment.id, _export); /* We create an annotation in the source with a generated ID (param. false) */ |
224 |
224 |
225 _annotation.setAnnotationType(this.currentSegment.getAnnotationType().id); |
225 _annotation.setAnnotationType(this.currentSegment.getAnnotationType().id); |
226 _annotation.setMedia(this.currentSegment.getMedia().id); |
226 _annotation.setMedia(this.currentSegment.getMedia().id); |
227 _annotation.setBegin(this.currentSegment.begin); |
227 _annotation.setBegin(this.currentSegment.begin); |
228 _annotation.setEnd(this.currentSegment.end); |
228 _annotation.setEnd(this.currentSegment.end); |
229 _annotation.created = this.currentSegment.created; |
229 _annotation.created = this.currentSegment.created; |
230 _annotation.creator = this.currentSegment.creator; |
230 _annotation.creator = this.currentSegment.creator; |
231 _annotation.title = new_title /* Champ titre */ |
231 _annotation.title = new_title /* Title field */ |
232 _annotation.description = new_description /* Champ description */ |
232 _annotation.description = new_description /* Description field */ |
233 var _tagIds = IriSP._(new_tags_titles).map(function(_title) { |
233 var _tagIds = IriSP._(new_tags_titles).map(function(_title) { |
234 var _tags = _this.source.getTags(true).searchByTitle(_title, true); |
234 var _tags = _this.source.getTags(true).searchByTitle(_title, true); |
235 if (_tags.length) { |
235 if (_tags.length) { |
236 var _tag = _tags[0]; |
236 var _tag = _tags[0]; |
237 } |
237 } |
243 return _tag.id; |
243 return _tag.id; |
244 }); |
244 }); |
245 _annotation.setTags(_tagIds); |
245 _annotation.setTags(_tagIds); |
246 _annotation.project_id = this.project_id; |
246 _annotation.project_id = this.project_id; |
247 |
247 |
248 _exportedAnnotations.push(_annotation); /* Ajout de l'annotation à la liste à exporter */ |
248 _exportedAnnotations.push(_annotation); /* We add the annotation in the list to export */ |
249 _export.addList("annotation",_exportedAnnotations); /* Ajout de la liste à exporter à l'objet Source */ |
249 _export.addList("annotation",_exportedAnnotations); /* We add the list to the source object */ |
250 |
250 |
251 _url = Mustache.to_html(this.api_endpoint_template, {annotation_id: this.currentSegment.id}); |
251 _url = Mustache.to_html(this.api_endpoint_template, {annotation_id: this.currentSegment.id}); |
252 |
252 |
253 IriSP.jQuery.ajax({ |
253 IriSP.jQuery.ajax({ |
254 url: _url, |
254 url: _url, |
255 type: this.api_method, |
255 type: this.api_method, |
256 contentType: 'application/json', |
256 contentType: 'application/json', |
257 data: _export.serialize(), /* L'objet Source est sérialisé */ |
257 data: _export.serialize(), /* Source is serialized */ |
258 success: function(_data) { |
258 success: function(_data) { |
259 _export.getAnnotations().removeElement(_annotation, true); /* Pour éviter les doublons, on supprime l'annotation qui a été envoyée */ |
259 _export.getAnnotations().removeElement(_annotation, true); /* We delete the sent annotation to avoid redundancy */ |
260 _export.deSerialize(_data); /* On désérialise les données reçues pour les réinjecter */ |
260 _export.deSerialize(_data); /* Data deserialization */ |
261 _this.source.merge(_export); /* On récupère les données réimportées dans l'espace global des données */ |
261 _this.source.merge(_export); /* We merge the deserialized data with the current source data */ |
262 _this.segments.forEach(function(_segment){ |
262 _this.segments.forEach(function(_segment){ |
263 if (_segment.id == _annotation.id){ |
263 if (_segment.id == _annotation.id){ |
264 _this.segments.removeElement(_segment) |
264 _this.segments.removeElement(_segment) |
265 } |
265 } |
266 }) |
266 }) |