diff --git a/app/assets/javascripts/discourse/components/header-extra-info.js.es6 b/app/assets/javascripts/discourse/components/header-extra-info.js.es6 new file mode 100644 index 00000000000..a323d50df56 --- /dev/null +++ b/app/assets/javascripts/discourse/components/header-extra-info.js.es6 @@ -0,0 +1,47 @@ +const TopicCategoryComponent = Ember.Component.extend({ + needsSecondRow: Ember.computed.gt('secondRowItems.length', 0), + secondRowItems: function() { return []; }.property(), + + showPrivateMessageGlyph: function() { + return !this.get('topic.is_warning') && this.get('topic.isPrivateMessage'); + }.property('topic.is_warning', 'topic.isPrivateMessage'), + + actions: { + jumpToTopPost: function () { + var topic = this.get('topic'); + if (topic) { + Discourse.URL.routeTo(topic.get('firstPostUrl')); + } + } + } + +}); + +let id = 0; + +// Allow us (and plugins) to register themselves as needing a second +// row in the header. If there is at least one thing in the second row +// the style changes to accomodate it. +function needsSecondRowIf(prop, cb) { + const rowId = "_second_row_" + (id++), + methodHash = {}; + + methodHash[id] = function() { + const secondRowItems = this.get('secondRowItems'), + propVal = this.get(prop); + if (cb.call(this, propVal)) { + secondRowItems.addObject(rowId); + } else { + secondRowItems.removeObject(rowId); + } + }.observes(prop).on('init'); + + TopicCategoryComponent.reopen(methodHash); +} + +needsSecondRowIf('topic.category', function(cat) { + return cat && (!cat.get('isUncategorizedCategory') || !this.siteSettings.suppress_uncategorized_badge); +}); + +export default TopicCategoryComponent; +export { needsSecondRowIf }; diff --git a/app/assets/javascripts/discourse/controllers/header.js.es6 b/app/assets/javascripts/discourse/controllers/header.js.es6 index 2511aa50088..b40ac3efdad 100644 --- a/app/assets/javascripts/discourse/controllers/header.js.es6 +++ b/app/assets/javascripts/discourse/controllers/header.js.es6 @@ -10,15 +10,6 @@ export default DiscourseController.extend({ loginRequired: Em.computed.alias('controllers.application.loginRequired'), canSignUp: Em.computed.alias('controllers.application.canSignUp'), - hasCategory: function() { - var cat = this.get('topic.category'); - return cat && (!cat.get('isUncategorizedCategory') || !this.siteSettings.suppress_uncategorized_badge); - }.property('topic.category'), - - showPrivateMessageGlyph: function() { - return !this.get('topic.is_warning') && this.get('topic.isPrivateMessage'); - }.property('topic.is_warning', 'topic.isPrivateMessage'), - showSignUpButton: function() { return this.get('canSignUp') && !this.get('showExtraInfo'); }.property('canSignUp', 'showExtraInfo'), @@ -78,13 +69,6 @@ export default DiscourseController.extend({ self.refreshNotifications(); } headerView.showDropdownBySelector("#user-notifications"); - }, - - jumpToTopPost: function () { - var topic = this.get('topic'); - if (topic) { - Discourse.URL.routeTo(topic.get('firstPostUrl')); - } } } diff --git a/app/assets/javascripts/discourse/templates/components/header-extra-info.hbs b/app/assets/javascripts/discourse/templates/components/header-extra-info.hbs new file mode 100644 index 00000000000..c6326286eea --- /dev/null +++ b/app/assets/javascripts/discourse/templates/components/header-extra-info.hbs @@ -0,0 +1,21 @@ +