ES6ify category chooser

This commit is contained in:
Robin Ward
2015-04-01 11:10:32 -04:00
parent eec1921ba9
commit 35da1ef620

View File

@ -9,11 +9,11 @@ export default ComboboxView.extend({
castInteger: true, castInteger: true,
content: function() { content: function() {
var scopedCategoryId = this.get('scopedCategoryId'); let scopedCategoryId = this.get('scopedCategoryId');
// Always scope to the parent of a category, if present // Always scope to the parent of a category, if present
if (scopedCategoryId) { if (scopedCategoryId) {
var scopedCat = Discourse.Category.findById(scopedCategoryId); const scopedCat = Discourse.Category.findById(scopedCategoryId);
scopedCategoryId = scopedCat.get('parent_category_id') || scopedCat.get('id'); scopedCategoryId = scopedCat.get('parent_category_id') || scopedCat.get('id');
} }
@ -41,13 +41,13 @@ export default ComboboxView.extend({
} }
}.property(), }.property(),
template: function(item) { template(item) {
var category; let category;
// If we have no id, but text with the uncategorized name, we can use that badge. // If we have no id, but text with the uncategorized name, we can use that badge.
if (Ember.isEmpty(item.id)) { if (Ember.isEmpty(item.id)) {
var uncat = Discourse.Category.findUncategorized(); const uncat = Discourse.Category.findUncategorized();
if (uncat && uncat.get('name') === item.text) { if (uncat && uncat.get('name') === item.text) {
category = uncat; category = uncat;
} }
@ -56,15 +56,16 @@ export default ComboboxView.extend({
} }
if (!category) return item.text; if (!category) return item.text;
var result = categoryBadgeHTML(category, {link: false, allowUncategorized: true, hideParent: true}), let result = categoryBadgeHTML(category, {link: false, allowUncategorized: true, hideParent: true});
parentCategoryId = category.get('parent_category_id'); const parentCategoryId = category.get('parent_category_id');
if (parentCategoryId) { if (parentCategoryId) {
result = categoryBadgeHTML(Discourse.Category.findById(parentCategoryId), {link: false}) + " " + result; result = categoryBadgeHTML(Discourse.Category.findById(parentCategoryId), {link: false}) + " " + result;
} }
result += " <span class='topic-count'>&times; " + category.get('topic_count') + "</span>"; result += " <span class='topic-count'>&times; " + category.get('topic_count') + "</span>";
var description = category.get('description'); const description = category.get('description');
// TODO wtf how can this be null?; // TODO wtf how can this be null?;
if (description && description !== 'null') { if (description && description !== 'null') {
result += '<div class="category-desc">' + result += '<div class="category-desc">' +