diff --git a/app/assets/javascripts/discourse/models/category.js b/app/assets/javascripts/discourse/models/category.js index 37e5b95e44b..0b40ed3e0ab 100644 --- a/app/assets/javascripts/discourse/models/category.js +++ b/app/assets/javascripts/discourse/models/category.js @@ -188,6 +188,8 @@ Discourse.Category = Discourse.Model.extend({ }.property('id') }); +var _uncategorized; + Discourse.Category.reopenClass({ NotificationLevel: { @@ -197,6 +199,11 @@ Discourse.Category.reopenClass({ MUTED: 0 }, + findUncategorized: function() { + _uncategorized = _uncategorized || Discourse.Category.list().findBy('id', Discourse.Site.currentProp('uncategorized_category_id')); + return _uncategorized; + }, + slugFor: function(category) { if (!category) return ""; diff --git a/app/assets/javascripts/discourse/views/category-chooser.js.es6 b/app/assets/javascripts/discourse/views/category-chooser.js.es6 index bd5258d6e42..84bb3424d32 100644 --- a/app/assets/javascripts/discourse/views/category-chooser.js.es6 +++ b/app/assets/javascripts/discourse/views/category-chooser.js.es6 @@ -34,7 +34,7 @@ export default ComboboxView.extend({ if (this.get('rootNone')) { return "category.none"; } else { - return Discourse.Category.list().findBy('id', Discourse.Site.currentProp('uncategorized_category_id')); + return Discourse.Category.findUncategorized(); } } else { return 'category.choose'; @@ -42,9 +42,20 @@ export default ComboboxView.extend({ }.property(), template: function(item) { - var category = Discourse.Category.findById(parseInt(item.id,10)); - if (!category) return item.text; + var category; + + // If we have no id, but text with the uncategorized name, we can use that badge. + if (Em.empty(item.id)) { + var uncat = Discourse.Category.findUncategorized(); + if (uncat && uncat.get('name') === item.text) { + category = uncat; + } + } else { + category = Discourse.Category.findById(parseInt(item.id,10)); + } + + if (!category) return item.text; var result = badgeHtml(category, {showParent: false, link: false, allowUncategorized: true}), parentCategoryId = category.get('parent_category_id'); if (parentCategoryId) { @@ -56,7 +67,6 @@ export default ComboboxView.extend({ var description = category.get('description'); // TODO wtf how can this be null?; if (description && description !== 'null') { - result += '
' + description.substr(0,200) + (description.length > 200 ? '…' : '') +