diff --git a/apps/client/src/widgets/dialogs/confirm.ts b/apps/client/src/widgets/dialogs/confirm.ts deleted file mode 100644 index 8fa25a728..000000000 --- a/apps/client/src/widgets/dialogs/confirm.ts +++ /dev/null @@ -1,151 +0,0 @@ -import BasicWidget from "../basic_widget.js"; -import { t } from "../../services/i18n.js"; -import { Modal } from "bootstrap"; - -const DELETE_NOTE_BUTTON_CLASS = "confirm-dialog-delete-note"; - -const TPL = /*html*/` -`; - -export type ConfirmDialogResult = false | ConfirmDialogOptions; -export type ConfirmDialogCallback = (val?: ConfirmDialogResult) => void; - -export interface ConfirmDialogOptions { - confirmed: boolean; - isDeleteNoteChecked: boolean; -} - -// For "showConfirmDialog" - -export interface ConfirmWithMessageOptions { - message: string | HTMLElement | JQuery; - callback: ConfirmDialogCallback; -} - -export interface ConfirmWithTitleOptions { - title: string; - callback: ConfirmDialogCallback; -} - -export default class ConfirmDialog extends BasicWidget { - private resolve: ConfirmDialogCallback | null; - - private modal!: Modal; - private $originallyFocused!: JQuery | null; - private $confirmContent!: JQuery; - private $okButton!: JQuery; - private $cancelButton!: JQuery; - private $custom!: JQuery; - - constructor() { - super(); - - this.resolve = null; - this.$originallyFocused = null; // element focused before the dialog was opened, so we can return to it afterward - } - - doRender() { - this.$widget = $(TPL); - this.modal = Modal.getOrCreateInstance(this.$widget[0]); - this.$confirmContent = this.$widget.find(".confirm-dialog-content"); - this.$okButton = this.$widget.find(".confirm-dialog-ok-button"); - this.$cancelButton = this.$widget.find(".confirm-dialog-cancel-button"); - this.$custom = this.$widget.find(".confirm-dialog-custom"); - - this.$widget.on("shown.bs.modal", () => this.$okButton.trigger("focus")); - - this.$widget.on("hidden.bs.modal", () => { - if (this.resolve) { - this.resolve(false); - } - - if (this.$originallyFocused) { - this.$originallyFocused.trigger("focus"); - this.$originallyFocused = null; - } - }); - - this.$cancelButton.on("click", () => this.doResolve(false)); - this.$okButton.on("click", () => this.doResolve(true)); - } - - showConfirmDialogEvent({ message, callback }: ConfirmWithMessageOptions) { - this.$originallyFocused = $(":focus"); - - this.$custom.hide(); - - glob.activeDialog = this.$widget; - - if (typeof message === "string") { - message = $("
").text(message); - } - - this.$confirmContent.empty().append(message); - - this.modal.show(); - - this.resolve = callback; - } - - showConfirmDeleteNoteBoxWithNoteDialogEvent({ title, callback }: ConfirmWithTitleOptions) { - glob.activeDialog = this.$widget; - - this.$confirmContent.text(`${t("confirm.are_you_sure_remove_note", { title: title })}`); - - this.$custom - .empty() - .append("
") - .append( - $("
") - .addClass("form-check") - .append( - $("