src/widgets/CreateAnnotation.js
changeset 988 eefd336335f9
parent 986 f9d51dd4a3fe
child 1002 a86208b60c91
equal deleted inserted replaced
987:7b65bf78873a 988:eefd336335f9
   147     this.end = this.source.getDuration();
   147     this.end = this.source.getDuration();
   148     
   148     
   149     if (this.tag_titles && !this.tags) {
   149     if (this.tag_titles && !this.tags) {
   150         this.tags = IriSP._(this.tag_titles).map(function(_tag_title) {
   150         this.tags = IriSP._(this.tag_titles).map(function(_tag_title) {
   151             var _tag,
   151             var _tag,
   152                 _tags = _this.source.getTags().searchByTitle(_tag_title);
   152                 _tags = _this.source.getTags().searchByTitle(_tag_title, true);
   153             if (_tags.length) {
   153             if (_tags.length) {
   154                 _tag = _tags[0];
   154                 _tag = _tags[0];
   155             } else {
   155             } else {
   156                 _tag = new IriSP.Model.Tag(false, _this.source);
   156                 _tag = new IriSP.Model.Tag(false, _this.source);
   157                 _tag.title = _tag_title;
   157                 _tag.title = _tag_title;
   368     
   368     
   369     if (this.recorder) {
   369     if (this.recorder) {
   370         this.recorder.stopRecord();
   370         this.recorder.stopRecord();
   371     }
   371     }
   372     
   372     
   373     var _exportedAnnotations = new IriSP.Model.List(this.player.sourceManager), /* Création d'une liste d'annotations contenant une annotation afin de l'envoyer au serveur */
   373     var _this = this,
       
   374         _exportedAnnotations = new IriSP.Model.List(this.player.sourceManager), /* Création d'une liste d'annotations contenant une annotation afin de l'envoyer au serveur */
   374         _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 */
   375         _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 */
   375         _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) */
   376         _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) */
   376         _annotationTypes = this.source.getAnnotationTypes().searchByTitle(this.annotation_type), /* Récupération du type d'annotation dans lequel l'annotation doit être ajoutée */
   377         _annotationTypes = this.source.getAnnotationTypes().searchByTitle(this.annotation_type, true), /* Récupération du type d'annotation dans lequel l'annotation doit être ajoutée */
   377         _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 */
   378         _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 */
   378         _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 */
   379         _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 */
   379     
   380     
   380     /* Si nous avons dû générer un ID d'annotationType à la volée... */
   381     /* Si nous avons dû générer un ID d'annotationType à la volée... */
   381     if (!_annotationTypes.length) {
   382     if (!_annotationTypes.length) {
   398         /* Champ titre, seulement s'il est visible */
   399         /* Champ titre, seulement s'il est visible */
   399         _annotation.title = this.$.find(".Ldt-CreateAnnotation-Title").val();
   400         _annotation.title = this.$.find(".Ldt-CreateAnnotation-Title").val();
   400     }
   401     }
   401     _annotation.created = new Date(); /* Date de création de l'annotation */
   402     _annotation.created = new Date(); /* Date de création de l'annotation */
   402     _annotation.description = this.$.find(".Ldt-CreateAnnotation-Description").val(); /* Champ description */
   403     _annotation.description = this.$.find(".Ldt-CreateAnnotation-Description").val(); /* Champ description */
   403     _annotation.setTags(this.$.find(".Ldt-CreateAnnotation-TagLi.selected")
   404    
   404         .map(function() { return IriSP.jQuery(this).attr("tag-id")})); /*Liste des ids de tags */
   405     var tagIds = this.$.find(".Ldt-CreateAnnotation-TagLi.selected")
       
   406         .map(function() { return IriSP.jQuery(this).attr("tag-id")});
       
   407     
       
   408     IriSP._(_annotation.description.match(/#[\w\d]+/g)).each(function(_tt) {
       
   409         var _tag,
       
   410             _tag_title = _tt.replace(/^#/,'')
       
   411             _tags = _this.source.getTags().searchByTitle(_tag_title, true);
       
   412         if (_tags.length) {
       
   413             _tag = _tags[0];
       
   414         } else {
       
   415             _tag = new IriSP.Model.Tag(false, _this.source);
       
   416             _tag.title = _tag_title;
       
   417         }
       
   418         tagIds.push(_tag.id);
       
   419     })
       
   420    
       
   421     _annotation.setTags(IriSP._(tagIds).uniq()); /*Liste des ids de tags */
   405     if (this.audio_url) {
   422     if (this.audio_url) {
   406         _annotation.audio = {
   423         _annotation.audio = {
   407             src: "mic",
   424             src: "mic",
   408             mimetype: "audio/mp3",
   425             mimetype: "audio/mp3",
   409             href: this.audio_url
   426             href: this.audio_url