FIX: category-group didn't work with subdirectories

This commit is contained in:
Robin Ward 2015-03-09 16:09:26 -04:00
parent 26a9c35293
commit 49978d02c2

View File

@ -2,31 +2,32 @@ import { categoryBadgeHTML } from 'discourse/helpers/category-link';
export default Ember.Component.extend({ export default Ember.Component.extend({
_initializeAutocomplete: function(){ _initializeAutocomplete: function() {
var self = this; const self = this,
var template = this.container.lookup('template:category-group-autocomplete.raw'); template = this.container.lookup('template:category-group-autocomplete.raw'),
regexp = new RegExp("href=['\"]" + Discourse.getURL('/c/') + "([^'\"]+)");
this.$('input').autocomplete({ this.$('input').autocomplete({
items: this.get('categories'), items: this.get('categories'),
single: false, single: false,
allowAny: false, allowAny: false,
dataSource: function(term){ dataSource(term){
return Discourse.Category.list().filter(function(category){ return Discourse.Category.list().filter(function(category){
var regex = new RegExp(term, "i"); const regex = new RegExp(term, "i");
return category.get("name").match(regex) && return category.get("name").match(regex) &&
!_.contains(self.get('blacklist') || [], category) && !_.contains(self.get('blacklist') || [], category) &&
!_.contains(self.get('categories'), category) ; !_.contains(self.get('categories'), category) ;
}); });
}, },
onChangeItems: function(items) { onChangeItems(items) {
var categories = _.map(items, function(link) { const categories = _.map(items, function(link) {
var slug = link.match(/href=['"]\/c\/([^'"]+)/)[1]; const slug = link.match(regexp)[1];
return Discourse.Category.findSingleBySlug(slug); return Discourse.Category.findSingleBySlug(slug);
}); });
self.set("categories", categories); self.set("categories", categories);
}, },
template: template, template,
transformComplete: function(category) { transformComplete(category) {
return categoryBadgeHTML(category, {allowUncategorized: true}); return categoryBadgeHTML(category, {allowUncategorized: true});
} }
}); });