FIX: Text not updated when changing notifications after reading a topic

This commit is contained in:
Régis Hanol 2013-04-10 15:41:06 +02:00
parent 33e3ad1603
commit ebbd5af8bc
3 changed files with 38 additions and 52 deletions

View File

@ -288,14 +288,13 @@ Discourse.Topic = Discourse.Model.extend({
}).then(afterTopicLoaded, errorLoadingTopic); }).then(afterTopicLoaded, errorLoadingTopic);
}, },
notificationReasonText: (function() { notificationReasonText: function() {
var locale_string; var locale_string = "topic.notifications.reasons." + this.get('notification_level');
locale_string = "topic.notifications.reasons." + this.notification_level; if (typeof this.get('notifications_reason_id') === 'number') {
if (typeof this.notifications_reason_id === 'number') { locale_string += "_" + this.get('notifications_reason_id');
locale_string += "_" + this.notifications_reason_id;
} }
return Em.String.i18n(locale_string, { username: Discourse.currentUser.username.toLowerCase() }); return Em.String.i18n(locale_string, { username: Discourse.currentUser.username.toLowerCase() });
}).property('notifications_reason_id'), }.property('notification_level', 'notifications_reason_id'),
updateNotifications: function(v) { updateNotifications: function(v) {
this.set('notification_level', v); this.set('notification_level', v);

View File

@ -23,35 +23,32 @@ Discourse.DropdownButtonView = Discourse.View.extend({
return null; return null;
}, },
textChanged: (function() { textChanged: function() {
return this.rerender(); this.rerender();
}).observes('text', 'longDescription'), }.observes('text', 'longDescription'),
render: function(buffer) { render: function(buffer) {
var desc; var desc;
buffer.push("<h4 class='title'>" + (this.get('title')) + "</h4>"); buffer.push("<h4 class='title'>" + this.get('title') + "</h4>");
buffer.push("<button class='btn standard dropdown-toggle' data-toggle='dropdown'>"); buffer.push("<button class='btn standard dropdown-toggle' data-toggle='dropdown'>");
buffer.push(this.get('text')); buffer.push(this.get('text'));
buffer.push("</button>"); buffer.push("</button>");
buffer.push("<ul class='dropdown-menu'>"); buffer.push("<ul class='dropdown-menu'>");
this.get('dropDownContent').each(function(row) { this.get('dropDownContent').each(function(row) {
var description, id, textKey, title; var id = row[0],
id = row[0]; textKey = row[1],
textKey = row[1]; title = Em.String.i18n("" + textKey + ".title"),
title = Em.String.i18n("" + textKey + ".title");
description = Em.String.i18n("" + textKey + ".description"); description = Em.String.i18n("" + textKey + ".description");
buffer.push("<li data-id=\"" + id + "\"><a href='#'>"); buffer.push("<li data-id=\"" + id + "\"><a href='#'>");
buffer.push("<span class='title'>" + title + "</span>"); buffer.push("<span class='title'>" + title + "</span>");
buffer.push("<span>" + description + "</span>"); buffer.push("<span>" + description + "</span>");
return buffer.push("</a></li>"); buffer.push("</a></li>");
}); });
buffer.push("</ul>"); buffer.push("</ul>");
if (desc = this.get('longDescription')) { if (desc = this.get('longDescription')) {
buffer.push("<p>"); buffer.push("<p>");
buffer.push(desc); buffer.push(desc);
return buffer.push("</p>"); buffer.push("</p>");
} }
} }
}); });

View File

@ -100,14 +100,14 @@ Discourse.TopicFooterButtonsView = Ember.ContainerView.extend({
helpKey: 'topic.reply.help', helpKey: 'topic.reply.help',
disabled: !this.get('controller.content.can_create_post'), disabled: !this.get('controller.content.can_create_post'),
text: (function() { text: function() {
var archetype, customTitle; var archetype, customTitle;
archetype = this.get('controller.content.archetype'); archetype = this.get('controller.content.archetype');
if (customTitle = this.get("parentView.replyButtonText" + (archetype.capitalize()))) { if (customTitle = this.get("parentView.replyButtonText" + (archetype.capitalize()))) {
return customTitle; return customTitle;
} }
return Em.String.i18n("topic.reply.title"); return Em.String.i18n("topic.reply.title");
}).property(), }.property(),
renderIcon: function(buffer) { renderIcon: function(buffer) {
buffer.push("<i class='icon icon-plus'></i>"); buffer.push("<i class='icon icon-plus'></i>");
@ -123,37 +123,6 @@ Discourse.TopicFooterButtonsView = Ember.ContainerView.extend({
topic: topic, topic: topic,
title: Em.String.i18n('topic.notifications.title'), title: Em.String.i18n('topic.notifications.title'),
longDescriptionBinding: 'topic.notificationReasonText', longDescriptionBinding: 'topic.notificationReasonText',
text: (function() {
var icon, key;
key = (function() {
switch (this.get('topic.notification_level')) {
case Discourse.Topic.NotificationLevel.WATCHING:
return 'watching';
case Discourse.Topic.NotificationLevel.TRACKING:
return 'tracking';
case Discourse.Topic.NotificationLevel.REGULAR:
return 'regular';
case Discourse.Topic.NotificationLevel.MUTE:
return 'muted';
}
}).call(this);
icon = (function() {
switch (key) {
case 'watching':
return '<i class="icon-circle heatmap-high"></i>&nbsp;';
case 'tracking':
return '<i class="icon-circle heatmap-low"></i>&nbsp;';
case 'regular':
return '';
case 'muted':
return '<i class="icon-remove-sign"></i>&nbsp;';
}
})();
return icon + (Ember.String.i18n("topic.notifications." + key + ".title")) + "<span class='caret'></span>";
}).property('topic.notification_level'),
dropDownContent: [ dropDownContent: [
[Discourse.Topic.NotificationLevel.WATCHING, 'topic.notifications.watching'], [Discourse.Topic.NotificationLevel.WATCHING, 'topic.notifications.watching'],
[Discourse.Topic.NotificationLevel.TRACKING, 'topic.notifications.tracking'], [Discourse.Topic.NotificationLevel.TRACKING, 'topic.notifications.tracking'],
@ -161,6 +130,27 @@ Discourse.TopicFooterButtonsView = Ember.ContainerView.extend({
[Discourse.Topic.NotificationLevel.MUTE, 'topic.notifications.muted'] [Discourse.Topic.NotificationLevel.MUTE, 'topic.notifications.muted']
], ],
text: function() {
var key = (function() {
switch (this.get('topic.notification_level')) {
case Discourse.Topic.NotificationLevel.WATCHING: return 'watching';
case Discourse.Topic.NotificationLevel.TRACKING: return 'tracking';
case Discourse.Topic.NotificationLevel.REGULAR: return 'regular';
case Discourse.Topic.NotificationLevel.MUTE: return 'muted';
}
}).call(this);
var icon = (function() {
switch (key) {
case 'watching': return '<i class="icon-circle heatmap-high"></i>&nbsp;';
case 'tracking': return '<i class="icon-circle heatmap-low"></i>&nbsp;';
case 'regular': return '';
case 'muted': return '<i class="icon-remove-sign"></i>&nbsp;';
}
})();
return icon + (Ember.String.i18n("topic.notifications." + key + ".title")) + "<span class='caret'></span>";
}.property('topic.notification_level'),
clicked: function(id) { clicked: function(id) {
return this.get('topic').updateNotifications(id); return this.get('topic').updateNotifications(id);
} }