mirror of
https://github.com/discourse/discourse.git
synced 2025-06-08 00:27:32 +08:00
FEATURE: ask confirmation when clearing more than 1 bookmark
This commit is contained in:
@ -179,63 +179,61 @@ const Topic = Discourse.Model.extend({
|
|||||||
}.property('word_count'),
|
}.property('word_count'),
|
||||||
|
|
||||||
toggleBookmark() {
|
toggleBookmark() {
|
||||||
|
if (this.get("bookmarking")) { return; }
|
||||||
|
this.set("bookmarking", true);
|
||||||
|
|
||||||
const self = this,
|
const self = this,
|
||||||
stream = this.get('postStream'),
|
stream = this.get('postStream'),
|
||||||
posts = Em.get(stream, 'posts'),
|
posts = Em.get(stream, 'posts'),
|
||||||
firstPost = posts &&
|
firstPost = posts && posts[0] && posts[0].get('post_number') === 1 && posts[0],
|
||||||
posts[0] &&
|
bookmark = !this.get('bookmarked'),
|
||||||
posts[0].get('post_number') === 1 &&
|
path = bookmark ? '/bookmark' : '/remove_bookmarks';
|
||||||
posts[0],
|
|
||||||
bookmark = !self.get('bookmarked');
|
|
||||||
|
|
||||||
var path = bookmark ? '/bookmark' : '/remove_bookmarks';
|
const toggleBookmarkOnServer = function() {
|
||||||
var unbookmarkedPosts = [],
|
return Discourse.ajax('/t/' + self.get('id') + path, {
|
||||||
bookmarkedPost;
|
|
||||||
|
|
||||||
this.toggleProperty('bookmarked');
|
|
||||||
|
|
||||||
if (bookmark && firstPost) {
|
|
||||||
firstPost.set('bookmarked', true);
|
|
||||||
bookmarkedPost = firstPost;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!bookmark && posts) {
|
|
||||||
posts.forEach(function(post){
|
|
||||||
if(post.get('bookmarked')){
|
|
||||||
post.set('bookmarked', false);
|
|
||||||
unbookmarkedPosts.push(post);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return Discourse.ajax('/t/' + this.get('id') + path, {
|
|
||||||
type: 'PUT',
|
type: 'PUT',
|
||||||
}).catch(function(error) {
|
}).then(function() {
|
||||||
|
|
||||||
self.toggleProperty('bookmarked');
|
self.toggleProperty('bookmarked');
|
||||||
|
if (bookmark && firstPost) { firstPost.set('bookmarked', true); }
|
||||||
if(bookmarkedPost) {
|
if (!bookmark && posts) {
|
||||||
bookmarkedPost.set('bookmarked', false);
|
posts.forEach((post) => post.get('bookmarked') && post.set('bookmarked', false));
|
||||||
}
|
}
|
||||||
|
}).catch(function(error) {
|
||||||
unbookmarkedPosts.forEach(function(p){
|
|
||||||
p.set('bookmarked', true);
|
|
||||||
});
|
|
||||||
|
|
||||||
let showGenericError = true;
|
let showGenericError = true;
|
||||||
if (error && error.responseText) {
|
if (error && error.responseText) {
|
||||||
try {
|
try {
|
||||||
bootbox.alert($.parseJSON(error.responseText).errors);
|
bootbox.alert($.parseJSON(error.responseText).errors);
|
||||||
showGenericError = false;
|
showGenericError = false;
|
||||||
} catch(e){}
|
} catch(e) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
if(showGenericError){
|
if (showGenericError) {
|
||||||
bootbox.alert(I18n.t('generic_error'));
|
bootbox.alert(I18n.t('generic_error'));
|
||||||
}
|
}
|
||||||
|
|
||||||
throw error;
|
throw error;
|
||||||
|
}).finally(function() {
|
||||||
|
self.set("bookmarking", false);
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
let unbookmarkedPosts = [];
|
||||||
|
if (!bookmark && posts) {
|
||||||
|
posts.forEach((post) => post.get('bookmarked') && unbookmarkedPosts.push(post));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unbookmarkedPosts.length > 1) {
|
||||||
|
return bootbox.confirm(
|
||||||
|
I18n.t("bookmarks.confirm_clear"),
|
||||||
|
I18n.t("no_value"),
|
||||||
|
I18n.t("yes_value"),
|
||||||
|
function (confirmed) {
|
||||||
|
if (confirmed) { return toggleBookmarkOnServer(); }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return toggleBookmarkOnServer();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
createInvite(emailOrUsername, groupNames) {
|
createInvite(emailOrUsername, groupNames) {
|
||||||
|
@ -179,6 +179,7 @@ en:
|
|||||||
not_bookmarked: "you've read this post; click to bookmark it"
|
not_bookmarked: "you've read this post; click to bookmark it"
|
||||||
last_read: "this is the last post you've read; click to bookmark it"
|
last_read: "this is the last post you've read; click to bookmark it"
|
||||||
remove: "Remove Bookmark"
|
remove: "Remove Bookmark"
|
||||||
|
confirm_clear: "Are you sure you want to clear all the bookmarks from this topic?"
|
||||||
|
|
||||||
topic_count_latest:
|
topic_count_latest:
|
||||||
one: "{{count}} new or updated topic."
|
one: "{{count}} new or updated topic."
|
||||||
|
Reference in New Issue
Block a user