import BasicWidget from "../basic_widget.js"; import server from "../../services/server.js"; import dialogService from "../../services/dialog.js"; import toastService from "../../services/toast.js"; import ws from "../../services/ws.js"; import appContext from "../../components/app_context.js"; const TPL = ` `; export default class AttachmentActionsWidget extends BasicWidget { constructor(attachment) { super(); this.attachment = attachment; } doRender() { this.$widget = $(TPL); this.$widget.on('click', '.dropdown-item', () => this.$widget.find("[data-toggle='dropdown']").dropdown('toggle')); } async deleteAttachmentCommand() { if (await dialogService.confirm(`Are you sure you want to delete attachment '${this.attachment.title}'?`)) { await server.remove(`attachments/${this.attachment.attachmentId}`); toastService.showMessage(`Attachment '${this.attachment.title}' has been deleted.`); } } async convertAttachmentIntoNoteCommand() { if (await dialogService.confirm(`Are you sure you want to convert attachment '${this.attachment.title}' into a separate note?`)) { const {note: newNote} = await server.post(`attachments/${this.attachment.attachmentId}/convert-to-note`) toastService.showMessage(`Attachment '${this.attachment.title}' has been converted to note.`); await ws.waitForMaxKnownEntityChangeId(); await appContext.tabManager.getActiveContext().setNote(newNote.noteId); } } }