diff --git a/app/assets/javascripts/discourse/models/category.js b/app/assets/javascripts/discourse/models/category.js index ffa3c56af06..c7922b13e78 100644 --- a/app/assets/javascripts/discourse/models/category.js +++ b/app/assets/javascripts/discourse/models/category.js @@ -157,12 +157,11 @@ Discourse.Category = Discourse.Model.extend({ return this.countStats('topics'); }.property('posts_year', 'posts_month', 'posts_week', 'posts_day'), - notification_level: function () { + notification_level: function() { return this.get('notification_level'); }.property('notification_level'), - setNotification: function (notification_level) { - //console.log("inside category.js"); + setNotification: function(notification_level) { var url = "/category/" + this.get('id')+"/notifications"; this.set('notification_level', notification_level) return Discourse.ajax(url, { diff --git a/app/assets/javascripts/discourse/routes/discovery_route_builders.js b/app/assets/javascripts/discourse/routes/discovery_route_builders.js index 0d2aa32279a..df909771a2c 100644 --- a/app/assets/javascripts/discourse/routes/discovery_route_builders.js +++ b/app/assets/javascripts/discourse/routes/discovery_route_builders.js @@ -150,6 +150,12 @@ function buildCategoryRoute(filter, params) { deactivate: function() { this._super(); this.controllerFor('search').set('searchContext', null); + }, + + actions: { + setNotification: function(notification_level){ + this.currentModel.setNotification(notification_level); + } } }); } diff --git a/app/assets/javascripts/discourse/templates/category_notification_dropdown.js.handlebars b/app/assets/javascripts/discourse/templates/category_notification_dropdown.js.handlebars new file mode 100644 index 00000000000..7ff16d5fe4e --- /dev/null +++ b/app/assets/javascripts/discourse/templates/category_notification_dropdown.js.handlebars @@ -0,0 +1,17 @@ +
+ + + + +
\ No newline at end of file diff --git a/app/assets/javascripts/discourse/views/buttons/category_notification_dropdown_view.js b/app/assets/javascripts/discourse/views/buttons/category_notification_dropdown_view.js index f9cd8f96326..cb0b99babaa 100644 --- a/app/assets/javascripts/discourse/views/buttons/category_notification_dropdown_view.js +++ b/app/assets/javascripts/discourse/views/buttons/category_notification_dropdown_view.js @@ -1,50 +1,39 @@ -/** - This view handles rendering of a button with an associated drop down +// /** +// This view handles rendering of a button with an associated drop down - @class CategoryNotificationDropdownButtonView - @extends Discourse.View - @namespace Discourse - @module Discourse -**/ -Discourse.CategoryNotificationDropdownButtonView = Discourse.View.extend({ - classNameBindings: [':btn-group', 'hidden'], - shouldRerender: Discourse.View.renderIfChanged('text', 'text'), +// @class CategoryNotificationDropdownButtonView +// @extends Discourse.View +// @namespace Discourse +// @module Discourse +// **/ +// Discourse.CategoryNotificationDropdownButtonView = Discourse.View.extend({ +// //classNameBindings: [':btn-group', 'hidden'], +// //shouldRerender: Discourse.View.renderIfChanged('text', 'text'), +// //templateName: 'category_notification_dropdown', +// // didInsertElement: function() { +// // // If there's a click handler, call it +// // if (this.clicked) { +// // var dropDownButtonView = this; +// // this.$('ul li').on('click.dropdown-button', function(e) { +// // e.preventDefault(); +// // dropDownButtonView.clicked($(e.currentTarget).data('id')); +// // return false; +// // }); +// // } +// // }, - didInsertElement: function() { - // If there's a click handler, call it - if (this.clicked) { - var dropDownButtonView = this; - this.$('ul li').on('click.dropdown-button', function(e) { - e.preventDefault(); - dropDownButtonView.clicked($(e.currentTarget).data('id')); - return false; - }); - } - }, +// // willDestroyElement: function() { +// // this.$('ul li').off('click.dropdown-button'); +// // }, - willDestroyElement: function() { - this.$('ul li').off('click.dropdown-button'); - }, +// click: function(foo) { +// console.log(foo); +// }, - render: function(buffer) { - buffer.push(""); - - buffer.push(""); - - } -}); +// }); diff --git a/app/assets/javascripts/discourse/views/buttons/category_notifications_button.js b/app/assets/javascripts/discourse/views/buttons/category_notifications_button.js index cffdb3a2f62..cac4652c56d 100644 --- a/app/assets/javascripts/discourse/views/buttons/category_notifications_button.js +++ b/app/assets/javascripts/discourse/views/buttons/category_notifications_button.js @@ -6,13 +6,16 @@ @namespace Discourse @module Discourse **/ -Discourse.CategoryNotificationsButton = Discourse.CategoryNotificationDropdownButtonView.extend({ +Discourse.CategoryNotificationsButton = Discourse.View.extend({ classNames: ['notification-options'], - //title: I18n.t('category.notifications.title'), - //longDescriptionBinding: 'topic.details.notificationReasonText', - //topic: Em.computed.alias('controller.model'), category: Em.computed.alias('controller.model'), - hidden: Em.computed.alias('topic.deleted'), + hidden: Em.computed.alias('category.deleted'), + templateName: 'category_notification_dropdown', + + init: function() { + this._super(); + this.display(); + }, dropDownContent: function() { var contents = []; @@ -26,17 +29,20 @@ Discourse.CategoryNotificationsButton = Discourse.CategoryNotificationDropdownBu if (pair[1] === 'regular') { return; } - contents.push([ - Discourse.Category.NotificationLevel[pair[0]], - 'category.notifications.' + pair[1] - ]); + contents.push({ + id: Discourse.Category.NotificationLevel[pair[0]], + title: I18n.t('category.notifications.' + pair[1] + '.title'), + description: I18n.t('category.notifications.' + pair[1] + '.description') + } + + ); }); return contents; }.property(), // displayed Button - text: function() { + display: function() { var key = (function() { switch (this.get('category.notification_level')) { case Discourse.Category.NotificationLevel.WATCHING: return 'watching'; @@ -48,18 +54,17 @@ Discourse.CategoryNotificationsButton = Discourse.CategoryNotificationDropdownBu var icon = (function() { switch (key) { - case 'watching': return ' '; - case 'tracking': return ' '; - case 'muted': return ' '; + case 'watching': return 'heatmap-high'; + case 'tracking': return 'fa-circle heatmap-low'; + case 'muted': return 'fa-times-circle'; default: return ''; } })(); - return icon + (I18n.t("category.notifications." + key + ".title")) + ""; - }.property('category.notification_level'), - - clicked: function(id) { - return this.get('category').setNotification(id); - } + this.set("text", I18n.t("category.notifications." + key + ".title")); + this.set("icon", icon); + }, + changeDisplay: function() { + this.display(); + }.observes('category.notification_level') }); - diff --git a/app/assets/stylesheets/desktop/category-notification.scss b/app/assets/stylesheets/desktop/category-notification.scss index f3e7e857003..179f65a5467 100644 --- a/app/assets/stylesheets/desktop/category-notification.scss +++ b/app/assets/stylesheets/desktop/category-notification.scss @@ -15,15 +15,16 @@ box-shadow: 0 1px 5px rgba($primary_shadow_color, .4); background-clip: padding-box; span {font-size: 12px;} -.title {font-weight: bold; display: block; font-size: 14px;} -} -.notification-dropdown-menu a { - display: block; - padding: 3px 15px; - clear: both; - font-weight: normal; - line-height: 18px; - color: $primary_text_color; + .title {font-weight: bold; display: block; font-size: 14px;} + + a { + display: block; + padding: 3px 15px; + clear: both; + font-weight: normal; + line-height: 18px; + color: $primary_text_color; + } } .notification-dropdown-menu li > a:hover, .notification-dropdown-menu .active > a, diff --git a/app/models/site.rb b/app/models/site.rb index c48790c9799..a45dc5bba7d 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -45,10 +45,9 @@ class Site by_id = {} categories.each do |category| - # nur wenn user gesetzt ist - #unless guardian.anonymous? + unless @guardian.anonymous? category.notification_level = CategoryUser.lookup_by_category(@guardian.user, category).pluck(:notification_level)[0] - #end + end category.permission = CategoryGroup.permission_types[:full] if allowed_topic_create.include?(category.id) by_id[category.id] = category