FIX: Editing tags was double rendering
This commit is contained in:
parent
2655be512f
commit
d69b782737
|
@ -8,10 +8,17 @@ export default Ember.TextField.extend({
|
||||||
classNameBindings: [':tag-chooser'],
|
classNameBindings: [':tag-chooser'],
|
||||||
attributeBindings: ['tabIndex', 'placeholderKey', 'categoryId'],
|
attributeBindings: ['tabIndex', 'placeholderKey', 'categoryId'],
|
||||||
|
|
||||||
_initValue: function() {
|
init() {
|
||||||
|
this._super();
|
||||||
const tags = this.get('tags') || [];
|
const tags = this.get('tags') || [];
|
||||||
this.set('value', tags.join(", "));
|
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() {
|
_valueChanged: function() {
|
||||||
const tags = this.get('value').split(',').map(v => v.trim()).reject(v => v.length === 0).uniq();
|
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'),
|
}.observes('tags'),
|
||||||
|
|
||||||
_initializeTags: function() {
|
didInsertElement() {
|
||||||
const site = this.site,
|
this._super();
|
||||||
self = this,
|
|
||||||
filterRegexp = new RegExp(this.site.tags_filter_regexp, "g");
|
|
||||||
|
|
||||||
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) {
|
let limit = this.siteSettings.max_tags_per_topic;
|
||||||
this.set('allowCreate', site.get('can_create_tag'));
|
|
||||||
}
|
|
||||||
|
|
||||||
this.set('termMatchesForbidden', false);
|
|
||||||
|
|
||||||
if (this.get('unlimitedTagCount')) {
|
if (this.get('unlimitedTagCount')) {
|
||||||
limit = null;
|
limit = null;
|
||||||
|
@ -77,7 +79,7 @@ export default Ember.TextField.extend({
|
||||||
|
|
||||||
callback(data);
|
callback(data);
|
||||||
},
|
},
|
||||||
createSearchChoice: function(term, data) {
|
createSearchChoice(term, data) {
|
||||||
term = term.replace(filterRegexp, '').trim().toLowerCase();
|
term = term.replace(filterRegexp, '').trim().toLowerCase();
|
||||||
|
|
||||||
// No empty terms, make sure the user has permission to create the tag
|
// 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 };
|
return { id: term, text: term };
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
createSearchChoicePosition: function(list, item) {
|
createSearchChoicePosition(list, item) {
|
||||||
// Search term goes on the bottom
|
// Search term goes on the bottom
|
||||||
list.push(item);
|
list.push(item);
|
||||||
},
|
},
|
||||||
formatSelection: function (data) {
|
formatSelection(data) {
|
||||||
return data ? renderTag(this.text(data)) : undefined;
|
return data ? renderTag(this.text(data)) : undefined;
|
||||||
},
|
},
|
||||||
formatSelectionCssClass: function(){
|
formatSelectionCssClass() {
|
||||||
return "discourse-tag-select2";
|
return "discourse-tag-select2";
|
||||||
},
|
},
|
||||||
formatResult: formatTag,
|
formatResult: formatTag,
|
||||||
|
@ -127,10 +129,11 @@ export default Ember.TextField.extend({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}.on('didInsertElement'),
|
},
|
||||||
|
|
||||||
_destroyTags: function() {
|
willDestroyElement() {
|
||||||
|
this._super();
|
||||||
this.$().select2('destroy');
|
this.$().select2('destroy');
|
||||||
}.on('willDestroyElement')
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue