import utils from "../../services/utils.js";
import BasicWidget from "../basic_widget.js";
const TPL = `
`;
export default class InfoDialog extends BasicWidget {
constructor() {
super();
this.resolve = null;
this.$originallyFocused = null; // element focused before the dialog was opened, so we can return to it afterwards
}
doRender() {
this.$widget = $(TPL);
this.$infoContent = this.$widget.find(".info-dialog-content");
this.$okButton = this.$widget.find(".info-dialog-ok-button");
this.$widget.on('shown.bs.modal', () => this.$okButton.trigger("focus"));
this.$widget.on("hidden.bs.modal", () => {
if (this.resolve) {
this.resolve();
}
if (this.$originallyFocused) {
this.$originallyFocused.trigger('focus');
this.$originallyFocused = null;
}
});
this.$okButton.on('click', () => this.$widget.modal("hide"));
}
showInfoDialogEvent({message, callback}) {
this.$originallyFocused = $(':focus');
this.$infoContent.text(message);
utils.openDialog(this.$widget);
this.resolve = callback;
}
}