This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/components/topic_status_component.js
2014-01-24 14:29:41 -05:00

36 lines
1.2 KiB
JavaScript

/**
This view is for rendering an icon representing the status of a topic
@class TopicStatusComponent
@extends Ember.Component
@namespace Discourse
@module Discourse
**/
Discourse.TopicStatusComponent = Ember.Component.extend({
classNames: ['topic-statuses'],
hasDisplayableStatus: Em.computed.or('topic.closed', 'topic.pinned', 'topic.invisible', 'topic.archetypeObject.notDefault'),
shouldRerender: Discourse.View.renderIfChanged('topic.closed', 'topic.pinned', 'topic.visible'),
render: function(buffer) {
if (!this.get('hasDisplayableStatus')) { return; }
var self = this,
renderIconIf = function(conditionProp, name, key) {
if (!self.get(conditionProp)) { return; }
var title = I18n.t("topic_statuses." + key + ".help");
buffer.push("<span title='" + title + "' class='topic-status'><i class='fa fa-" + name + "'></i></span>");
};
// Allow a plugin to add a custom icon to a topic
this.trigger('addCustomIcon', buffer);
renderIconIf('topic.closed', 'lock', 'locked');
renderIconIf('topic.pinned', 'thumb-tack', 'pinned');
renderIconIf('topic.invisible', 'eye-slash', 'invisible');
}
});
Discourse.View.registerHelper('topicStatus', Discourse.TopicStatusComponent);