This commit is contained in:
Catrin 2014-05-03 10:45:09 +02:00 committed by Neil Lalonde
parent 772a304fc2
commit 66dccfe8d0
7 changed files with 96 additions and 80 deletions

View File

@ -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, {

View File

@ -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);
}
}
});
}

View File

@ -0,0 +1,17 @@
<div>
<button class='btn standard dropdown-toggle' data-toggle='dropdown'>
<i class="fa fa-circle {{view.icon}}"></i>&nbsp;{{view.text}}
<span class='caret'></span>
</button>
<ul class='notification-dropdown-menu'>
{{#each level in view.dropDownContent}}
<li data-id="{{level.id}}">
<a {{action setNotification level.id}} href="#">
<span class='title'>{{level.title}}</span><span>{{level.description}}</span>
</a>
</li>
{{/each}}
</ul>
</div>

View File

@ -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("<button class='btn standard dropdown-toggle' data-toggle='dropdown'>");
buffer.push(this.get('text'));
buffer.push("</button>");
buffer.push("<ul class='notification-dropdown-menu'>");
// actions: {
// setNotification: function(foo){
// console.log(foo);
// }
// }
_.each(this.get('dropDownContent'), function(row) {
var id = row[0],
textKey = row[1],
title = I18n.t(textKey + ".title"),
description = I18n.t(textKey + ".description");
buffer.push("<li data-id=\"" + id + "\"><a href='#'>");
buffer.push("<span class='title'>" + title + "</span>");
buffer.push("<span>" + description + "</span>");
buffer.push("</a></li>");
});
buffer.push("</ul>");
}
});
// });

View File

@ -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 '<i class="fa fa-circle heatmap-high"></i>&nbsp;';
case 'tracking': return '<i class="fa fa-circle heatmap-low"></i>&nbsp;';
case 'muted': return '<i class="fa fa-times-circle"></i>&nbsp;';
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")) + "<span class='caret'></span>";
}.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')
});

View File

@ -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,

View File

@ -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