import utils from "../../services/utils.js"; import BasicWidget from "../basic_widget.js"; const TPL = ` `; export default class PromptDialog extends BasicWidget { constructor() { super(); this.resolve = null; this.shownCb = null; } doRender() { this.$widget = $(TPL); this.$dialogBody = this.$widget.find(".modal-body"); this.$form = this.$widget.find("#prompt-dialog-form"); this.$question = null; this.$answer = null; this.$widget.on('shown.bs.modal', () => { if (this.shownCb) { this.shownCb({ $dialog: this.$widget, $question: this.$question, $answer: this.$answer, $form: this.$form }); } this.$answer.trigger('focus').select(); }); this.$widget.on("hidden.bs.modal", () => { if (this.resolve) { this.resolve(null); } }); this.$form.on('submit', e => { e.preventDefault(); this.resolve(this.$answer.val()); this.$widget.modal('hide'); }); } showPromptDialogEvent({ title, message, defaultValue, shown, callback }) { this.shownCb = shown; this.resolve = callback; this.$widget.find(".prompt-title").text(title || "Prompt"); this.$question = $("