FIX: Editing tags was double rendering

This commit is contained in:
Robin Ward 2016-12-15 10:40:11 -05:00
parent 2655be512f
commit d69b782737
1 changed files with 22 additions and 19 deletions

View File

@ -8,10 +8,17 @@ export default Ember.TextField.extend({
classNameBindings: [':tag-chooser'],
attributeBindings: ['tabIndex', 'placeholderKey', 'categoryId'],
_initValue: function() {
init() {
this._super();
const tags = this.get('tags') || [];
this.set('value', tags.join(", "));
}.on('init'),
if (this.get('allowCreate') !== false) {
this.set('allowCreate', this.site.get('can_create_tag'));
}
this.set('termMatchesForbidden', false);
},
_valueChanged: function() {
const tags = this.get('value').split(',').map(v => v.trim()).reject(v => v.length === 0).uniq();
@ -32,18 +39,13 @@ export default Ember.TextField.extend({
}
}.observes('tags'),
_initializeTags: function() {
const site = this.site,
self = this,
filterRegexp = new RegExp(this.site.tags_filter_regexp, "g");
didInsertElement() {
this._super();
var limit = this.siteSettings.max_tags_per_topic;
const self = this;
const filterRegexp = new RegExp(this.site.tags_filter_regexp, "g");
if (this.get('allowCreate') !== false) {
this.set('allowCreate', site.get('can_create_tag'));
}
this.set('termMatchesForbidden', false);
let limit = this.siteSettings.max_tags_per_topic;
if (this.get('unlimitedTagCount')) {
limit = null;
@ -77,7 +79,7 @@ export default Ember.TextField.extend({
callback(data);
},
createSearchChoice: function(term, data) {
createSearchChoice(term, data) {
term = term.replace(filterRegexp, '').trim().toLowerCase();
// No empty terms, make sure the user has permission to create the tag
@ -89,14 +91,14 @@ export default Ember.TextField.extend({
return { id: term, text: term };
}
},
createSearchChoicePosition: function(list, item) {
createSearchChoicePosition(list, item) {
// Search term goes on the bottom
list.push(item);
},
formatSelection: function (data) {
formatSelection(data) {
return data ? renderTag(this.text(data)) : undefined;
},
formatSelectionCssClass: function(){
formatSelectionCssClass() {
return "discourse-tag-select2";
},
formatResult: formatTag,
@ -127,10 +129,11 @@ export default Ember.TextField.extend({
}
},
});
}.on('didInsertElement'),
},
_destroyTags: function() {
willDestroyElement() {
this._super();
this.$().select2('destroy');
}.on('willDestroyElement')
}
});