discourse/app/assets/javascripts/select-kit/addon/components/bulk-select-bookmarks-dropdown.js
Amanda Alves Branquinho b0d95c8c78
FEATURE: Add bulk action to bookmark (#26856)
This PR aims to add bulk actions to the user's bookmarks.

After this feature, all users should be able to select multiple bookmarks and perform the actions of "deleting" or "clear reminders"
2024-05-22 12:50:21 -03:00

102 lines
2.8 KiB
JavaScript

import { action } from "@ember/object";
import { service } from "@ember/service";
import { popupAjaxError } from "discourse/lib/ajax-error";
import Bookmark from "discourse/models/bookmark";
import i18n from "discourse-common/helpers/i18n";
import DropdownSelectBoxComponent from "select-kit/components/dropdown-select-box";
const _customButtons = [];
const _customActions = {};
export function addBulkDropdownAction(name, customAction) {
_customActions[name] = customAction;
}
export default DropdownSelectBoxComponent.extend({
classNames: ["bulk-select-bookmarks-dropdown"],
headerIcon: null,
showFullTitle: true,
selectKitOptions: {
showCaret: true,
showFullTitle: true,
none: "select_kit.components.bulk_select_bookmarks_dropdown.title",
},
router: service(),
toasts: service(),
dialog: service(),
get content() {
let options = [];
options = options.concat([
{
id: "clear-reminders",
icon: "tag",
name: i18n("bookmark_bulk_actions.clear_reminders.name"),
},
{
id: "delete-bookmarks",
icon: "trash-alt",
name: i18n("bookmark_bulk_actions.delete_bookmarks.name"),
},
]);
return [...options, ..._customButtons];
},
getSelectedBookmarks() {
return this.bulkSelectHelper.selected;
},
@action
onSelect(id) {
switch (id) {
case "clear-reminders":
this.dialog.yesNoConfirm({
message: i18n(
`js.bookmark_bulk_actions.clear_reminders.description`,
{
count: this.getSelectedBookmarks().length,
}
),
didConfirm: () => {
Bookmark.bulkOperation(this.getSelectedBookmarks(), {
type: "clear_reminder",
})
.then(() => {
this.router.refresh();
this.toasts.success({
duration: 3000,
data: { message: i18n("bookmarks.bulk.reminders_cleared") },
});
})
.catch(popupAjaxError);
},
});
break;
case "delete-bookmarks":
this.dialog.deleteConfirm({
message: i18n(
`js.bookmark_bulk_actions.delete_bookmarks.description`,
{
count: this.getSelectedBookmarks().length,
}
),
didConfirm: () => {
Bookmark.bulkOperation(this.getSelectedBookmarks(), {
type: "delete",
})
.then(() => {
this.router.refresh();
this.toasts.success({
duration: 3000,
data: { message: i18n("bookmarks.bulk.delete_completed") },
});
})
.catch(popupAjaxError);
},
});
}
},
});