From 72a6566bfd31edd97e9eda587bfee6ae2aa8ea84 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Wed, 9 Apr 2014 16:32:58 +0200 Subject: [PATCH] Prevent user from selecting the same category twice for different notification levels in their preferences --- .../discourse/components/category_group_component.js | 3 ++- .../discourse/controllers/preferences_controller.js | 4 ++++ .../discourse/templates/user/preferences.js.handlebars | 6 +++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse/components/category_group_component.js b/app/assets/javascripts/discourse/components/category_group_component.js index 40ea90878b0..9fae6cc23eb 100644 --- a/app/assets/javascripts/discourse/components/category_group_component.js +++ b/app/assets/javascripts/discourse/components/category_group_component.js @@ -11,7 +11,8 @@ Discourse.CategoryGroupComponent = Ember.Component.extend({ return Discourse.Category.list().filter(function(category){ var regex = new RegExp(term, "i"); return category.get("name").match(regex) && - !_.contains(self.get('categories'), category); + !_.contains(self.get('blacklist') || [], category) && + !_.contains(self.get('categories'), category) ; }); }, onChangeItems: function(items) { diff --git a/app/assets/javascripts/discourse/controllers/preferences_controller.js b/app/assets/javascripts/discourse/controllers/preferences_controller.js index fa800b0a18b..c5f6c143054 100644 --- a/app/assets/javascripts/discourse/controllers/preferences_controller.js +++ b/app/assets/javascripts/discourse/controllers/preferences_controller.js @@ -15,6 +15,10 @@ Discourse.PreferencesController = Discourse.ObjectController.extend({ return Discourse.SiteSettings.allow_user_locale; }.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 saved: false, diff --git a/app/assets/javascripts/discourse/templates/user/preferences.js.handlebars b/app/assets/javascripts/discourse/templates/user/preferences.js.handlebars index d87c2f7c9ce..be9d804b6cd 100644 --- a/app/assets/javascripts/discourse/templates/user/preferences.js.handlebars +++ b/app/assets/javascripts/discourse/templates/user/preferences.js.handlebars @@ -187,17 +187,17 @@
- {{category-group categories=watchedCategories}} + {{category-group categories=watchedCategories blacklist=selectedCategories}}
{{i18n user.watched_categories_instructions}}
- {{category-group categories=trackedCategories}} + {{category-group categories=trackedCategories blacklist=selectedCategories}}
{{i18n user.tracked_categories_instructions}}
- {{category-group categories=mutedCategories}} + {{category-group categories=mutedCategories blacklist=selectedCategories}}
{{i18n user.muted_categories_instructions}}