correct the category chooser to properly convert any html in category descriptions to text

This commit is contained in:
Sam 2013-06-25 17:22:38 +10:00
parent 1ac7c28680
commit 1106eb9902
2 changed files with 20 additions and 5 deletions

View File

@ -63,7 +63,13 @@ Discourse.Category = Discourse.Model.extend({
removeGroup: function(group){
this.get("groups").removeObject(group);
this.get("availableGroups").addObject(group);
}
},
// note, this is used in a data attribute, data attributes get downcased
// to avoid confusion later on using this naming here.
description_text: function(){
return $("<div>" + this.get("description") + "</div>").text();
}.property("description")
});

View File

@ -9,7 +9,7 @@
Discourse.CategoryChooserView = Discourse.ComboboxView.extend({
classNames: ['combobox category-combobox'],
overrideWidths: true,
dataAttributes: ['name', 'color', 'text_color', 'description', 'topic_count'],
dataAttributes: ['name', 'color', 'text_color', 'description_text', 'topic_count'],
valueBinding: Ember.Binding.oneWay('source'),
init: function() {
@ -23,15 +23,24 @@ Discourse.CategoryChooserView = Discourse.ComboboxView.extend({
template: function(text, templateData) {
if (!templateData.color) return text;
var result = "<span class='badge-category' style='background-color: #" + templateData.color + '; color: #' +
templateData.text_color + ";'>" + templateData.name + "</span>";
result += " <span class='topic-count'>&times; " + templateData.topic_count + "</span>";
if (templateData.description && templateData.description !== 'null') {
result += '<div class="category-desc">' + templateData.description.substr(0,200) + (templateData.description.length > 200 ? '&hellip;' : '') + '</div>';
var description = templateData.description_text;
// TODO wtf how can this be null?
if (description && description !== 'null') {
result += '<div class="category-desc">' +
description.substr(0,200) +
(description.length > 200 ? '&hellip;' : '') +
'</div>';
}
return result;
}
});
Discourse.View.registerHelper('categoryChooser', Discourse.CategoryChooserView);
Discourse.View.registerHelper('categoryChooser', Discourse.CategoryChooserView);