import BasicWidget from "../basic_widget.js"; const DELETE_NOTE_BUTTON_CLASS = "confirm-dialog-delete-note"; const TPL = ` `; export default class ConfirmDialog extends BasicWidget { 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.$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}) { this.$originallyFocused = $(':focus'); this.$custom.hide(); glob.activeDialog = this.$widget; if (typeof message === 'string') { message = $("
").text(message); } this.$confirmContent.empty().append(message); this.$widget.modal(); this.resolve = callback; } showConfirmDeleteNoteBoxWithNoteDialogEvent({title, callback}) { glob.activeDialog = this.$widget; this.$confirmContent.text(`Are you sure you want to remove the note "${title}" from relation map?`); this.$custom.empty() .append("
") .append($("
") .addClass("form-check") .append( $("