This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/controllers/user-activity-bookmarks-with-reminders.js
Martin Brennan 344ef5226c
FEATURE: Edit bookmark reminders from post and explicit delete button (#9455)
There is now an explicit "Delete Bookmark" button in the edit modal. A confirmation is shown before deleting.

Along with this, when the bookmarked post icon is clicked the modal is now shown instead of just deleting the bookmark. Also, the "Delete Bookmark" button from the user bookmark list now confirms the action.

Add a `d d` shortcut in the modal to delete the bookmark.
2020-04-20 13:30:04 +10:00

107 lines
2.6 KiB
JavaScript

import Controller from "@ember/controller";
import showModal from "discourse/lib/show-modal";
import { Promise } from "rsvp";
import { inject } from "@ember/controller";
import discourseComputed from "discourse-common/utils/decorators";
import Bookmark from "discourse/models/bookmark";
export default Controller.extend({
application: inject(),
user: inject(),
content: null,
loading: false,
noResultsHelp: null,
loadItems() {
this.setProperties({
content: [],
loading: true,
noResultsHelp: null
});
return this.model
.loadItems()
.then(response => {
this.processLoadResponse(response);
})
.catch(() => {
this.set("noResultsHelp", I18n.t("bookmarks.list_permission_denied"));
})
.finally(() =>
this.setProperties({
loaded: true,
loading: false
})
);
},
@discourseComputed("loaded", "content.length", "noResultsHelp")
noContent(loaded, contentLength, noResultsHelp) {
return loaded && contentLength === 0 && noResultsHelp !== null;
},
processLoadResponse(response) {
response = response.user_bookmark_list;
if (response && response.no_results_help) {
this.set("noResultsHelp", response.no_results_help);
}
this.model.more_bookmarks_url = response.more_bookmarks_url;
if (response && response.bookmarks) {
let bookmarks = [];
response.bookmarks.forEach(bookmark => {
bookmarks.push(Bookmark.create(bookmark));
});
this.content.pushObjects(bookmarks);
}
},
actions: {
removeBookmark(bookmark) {
bootbox.confirm(I18n.t("bookmarks.confirm_delete"), result => {
if (result) {
return bookmark.destroy().then(() => this.loadItems());
}
});
},
editBookmark(bookmark) {
let controller = showModal("bookmark", {
model: {
postId: bookmark.post_id,
id: bookmark.id,
reminderAt: bookmark.reminder_at,
name: bookmark.name
},
title: "post.bookmarks.edit",
modalClass: "bookmark-with-reminder"
});
controller.setProperties({
afterSave: () => this.loadItems()
});
},
loadMore() {
if (this.loadingMore) {
return Promise.resolve();
}
this.set("loadingMore", true);
return this.model
.loadMore()
.then(response => this.processLoadResponse(response))
.catch(() => {
this.set("noResultsHelp", I18n.t("bookmarks.list_permission_denied"));
})
.finally(() =>
this.setProperties({
loadingMore: false
})
);
}
}
});