Prevent user from selecting the same category twice for different notification levels in their preferences

This commit is contained in:
Benjamin Kampmann 2014-04-09 16:32:58 +02:00
parent 6daef624c3
commit 72a6566bfd
3 changed files with 9 additions and 4 deletions

View file

@ -11,7 +11,8 @@ Discourse.CategoryGroupComponent = Ember.Component.extend({
return Discourse.Category.list().filter(function(category){ return Discourse.Category.list().filter(function(category){
var regex = new RegExp(term, "i"); var regex = new RegExp(term, "i");
return category.get("name").match(regex) && return category.get("name").match(regex) &&
!_.contains(self.get('categories'), category); !_.contains(self.get('blacklist') || [], category) &&
!_.contains(self.get('categories'), category) ;
}); });
}, },
onChangeItems: function(items) { onChangeItems: function(items) {

View file

@ -15,6 +15,10 @@ Discourse.PreferencesController = Discourse.ObjectController.extend({
return Discourse.SiteSettings.allow_user_locale; return Discourse.SiteSettings.allow_user_locale;
}.property(), }.property(),
selectedCategories: function(){
return [].concat(this.get("watchedCategories"), this.get("trackedCategories"), this.get("mutedCategories"));
}.property("watchedCategories", "trackedCategories", "mutedCategories"),
// By default we haven't saved anything // By default we haven't saved anything
saved: false, saved: false,

View file

@ -187,17 +187,17 @@
<label class="control-label">{{i18n user.categories_settings}}</label> <label class="control-label">{{i18n user.categories_settings}}</label>
<div class="controls category-controls"> <div class="controls category-controls">
<label>{{i18n user.watched_categories}}</label> <label>{{i18n user.watched_categories}}</label>
{{category-group categories=watchedCategories}} {{category-group categories=watchedCategories blacklist=selectedCategories}}
</div> </div>
<div class="instructions">{{i18n user.watched_categories_instructions}}</div> <div class="instructions">{{i18n user.watched_categories_instructions}}</div>
<div class="controls category-controls"> <div class="controls category-controls">
<label>{{i18n user.tracked_categories}}</label> <label>{{i18n user.tracked_categories}}</label>
{{category-group categories=trackedCategories}} {{category-group categories=trackedCategories blacklist=selectedCategories}}
</div> </div>
<div class="instructions">{{i18n user.tracked_categories_instructions}}</div> <div class="instructions">{{i18n user.tracked_categories_instructions}}</div>
<div class="controls category-controls"> <div class="controls category-controls">
<label>{{i18n user.muted_categories}}</label> <label>{{i18n user.muted_categories}}</label>
{{category-group categories=mutedCategories}} {{category-group categories=mutedCategories blacklist=selectedCategories}}
</div> </div>
<div class="instructions">{{i18n user.muted_categories_instructions}}</div> <div class="instructions">{{i18n user.muted_categories_instructions}}</div>
</div> </div>