Add `bookmarked` class to bookmarks button. Also remove duplicated code,

use fewer observers.
This commit is contained in:
Robin Ward 2014-03-10 12:03:17 -04:00
parent 2838e1c3b5
commit 9f67d476ef
2 changed files with 22 additions and 30 deletions

View File

@ -64,32 +64,6 @@ Discourse.Post = Discourse.Model.extend({
hasHistory: Em.computed.gt('version', 1),
postElementId: Discourse.computed.fmt('post_number', 'post_%@'),
// The class for the read icon of the post. It starts with read-icon then adds 'seen' or
// 'last-read' if the post has been seen or is the highest post number seen so far respectively.
bookmarkClass: function() {
var result = 'read-icon';
if (this.get('bookmarked')) return result + ' bookmarked';
var topic = this.get('topic');
if (topic && topic.get('last_read_post_number') === this.get('post_number')) {
return result + ' last-read';
}
return result + (this.get('read') ? ' seen' : ' unseen');
}.property('read', 'topic.last_read_post_number', 'bookmarked'),
// Custom tooltips for the bookmark icons
bookmarkTooltip: function() {
if (this.get('bookmarked')) return I18n.t('bookmarks.created');
if (!this.get('read')) return "";
var topic = this.get('topic');
if (topic && topic.get('last_read_post_number') === this.get('post_number')) {
return I18n.t('bookmarks.last_read');
}
return I18n.t('bookmarks.not_bookmarked');
}.property('read', 'topic.last_read_post_number', 'bookmarked'),
bookmarkedChanged: function() {
Discourse.ajax("/posts/" + this.get('id') + "/bookmark", {
type: 'PUT',

View File

@ -16,8 +16,9 @@ Discourse.PostMenuView = Discourse.View.extend({
'post.reply_count',
'post.showRepliesBelow',
'post.can_delete',
'post.bookmarkClass',
'post.bookmarkTooltip',
'post.read',
'post.topic.last_read_post_number',
'post.bookmarked',
'post.shareUrl',
'post.topic.deleted_at',
'post.replies.length'),
@ -188,8 +189,25 @@ Discourse.PostMenuView = Discourse.View.extend({
renderBookmark: function(post, buffer) {
if (!Discourse.User.current()) return;
buffer.push("<button title=\"" + this.get('post.bookmarkTooltip') +
"\" data-action=\"bookmark\" class='bookmark'><div class='" + this.get('post.bookmarkClass') +
var iconClass = 'read-icon',
buttonClass = 'bookmark',
topic = post.get('topic'),
tooltip;
if (post.get('bookmarked')) {
iconClass += ' bookmarked';
buttonClass += ' bookmarked';
tooltip = I18n.t('bookmarks.created');
} else if (topic && topic.get('last_read_post_number') === post.get('post_number')) {
iconClass += ' last-read';
tooltip = I18n.t('bookmarks.last_read');
} else {
iconClass += (post.get('read') ? ' seen' : ' unseen');
tooltip = I18n.t('bookmarks.not_bookmarked');
}
buffer.push("<button title=\"" + tooltip +
"\" data-action=\"" + buttonClass + "\" class='bookmark'><div class='" + iconClass +
"'></div></button>");
},