FIX: Remove Bookmark was broken on bookmarks page

This was particularaly bad now that we removed stars :)
This commit is contained in:
Robin Ward 2015-01-13 13:14:58 -05:00
parent f49b11aa34
commit 0de6226a20
4 changed files with 28 additions and 25 deletions

View File

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

View File

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

View File

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

View File

@ -110,7 +110,7 @@ export default Discourse.View.extend(StringBuffer, {
}
}
if(post.get("bookmarked")){
if (post.get("bookmarked")) {
hiddenButtons.removeObject("bookmark");
}