FEATURE: bookmark topic button

This commit is contained in:
Régis Hanol
2015-01-12 12:10:15 +01:00
parent a9ef92f3d8
commit c681b353f2
14 changed files with 103 additions and 48 deletions

View File

@@ -213,8 +213,11 @@ export default ObjectController.extend(Discourse.SelectedPostsCount, BufferedCon
alert(I18n.t("bookmarks.not_bookmarked"));
return;
}
post.toggleProperty('bookmarked');
return false;
if (post) {
return post.toggleBookmark();
} else {
return this.get("model").toggleBookmark();
}
},
jumpTop: function() {
@@ -547,15 +550,13 @@ export default ObjectController.extend(Discourse.SelectedPostsCount, BufferedCon
// Receive notifications for this topic
subscribe: function() {
// Unsubscribe before subscribing again
this.unsubscribe();
var bus = Discourse.MessageBus;
var topicController = this;
bus.subscribe("/topic/" + (this.get('id')), function(data) {
Discourse.MessageBus.subscribe("/topic/" + this.get('id'), function(data) {
var topic = topicController.get('model');
if (data.notification_level_change) {
topic.set('details.notification_level', data.notification_level_change);
topic.set('details.notifications_reason_id', data.notifications_reason_id);

View File

@@ -18,15 +18,13 @@ var PATH_BINDINGS = {
},
CLICK_BINDINGS = {
// star topic
'f': '#topic-footer-buttons button.star, .topic-list tr.topic-list-item.selected a.star',
'f': '#topic-footer-buttons button.bookmark', // bookmark topic
'm m': 'div.notification-options li[data-id="0"] a', // mark topic as muted
'm r': 'div.notification-options li[data-id="1"] a', // mark topic as regular
'm t': 'div.notification-options li[data-id="2"] a', // mark topic as tracking
'm w': 'div.notification-options li[data-id="3"] a', // mark topic as watching
'x r': '#dismiss-new,#dismiss-new-top,#dismiss-posts,#dismiss-posts-top', // dismiss new/posts
'x t': '#dismiss-topics,#dismiss-topics-top', //dismiss topics
'x t': '#dismiss-topics,#dismiss-topics-top', // dismiss topics
'.': '.alert.alert-info.clickable', // show incoming/updated topics
'n': '#user-notifications', // open notifications menu
'o,enter': '.topic-list tr.selected a.title', // open selected topic
@@ -36,7 +34,7 @@ var PATH_BINDINGS = {
},
FUNCTION_BINDINGS = {
'c': 'createTopic', // create new topic
'c': 'createTopic', // create new topic
'home': 'goToFirstPost',
'#': 'toggleProgress',
'end': 'goToLastPost',
@@ -47,11 +45,11 @@ var PATH_BINDINGS = {
'k': 'selectUp',
'u': 'goBack',
'/': 'showSearch',
'=': 'showSiteMap', // open site map menu
'p': 'showCurrentUser', // open current user menu
'=': 'showSiteMap', // open site map menu
'p': 'showCurrentUser', // open current user menu
'ctrl+f': 'showBuiltinSearch',
'command+f': 'showBuiltinSearch',
'?': 'showHelpModal', // open keyboard shortcut help
'?': 'showHelpModal', // open keyboard shortcut help
'q': 'quoteReply'
};

View File

@@ -68,17 +68,6 @@ Discourse.Post = Discourse.Model.extend({
return this.get("user_id") === Discourse.User.currentProp("id") || Discourse.User.currentProp('staff');
}.property("user_id"),
bookmarkedChanged: function() {
Discourse.Post.bookmark(this.get('id'), this.get('bookmarked'))
.then(null, function (error) {
if (error && error.responseText) {
bootbox.alert($.parseJSON(error.responseText).errors[0]);
} else {
bootbox.alert(I18n.t('generic_error'));
}
});
}.observes('bookmarked'),
wikiChanged: function() {
var data = { wiki: this.get("wiki") };
this._updatePost("wiki", data);
@@ -421,6 +410,28 @@ Discourse.Post = Discourse.Model.extend({
unhide: function () {
return Discourse.ajax("/posts/" + this.get("id") + "/unhide", { type: "PUT" });
},
toggleBookmark: function() {
var self = this;
this.toggleProperty("bookmarked");
if (this.get("post_number") === 1) { this.toggleProperty("topic.bookmarked"); }
return Discourse.ajax("/posts/" + this.get("id") + "/bookmark", {
type: 'PUT',
data: { bookmarked: this.get("bookmarked") }
}).then(null, function (error) {
self.toggleProperty("bookmarked");
if (this.get("post_number") === 1) { this.toggleProperty("topic.bookmarked"); }
if (error && error.responseText) {
bootbox.alert($.parseJSON(error.responseText).errors[0]);
} else {
bootbox.alert(I18n.t('generic_error'));
}
});
}
});
@@ -491,10 +502,6 @@ Discourse.Post.reopenClass({
return Discourse.ajax("/posts/" + postId + ".json").then(function (result) {
return Discourse.Post.create(result);
});
},
bookmark: function(postId, bookmarked) {
return Discourse.ajax("/posts/" + postId + "/bookmark", { type: 'PUT', data: { bookmarked: bookmarked } });
}
});

View File

@@ -181,14 +181,17 @@ Discourse.Topic = Discourse.Model.extend({
}.property('word_count'),
toggleBookmark: function() {
var topic = this;
topic.toggleProperty('bookmarked');
return Discourse.ajax({
url: "" + (this.get('url')) + "/bookmark",
var self = this, firstPost = this.get("postStream.posts")[0];
this.toggleProperty('bookmarked');
if (this.get("postStream.firstPostPresent")) { firstPost.toggleProperty("bookmarked"); }
return Discourse.ajax('/t/' + this.get('id') + '/bookmark', {
type: 'PUT',
data: { bookmarked: topic.get('bookmarked') ? true : false }
data: { bookmarked: self.get('bookmarked') }
}).then(null, function (error) {
topic.toggleProperty('bookmarked');
self.toggleProperty('bookmarked');
if (self.get("postStream.firstPostPresent")) { firstPost.toggleProperty('bookmarked'); }
if (error && error.responseText) {
bootbox.alert($.parseJSON(error.responseText).errors);

View File

@@ -36,7 +36,7 @@
<div class="span6">
<h4>{{i18n 'keyboard_shortcuts_help.actions.title'}}</h4>
<ul>
<li>{{{i18n 'keyboard_shortcuts_help.actions.star'}}}</li>
<li>{{{i18n 'keyboard_shortcuts_help.actions.bookmark_topic'}}}</li>
<li>{{{i18n 'keyboard_shortcuts_help.actions.pin_unpin_topic'}}}</li>
<li>{{{i18n 'keyboard_shortcuts_help.actions.share_topic'}}}</li>
<li>{{{i18n 'keyboard_shortcuts_help.actions.share_post'}}}</li>

View File

@@ -0,0 +1,19 @@
import ButtonView from 'discourse/views/button';
export default ButtonView.extend({
classNames: ['bookmark'],
textKey: 'bookmarked.title',
helpKeyBinding: 'controller.bookmarkTooltipKey',
attributeBindings: ['disabled'],
rerenderTriggers: ['controller.bookmarked'],
click: function() {
this.get('controller').send('toggleBookmark');
},
renderIcon: function(buffer) {
var className = this.get("controller.bookmarked") ? "fa-bookmark" : "fa-bookmark-o";
buffer.push("<i class='fa " + className + "'></i>");
}
});

View File

@@ -1,6 +1,7 @@
import TopicAdminMenuButton from 'discourse/views/topic-admin-menu-button';
import LoginReplyButton from 'discourse/views/login-reply-button';
import FlagTopicButton from 'discourse/views/flag-topic-button';
import BookmarkButton from 'discourse/views/bookmark-button';
import ShareButton from 'discourse/views/share-button';
import InviteReplyButton from 'discourse/views/invite-reply-button';
import ReplyButton from 'discourse/views/reply-button';
@@ -29,6 +30,7 @@ export default DiscourseContainerView.extend({
if (this.get('topic.details.can_invite_to')) {
this.attachViewClass(InviteReplyButton);
}
this.attachViewClass(BookmarkButton);
this.attachViewClass(ShareButton);
if (this.get('topic.details.can_flag_topic')) {
this.attachViewClass(FlagTopicButton);