From ada633f084c567f1b43085acb86e0187a61d558c Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 27 Mar 2015 12:55:19 -0400 Subject: [PATCH] FIX: Clicking the lock icon was running the "pin" logic --- .../discourse/components/topic-status.js.es6 | 39 +++++++++++-------- .../discourse/templates/header.hbs | 6 +-- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/app/assets/javascripts/discourse/components/topic-status.js.es6 b/app/assets/javascripts/discourse/components/topic-status.js.es6 index eff062f2b2b..4f4eb934f97 100644 --- a/app/assets/javascripts/discourse/components/topic-status.js.es6 +++ b/app/assets/javascripts/discourse/components/topic-status.js.es6 @@ -1,3 +1,4 @@ +import { iconHTML } from 'discourse/helpers/fa-icon'; import StringBuffer from 'discourse/mixins/string-buffer'; export default Ember.Component.extend(StringBuffer, { @@ -5,14 +6,16 @@ export default Ember.Component.extend(StringBuffer, { rerenderTriggers: ['topic.archived', 'topic.closed', 'topic.pinned', 'topic.visible', 'topic.unpinned', 'topic.is_warning'], - click: function() { - var topic = this.get('topic'); + click(e) { + if ($(e.target).hasClass('fa-thumb-tack')) { + const topic = this.get('topic'); - // only pin unpin for now - if (topic.get('pinned')) { - topic.clearPin(); - } else { - topic.rePin(); + // only pin unpin for now + if (topic.get('pinned')) { + topic.clearPin(); + } else { + topic.rePin(); + } } return false; @@ -22,24 +25,26 @@ export default Ember.Component.extend(StringBuffer, { return Discourse.User.current() && !this.get('disableActions'); }.property('disableActions'), - renderString: function(buffer) { + renderString(buffer) { + const self = this; - var self = this; - - var renderIconIf = function(conditionProp, name, key, actionable) { + const renderIconIf = function(conditionProp, name, key, actionable) { if (!self.get(conditionProp)) { return; } - var title = Handlebars.Utils.escapeExpression(I18n.t("topic_statuses." + key + ".help")); - var startTag = actionable ? "a href" : "span"; - var endTag = actionable ? "a" : "span"; - buffer.push("<" + startTag + " title='" + title + "' class='topic-status'>"); + const title = Handlebars.Utils.escapeExpression(I18n.t("topic_statuses." + key + ".help")), + startTag = actionable ? "a href" : "span", + endTag = actionable ? "a" : "span", + iconArgs = key === 'unpinned' ? { 'class': 'unpinned' } : null, + icon = iconHTML(name, iconArgs); + + buffer.push("<" + startTag + " title='" + title + "' class='topic-status'>" + icon + ""); }; renderIconIf('topic.is_warning', 'envelope', 'warning'); renderIconIf('topic.closed', 'lock', 'locked'); renderIconIf('topic.archived', 'lock', 'archived'); - renderIconIf('topic.pinned', 'thumb-tack', 'pinned', self.get("canAct") ); - renderIconIf('topic.unpinned', 'thumb-tack unpinned', 'unpinned', self.get("canAct")); + renderIconIf('topic.pinned', 'thumb-tack', 'pinned', this.get("canAct") ); + renderIconIf('topic.unpinned', 'thumb-tack', 'unpinned', this.get("canAct")); renderIconIf('topic.invisible', 'eye-slash', 'invisible'); } }); diff --git a/app/assets/javascripts/discourse/templates/header.hbs b/app/assets/javascripts/discourse/templates/header.hbs index 02748e28da7..f701c967489 100644 --- a/app/assets/javascripts/discourse/templates/header.hbs +++ b/app/assets/javascripts/discourse/templates/header.hbs @@ -13,14 +13,14 @@