src/widgets/CreateAnnotation.js
changeset 1003 a4dc93a91a95
parent 1002 a86208b60c91
child 1013 392ddcd212d7
equal deleted inserted replaced
1002:a86208b60c91 1003:a4dc93a91a95
    44     api_serializer: "ldt_annotate",
    44     api_serializer: "ldt_annotate",
    45     api_endpoint_template: "",
    45     api_endpoint_template: "",
    46     api_method: "POST",
    46     api_method: "POST",
    47     after_send_timeout: 0,
    47     after_send_timeout: 0,
    48     close_after_send: false,
    48     close_after_send: false,
       
    49     tag_prefix: "#"
    49 }
    50 }
    50 
    51 
    51 IriSP.Widgets.CreateAnnotation.prototype.messages = {
    52 IriSP.Widgets.CreateAnnotation.prototype.messages = {
    52     en: {
    53     en: {
    53         from_time: "from",
    54         from_time: "from",
   129     + '             pluginspage="http://www.macromedia.com/go/getflashplayer">'
   130     + '             pluginspage="http://www.macromedia.com/go/getflashplayer">'
   130     + '        </embed>'
   131     + '        </embed>'
   131     + '    </object>'
   132     + '    </object>'
   132     + '</div>{{/show_mic_record}}' 
   133     + '</div>{{/show_mic_record}}' 
   133     + '{{#tags.length}}<div class="Ldt-CreateAnnotation-Tags"><div class="Ldt-CreateAnnotation-TagTitle">{{l10n.add_keywords_}}</div><ul class="Ldt-CreateAnnotation-TagList">'
   134     + '{{#tags.length}}<div class="Ldt-CreateAnnotation-Tags"><div class="Ldt-CreateAnnotation-TagTitle">{{l10n.add_keywords_}}</div><ul class="Ldt-CreateAnnotation-TagList">'
   134     + '{{#tags}}<li class="Ldt-CreateAnnotation-TagLi" tag-id="{{id}}"><span class="Ldt-CreateAnnotation-TagButton">{{title}}</span></li>{{/tags}}</ul></div>{{/tags.length}}'
   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}}'
   135     + '{{#polemics.length}}<div class="Ldt-CreateAnnotation-Polemics"><div class="Ldt-CreateAnnotation-PolemicTitle">{{l10n.add_polemic_keywords_}}</div><ul class="Ldt-CreateAnnotation-PolemicList">'
   136     + '{{#polemics.length}}<div class="Ldt-CreateAnnotation-Polemics"><div class="Ldt-CreateAnnotation-PolemicTitle">{{l10n.add_polemic_keywords_}}</div><ul class="Ldt-CreateAnnotation-PolemicList">'
   136     + '{{#polemics}}<li class="Ldt-CreateAnnotation-PolemicLi" style="background-color: {{background_color}}; color: {{text_color}}">{{keyword}}</li>{{/polemics}}</ul></div>{{/polemics.length}}'
   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}}'
   137     + '<div style="clear: both;"></div></form>'
   138     + '<div style="clear: both;"></div></form>'
   138     + '<div class="Ldt-CreateAnnotation-Screen Ldt-CreateAnnotation-Wait"><div class="Ldt-CreateAnnotation-InnerBox">{{l10n.wait_while_processing}}</div></div>'
   139     + '<div class="Ldt-CreateAnnotation-Screen Ldt-CreateAnnotation-Wait"><div class="Ldt-CreateAnnotation-InnerBox">{{l10n.wait_while_processing}}</div></div>'
   139     + '<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>'
   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>'
   140     + '<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>'
   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>'
   141     + '</div></div>';
   142     + '</div></div>';
   143 IriSP.Widgets.CreateAnnotation.prototype.draw = function() {
   144 IriSP.Widgets.CreateAnnotation.prototype.draw = function() {
   144     var _this = this;
   145     var _this = this;
   145     
   146     
   146     this.begin = new IriSP.Model.Time();
   147     this.begin = new IriSP.Model.Time();
   147     this.end = this.source.getDuration();
   148     this.end = this.source.getDuration();
       
   149     
       
   150     this.tag_prefix = this.tag_prefix || "";
   148     
   151     
   149     if (this.tag_titles && !this.tags) {
   152     if (this.tag_titles && !this.tags) {
   150         this.tags = IriSP._(this.tag_titles).map(function(_tag_title) {
   153         this.tags = IriSP._(this.tag_titles).map(function(_tag_title) {
   151             var _tag,
   154             var _tag,
   152                 _tags = _this.source.getTags().searchByTitle(_tag_title, true);
   155                 _tags = _this.source.getTags().searchByTitle(_tag_title, true);
   153             if (_tags.length) {
   156             if (_tags.length) {
   154                 _tag = _tags[0];
   157                 _tag = _tags[0];
   155             } else {
   158             } else {
   156                 _tag = new IriSP.Model.Tag(false, _this.source);
   159                 _tag = new IriSP.Model.Tag(false, _this.source);
       
   160                 _this.source.getTags().push(_tag);
   157                 _tag.title = _tag_title;
   161                 _tag.title = _tag_title;
   158             }
   162             }
   159             return _tag;
   163             return _tag;
   160         });
   164         });
   161     }
   165     }
   213         ? _this.hide()
   217         ? _this.hide()
   214         : _this.showScreen("Main");
   218         : _this.showScreen("Main");
   215         return false;
   219         return false;
   216     });
   220     });
   217     this.$.find(".Ldt-CreateAnnotation-TagLi, .Ldt-CreateAnnotation-PolemicLi").click(function() {
   221     this.$.find(".Ldt-CreateAnnotation-TagLi, .Ldt-CreateAnnotation-PolemicLi").click(function() {
   218         _this.addKeyword(IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,''));
   222         _this.addKeyword(IriSP.jQuery(this).attr("data-text"));
   219         return false;
   223         return false;
   220     });
   224     });
   221     this.$.find(".Ldt-CreateAnnotation-PolemicLi").each(function() {
   225     this.$.find(".Ldt-CreateAnnotation-PolemicLi").each(function() {
   222         var _el = IriSP.jQuery(this),
   226         var _el = IriSP.jQuery(this),
   223             _kw = _el.text().replace(/(^\s+|\s+$)/g,''),
   227             _kw = _el.attr("data-text"),
   224             _msg = _this.l10n["polemic" + _kw];
   228             _msg = _this.l10n["polemic" + _kw];
   225         if (_msg) {
   229         if (_msg) {
   226             _el.attr("title",_msg);
   230             _el.attr("title",_msg);
   227         }
   231         }
   228     });
   232     });
   319         _field.removeClass("empty");
   323         _field.removeClass("empty");
   320     } else {
   324     } else {
   321         _field.addClass("empty");
   325         _field.addClass("empty");
   322     }
   326     }
   323     this.$.find(".Ldt-CreateAnnotation-TagLi, .Ldt-CreateAnnotation-PolemicLi").each(function() {
   327     this.$.find(".Ldt-CreateAnnotation-TagLi, .Ldt-CreateAnnotation-PolemicLi").each(function() {
   324         var _rx = IriSP.Model.regexpFromTextOrArray(IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,''));
   328         var _rx = IriSP.Model.regexpFromTextOrArray(IriSP.jQuery(this).attr("data-text"));
   325         if (_contents.match(_rx)) {
   329         if (_contents.match(_rx)) {
   326             IriSP.jQuery(this).addClass("selected");
   330             IriSP.jQuery(this).addClass("selected");
   327         } else {
   331         } else {
   328             IriSP.jQuery(this).removeClass("selected");
   332             IriSP.jQuery(this).removeClass("selected");
   329         }
   333         }
   400         _annotation.title = this.$.find(".Ldt-CreateAnnotation-Title").val();
   404         _annotation.title = this.$.find(".Ldt-CreateAnnotation-Title").val();
   401     }
   405     }
   402     _annotation.created = new Date(); /* Date de création de l'annotation */
   406     _annotation.created = new Date(); /* Date de création de l'annotation */
   403     _annotation.description = this.$.find(".Ldt-CreateAnnotation-Description").val(); /* Champ description */
   407     _annotation.description = this.$.find(".Ldt-CreateAnnotation-Description").val(); /* Champ description */
   404    
   408    
   405     var tagIds = this.$.find(".Ldt-CreateAnnotation-TagLi.selected")
   409     var tagIds = Array.prototype.map.call(
   406         .map(function() { return IriSP.jQuery(this).attr("tag-id")});
   410         this.$.find(".Ldt-CreateAnnotation-TagLi.selected"),
   407     
   411         function(el) { return IriSP.jQuery(el).attr("tag-id")}
   408     IriSP._(_annotation.description.match(/#[\w\d]+/g)).each(function(_tt) {
   412     );
       
   413         
       
   414     IriSP._(_annotation.description.match(/#[^\s#.,;]+/g)).each(function(_tt) {
   409         var _tag,
   415         var _tag,
   410             _tag_title = _tt.replace(/^#/,'')
   416             _tag_title = _tt.replace(/^#/,''),
   411             _tags = _this.source.getTags().searchByTitle(_tag_title, true);
   417             _tags = _this.source.getTags().searchByTitle(_tag_title, true);
   412         if (_tags.length) {
   418         if (_tags.length) {
   413             _tag = _tags[0];
   419             _tag = _tags[0];
   414         } else {
   420         } else {
   415             _tag = new IriSP.Model.Tag(false, _this.source);
   421             _tag = new IriSP.Model.Tag(false, _this.source);
       
   422             _this.source.getTags().push(_tag);
   416             _tag.title = _tag_title;
   423             _tag.title = _tag_title;
   417         }
   424         }
   418         tagIds.push(_tag.id);
   425         if (tagIds.indexOf(_tag.id) === -1) {
       
   426             tagIds.push(_tag.id);
       
   427         }
       
   428         
   419     })
   429     })
   420    
   430    
   421     _annotation.setTags(IriSP._(tagIds).uniq()); /*Liste des ids de tags */
   431     _annotation.setTags(IriSP._(tagIds).uniq()); /*Liste des ids de tags */
   422     if (this.audio_url) {
   432     if (this.audio_url) {
   423         _annotation.audio = {
   433         _annotation.audio = {