Skip to content

Commit

Permalink
REFACTOR: tags mixin (#7533)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjaffeux committed May 13, 2019
1 parent b8db702 commit 7326dde
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions app/assets/javascripts/select-kit/mixins/tags.js.es6
Expand Up @@ -11,8 +11,6 @@ export default Ember.Mixin.create({
},

searchTags(url, data, callback) {
const self = this;

this.startLoading();

return ajax(Discourse.getURL(url), {
Expand All @@ -22,15 +20,11 @@ export default Ember.Mixin.create({
data
})
.then(json => {
self.set("asyncContent", callback(self, json));
self.autoHighlight();
})
.catch(error => {
popupAjaxError(error);
this.set("asyncContent", callback(this, json));
this.autoHighlight();
})
.finally(() => {
self.stopLoading();
});
.catch(error => popupAjaxError(error))
.finally(() => this.stopLoading());
},

validateCreate(term) {
Expand Down Expand Up @@ -63,6 +57,7 @@ export default Ember.Mixin.create({
const inSelection = this.get("selection")
.map(s => toLowerCaseOrUndefined(get(s, "value")))
.includes(term);

if (inCollection || inSelection) {
return false;
}
Expand All @@ -72,7 +67,7 @@ export default Ember.Mixin.create({

createContentFromInput(input) {
// See lib/discourse_tagging#clean_tag.
var content = input
let content = input
.trim()
.replace(/\s+/g, "-")
.replace(/[\/\?#\[\]@!\$&'\(\)\*\+,;=\.%\\`^\s|\{\}"<>]+/g, "")
Expand Down

0 comments on commit 7326dde

Please sign in to comment.