diff --git a/app/assets/javascripts/discourse/controllers/topic.js.es6 b/app/assets/javascripts/discourse/controllers/topic.js.es6 index 0bb6ed3e01f..d2cdbff9415 100644 --- a/app/assets/javascripts/discourse/controllers/topic.js.es6 +++ b/app/assets/javascripts/discourse/controllers/topic.js.es6 @@ -214,7 +214,13 @@ export default ObjectController.extend(Discourse.SelectedPostsCount, BufferedCon return; } if (post) { - return post.toggleBookmark(); + return post.toggleBookmark().catch(function(error) { + if (error && error.responseText) { + bootbox.alert($.parseJSON(error.responseText).errors[0]); + } else { + bootbox.alert(I18n.t('generic_error')); + } + }); } else { return this.get("model").toggleBookmark(); } diff --git a/app/assets/javascripts/discourse/models/_post.js b/app/assets/javascripts/discourse/models/_post.js index 9df35ab8d0e..59077aefcda 100644 --- a/app/assets/javascripts/discourse/models/_post.js +++ b/app/assets/javascripts/discourse/models/_post.js @@ -418,19 +418,9 @@ Discourse.Post = Discourse.Model.extend({ 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) { - + return Discourse.Post.updateBookmark(this.get('id'), this.get('bookmarked')).catch(function() { 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')); - } }); } }); @@ -461,6 +451,13 @@ Discourse.Post.reopenClass({ return result; }, + updateBookmark: function(postId, bookmarked) { + return Discourse.ajax("/posts/" + postId + "/bookmark", { + type: 'PUT', + data: { bookmarked: bookmarked } + }); + }, + deleteMany: function(selectedPosts, selectedReplies) { return Discourse.ajax("/posts/destroy_many", { type: 'DELETE', diff --git a/app/assets/javascripts/discourse/routes/user-activity-stream.js.es6 b/app/assets/javascripts/discourse/routes/user-activity-stream.js.es6 index 712be34bda7..7257f7358f3 100644 --- a/app/assets/javascripts/discourse/routes/user-activity-stream.js.es6 +++ b/app/assets/javascripts/discourse/routes/user-activity-stream.js.es6 @@ -26,18 +26,18 @@ export default Discourse.Route.extend(ShowFooter, { }, removeBookmark: function(userAction) { - var self = this; - Discourse.Post.bookmark(userAction.get('post_id'), false) - .then(function() { - // remove the user action from the stream - self.modelFor("user").get("stream").remove(userAction); - // update the counts - self.modelFor("user").get("stats").forEach(function (stat) { - if (stat.get("action_type") === userAction.action_type) { - stat.decrementProperty("count"); - } - }); - }); + var user = this.modelFor('user'); + Discourse.Post.updateBookmark(userAction.get('post_id'), false) + .then(function() { + // remove the user action from the stream + user.get('stream').remove(userAction); + // update the counts + user.get('stats').forEach(function (stat) { + if (stat.get("action_type") === userAction.action_type) { + stat.decrementProperty("count"); + } + }); + }); }, } diff --git a/app/assets/javascripts/discourse/views/post-menu.js.es6 b/app/assets/javascripts/discourse/views/post-menu.js.es6 index c1d86e79a4a..4c6b2bd0ef7 100644 --- a/app/assets/javascripts/discourse/views/post-menu.js.es6 +++ b/app/assets/javascripts/discourse/views/post-menu.js.es6 @@ -110,7 +110,7 @@ export default Discourse.View.extend(StringBuffer, { } } - if(post.get("bookmarked")){ + if (post.get("bookmarked")) { hiddenButtons.removeObject("bookmark"); }