FEATURE: If there is a category scope and `show_subcategory_list` is set, only

show the local categories in the dropdown instead of all categories.
This commit is contained in:
Robin Ward 2014-07-23 13:08:01 -04:00
parent b4ad70d767
commit 06512685ab
3 changed files with 26 additions and 9 deletions

View File

@ -15,6 +15,7 @@ export default Discourse.Controller.extend({
showEditReason: false,
editReason: null,
maxTitleLength: Discourse.computed.setting('max_topic_title_length'),
scopedCategoryId: null,
_initializeSimilar: function() {
this.set('similarTopics', []);
@ -254,13 +255,19 @@ export default Discourse.Controller.extend({
@param {String} [opts.quote] If we're opening a reply from a quote, the quote we're making
**/
open: function(opts) {
if (!opts) opts = {};
opts = opts || {};
if (!opts.draftKey) {
alert("composer was opened without a draft key");
throw "composer opened without a proper draft key";
}
// If we show the subcategory list, scope the categories drop down to
// the category we opened the composer with.
if (Discourse.SiteSettings.show_subcategory_list) {
this.set('scopedCategoryId', opts.categoryId);
}
var composerMessages = this.get('controllers.composer-messages'),
self = this,
composerModel = this.get('model');

View File

@ -44,7 +44,7 @@
{{#unless model.privateMessage}}
<div class="category-input">
{{category-chooser valueAttribute="id" value=model.categoryId}}
{{category-chooser valueAttribute="id" value=model.categoryId scopedCategoryId=scopedCategoryId}}
{{popupInputTip validation=view.categoryValidation shownAt=view.showCategoryTip}}
</div>
{{#if model.archetype.hasOptions}}

View File

@ -8,15 +8,25 @@ export default ComboboxView.extend({
dataAttributes: ['id', 'description_text'],
valueBinding: Ember.Binding.oneWay('source'),
content: Em.computed.filter('categories', function(c) {
var uncategorized_id = Discourse.Site.currentProp("uncategorized_category_id");
return c.get('permission') === Discourse.PermissionType.FULL && c.get('id') !== uncategorized_id;
}),
content: function() {
var scopedCategoryId = this.get('scopedCategoryId');
// Always scope to the parent of a category, if present
if (scopedCategoryId) {
var scopedCat = Discourse.Category.findById(scopedCategoryId);
scopedCategoryId = scopedCat.get('parent_category_id') || scopedCat.get('id');
}
return this.get('categories').filter(function(c) {
if (scopedCategoryId && (c.get('id') !== scopedCategoryId) && (c.get('parent_category_id') !== scopedCategoryId)) {
return false;
}
return c.get('permission') === Discourse.PermissionType.FULL && !c.get('isUncategorizedCategory');
});
}.property('scopedCategoryId', 'categories'),
_setCategories: function() {
if (!this.get('categories')) {
this.set('categories', Discourse.Category.list());
}
this.set('categories', this.get('categories') || Discourse.Category.list());
}.on('init'),
none: function() {