FIX: Category badges were missing stripes in some places

This commit is contained in:
Robin Ward 2014-12-18 11:03:17 -05:00
parent a8acbc37a2
commit 8b51176f2e
13 changed files with 37 additions and 50 deletions

View File

@ -1,22 +1,8 @@
// Compile and memoize a template
var compiled;
function templateFunction() {
compiled = compiled || Handlebars.compile("<div class='autocomplete'>" +
"<ul>" +
"{{#each options}}" +
"<li>" +
"{{category-link-raw this allowUncategorized=true}}" +
"</li>" +
"{{/each}}" +
"</ul>" +
"</div>");
return compiled;
}
export default Ember.Component.extend({ export default Ember.Component.extend({
didInsertElement: function(){ _initializeAutocomplete: function(){
var self = this; var self = this;
var template = this.container.lookup('template:category-group-autocomplete.raw');
this.$('input').autocomplete({ this.$('input').autocomplete({
items: this.get('categories'), items: this.get('categories'),
@ -37,10 +23,11 @@ export default Ember.Component.extend({
}); });
self.set("categories", categories); self.set("categories", categories);
}, },
template: templateFunction(), template: template,
transformComplete: function(category) { transformComplete: function(category) {
return Discourse.HTML.categoryBadge(category, {allowUncategorized: true}); return Discourse.HTML.categoryBadge(category, {allowUncategorized: true});
} }
}); });
} }.on('didInsertElement')
}); });

View File

@ -1,3 +0,0 @@
import { categoryLinkHTML } from 'discourse/lib/html-builder';
Ember.Handlebars.helper('bound-category-link', categoryLinkHTML);

View File

@ -1,4 +1,4 @@
import { categoryLinkHTML } from 'discourse/lib/html-builder'; import { categoryLinkHTML } from 'discourse/helpers/category-badge';
import registerUnbound from 'discourse/helpers/register-unbound'; import registerUnbound from 'discourse/helpers/register-unbound';
registerUnbound('category-badge', function(cat, options) { registerUnbound('category-badge', function(cat, options) {

View File

@ -1,5 +0,0 @@
import { categoryLinkHTML } from 'discourse/lib/html-builder';
Handlebars.registerHelper('category-link-raw', function(property, options) {
return categoryLinkHTML(property, options);
});

View File

@ -1,4 +1,21 @@
import { categoryLinkHTML } from 'discourse/lib/html-builder';
import registerUnbound from 'discourse/helpers/register-unbound'; import registerUnbound from 'discourse/helpers/register-unbound';
export function categoryLinkHTML(category, options) {
var categoryOptions = {};
// TODO: This is a compatibility layer with the old helper structure.
// Can be removed once we migrate to `registerUnbound` fully
if (options && options.hash) { options = options.hash; }
if (options) {
if (options.allowUncategorized) { categoryOptions.allowUncategorized = true; }
if (options.showParent) { categoryOptions.showParent = true; }
if (options.onlyStripe) { categoryOptions.onlyStripe = true; }
if (options.link !== undefined) { categoryOptions.link = options.link; }
if (options.extraClasses) { categoryOptions.extraClasses = options.extraClasses; }
}
return new Handlebars.SafeString(Discourse.HTML.categoryBadge(category, categoryOptions));
}
registerUnbound('category-link', categoryLinkHTML); registerUnbound('category-link', categoryLinkHTML);
Ember.Handlebars.helper('bound-category-link', categoryLinkHTML);

View File

@ -1,16 +0,0 @@
export function categoryLinkHTML(category, options) {
var categoryOptions = {};
// TODO: This is a compatibility layer with the old helper structure.
// Can be removed once we migrate to `registerUnbound` fully
if (options && options.hash) { options = options.hash; }
if (options) {
if (options.allowUncategorized) { categoryOptions.allowUncategorized = true; }
if (options.showParent) { categoryOptions.showParent = true; }
if (options.onlyStripe) { categoryOptions.onlyStripe = true; }
if (options.link !== undefined) { categoryOptions.link = options.link; }
if (options.extraClasses) { categoryOptions.extraClasses = options.extraClasses; }
}
return new Handlebars.SafeString(Discourse.HTML.categoryBadge(category, categoryOptions));
}

View File

@ -0,0 +1,7 @@
<div class='autocomplete'>
<ul>
{{#each options}}
<li>{{category-link this allowUncategorized="true"}}</li>
{{/each}}
</ul>
</div>

View File

@ -32,7 +32,7 @@
{{#if c.subcategories}} {{#if c.subcategories}}
<div class='subcategories'> <div class='subcategories'>
{{#each s in c.subcategories}} {{#each s in c.subcategories}}
{{category-link s showParent=true onlyStripe=true}} {{category-link s showParent="true" onlyStripe="true"}}
{{#if s.unreadTopics}} {{#if s.unreadTopics}}
<a href={{unbound s.unreadUrl}} class='badge new-posts badge-notification' title='{{i18n 'topic.unread_topics' count=s.unreadTopics}}'>{{unbound s.unreadTopics}}</a> <a href={{unbound s.unreadUrl}} class='badge new-posts badge-notification' title='{{i18n 'topic.unread_topics' count=s.unreadTopics}}'>{{unbound s.unreadTopics}}</a>
{{/if}} {{/if}}

View File

@ -1,3 +1,3 @@
{{#unless hideCategory}} {{#unless hideCategory}}
<td class='category'>{{category-link category showParent=true}}</td> <td class='category'>{{category-link category showParent="true"}}</td>
{{/unless}} {{/unless}}

View File

@ -32,7 +32,7 @@
</div> </div>
{{#unless controller.hideCategory}} {{#unless controller.hideCategory}}
<div class='category'> <div class='category'>
{{category-link t.category showParent=true}} {{category-link t.category showParent="true"}}
</div> </div>
{{/unless}} {{/unless}}
{{#if controller.showParticipants}} {{#if controller.showParticipants}}

View File

@ -46,7 +46,7 @@
<td> <td>
<div class='subcategories'> <div class='subcategories'>
{{#each subcategory in c.subcategories}} {{#each subcategory in c.subcategories}}
{{category-link subcategory showParent=true}} {{category-link subcategory showParent="true"}}
{{/each}} {{/each}}
</div> </div>
</td> </td>

View File

@ -23,7 +23,7 @@
<div class="topic-item-stats clearfix"> <div class="topic-item-stats clearfix">
{{#unless controller.hideCategory}} {{#unless controller.hideCategory}}
<div class='category'> <div class='category'>
{{category-link category showParent=true}} {{category-link category showParent="true"}}
</div> </div>
{{/unless}} {{/unless}}

View File

@ -43,7 +43,7 @@
{{#each c in categories itemController='site-map-category'}} {{#each c in categories itemController='site-map-category'}}
<li class="category"> <li class="category">
{{category-link c allowUncategorized=true showParent=true}} {{category-link c allowUncategorized="true" showParent="true"}}
{{#if c.unreadTotal}} {{#if c.unreadTotal}}
<a href={{unbound c.url}} class='badge badge-notification'>{{c.unreadTotal}}</a> <a href={{unbound c.url}} class='badge badge-notification'>{{c.unreadTotal}}</a>