From e0562894a8f22c548c682234210bc9ecb8c44b51 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 15 Sep 2015 10:52:42 +1000 Subject: [PATCH] FEATURE: if there is only one category, don't show the category picker --- .../javascripts/discourse/models/composer.js.es6 | 13 +++++++++++++ .../javascripts/discourse/templates/composer.hbs | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/models/composer.js.es6 b/app/assets/javascripts/discourse/models/composer.js.es6 index 576bec3973a..2b5241d29e5 100644 --- a/app/assets/javascripts/discourse/models/composer.js.es6 +++ b/app/assets/javascripts/discourse/models/composer.js.es6 @@ -67,6 +67,12 @@ const Composer = RestModel.extend({ creatingPrivateMessage: Em.computed.equal('action', PRIVATE_MESSAGE), notCreatingPrivateMessage: Em.computed.not('creatingPrivateMessage'), + showCategoryChooser: function(){ + const manyCategories = Discourse.Category.list().length > 1; + const hasOptions = this.get('archetype.hasOptions'); + return !this.get('privateMessage') && (hasOptions || manyCategories); + }.property('privateMessage'), + privateMessage: function(){ return this.get('creatingPrivateMessage') || this.get('topic.archetype') === 'private_message'; }.property('creatingPrivateMessage', 'topic'), @@ -434,6 +440,13 @@ const Composer = RestModel.extend({ // We set the category id separately for topic templates on opening of composer this.set('categoryId', opts.categoryId || this.get('topic.category.id')); + if (!this.get('categoryId') && this.get('creatingTopic')) { + const categories = Discourse.Category.list(); + if (categories.length === 1) { + this.set('categoryId', categories[0].get('id')); + } + } + if (opts.postId) { this.set('loading', true); this.store.find('post', opts.postId).then(function(post) { diff --git a/app/assets/javascripts/discourse/templates/composer.hbs b/app/assets/javascripts/discourse/templates/composer.hbs index 362df127919..01234ff0e9b 100644 --- a/app/assets/javascripts/discourse/templates/composer.hbs +++ b/app/assets/javascripts/discourse/templates/composer.hbs @@ -48,7 +48,7 @@ {{popup-input-tip validation=view.titleValidation shownAt=view.showTitleTip}} - {{#unless model.privateMessage}} + {{#if model.showCategoryChooser}}
{{category-chooser valueAttribute="id" value=model.categoryId scopedCategoryId=scopedCategoryId tabindex="3"}} {{popup-input-tip validation=view.categoryValidation shownAt=view.showCategoryTip}} @@ -57,7 +57,7 @@ {{/if}} {{render "additional-composer-buttons" model}} - {{/unless}} + {{/if}}
{{/if}}