# HG changeset patch # User veltr # Date 1371660886 -7200 # Node ID a4dc93a91a95b7387bf2f4893071ea8f79efc47a # Parent a86208b60c91d1146ee58383b93ea65c885cc421 Hashtags fix diff -r a86208b60c91 -r a4dc93a91a95 src/widgets/CreateAnnotation.js --- a/src/widgets/CreateAnnotation.js Tue Jun 18 11:08:50 2013 +0200 +++ b/src/widgets/CreateAnnotation.js Wed Jun 19 18:54:46 2013 +0200 @@ -46,6 +46,7 @@ api_method: "POST", after_send_timeout: 0, close_after_send: false, + tag_prefix: "#" } IriSP.Widgets.CreateAnnotation.prototype.messages = { @@ -131,9 +132,9 @@ + ' ' + '{{/show_mic_record}}' + '{{#tags.length}}
{{l10n.add_keywords_}}
{{/tags.length}}' + + '{{#tags}}
  • {{title}}
  • {{/tags}}{{/tags.length}}' + '{{#polemics.length}}
    {{l10n.add_polemic_keywords_}}
    {{/polemics.length}}' + + '{{#polemics}}
  • {{keyword}}
  • {{/polemics}}{{/polemics.length}}' + '
    ' + '
    {{l10n.wait_while_processing}}
    ' + '
    {{^always_visible}}{{/always_visible}}
    {{l10n.error_while_contacting}}
    ' @@ -146,6 +147,8 @@ this.begin = new IriSP.Model.Time(); this.end = this.source.getDuration(); + this.tag_prefix = this.tag_prefix || ""; + if (this.tag_titles && !this.tags) { this.tags = IriSP._(this.tag_titles).map(function(_tag_title) { var _tag, @@ -154,6 +157,7 @@ _tag = _tags[0]; } else { _tag = new IriSP.Model.Tag(false, _this.source); + _this.source.getTags().push(_tag); _tag.title = _tag_title; } return _tag; @@ -215,12 +219,12 @@ return false; }); this.$.find(".Ldt-CreateAnnotation-TagLi, .Ldt-CreateAnnotation-PolemicLi").click(function() { - _this.addKeyword(IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,'')); + _this.addKeyword(IriSP.jQuery(this).attr("data-text")); return false; }); this.$.find(".Ldt-CreateAnnotation-PolemicLi").each(function() { var _el = IriSP.jQuery(this), - _kw = _el.text().replace(/(^\s+|\s+$)/g,''), + _kw = _el.attr("data-text"), _msg = _this.l10n["polemic" + _kw]; if (_msg) { _el.attr("title",_msg); @@ -321,7 +325,7 @@ _field.addClass("empty"); } this.$.find(".Ldt-CreateAnnotation-TagLi, .Ldt-CreateAnnotation-PolemicLi").each(function() { - var _rx = IriSP.Model.regexpFromTextOrArray(IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,'')); + var _rx = IriSP.Model.regexpFromTextOrArray(IriSP.jQuery(this).attr("data-text")); if (_contents.match(_rx)) { IriSP.jQuery(this).addClass("selected"); } else { @@ -402,20 +406,26 @@ _annotation.created = new Date(); /* Date de création de l'annotation */ _annotation.description = this.$.find(".Ldt-CreateAnnotation-Description").val(); /* Champ description */ - var tagIds = this.$.find(".Ldt-CreateAnnotation-TagLi.selected") - .map(function() { return IriSP.jQuery(this).attr("tag-id")}); - - IriSP._(_annotation.description.match(/#[\w\d]+/g)).each(function(_tt) { + var tagIds = Array.prototype.map.call( + this.$.find(".Ldt-CreateAnnotation-TagLi.selected"), + function(el) { return IriSP.jQuery(el).attr("tag-id")} + ); + + IriSP._(_annotation.description.match(/#[^\s#.,;]+/g)).each(function(_tt) { var _tag, - _tag_title = _tt.replace(/^#/,'') + _tag_title = _tt.replace(/^#/,''), _tags = _this.source.getTags().searchByTitle(_tag_title, true); if (_tags.length) { _tag = _tags[0]; } else { _tag = new IriSP.Model.Tag(false, _this.source); + _this.source.getTags().push(_tag); _tag.title = _tag_title; } - tagIds.push(_tag.id); + if (tagIds.indexOf(_tag.id) === -1) { + tagIds.push(_tag.id); + } + }) _annotation.setTags(IriSP._(tagIds).uniq()); /*Liste des ids de tags */