65 lines
2.0 KiB
JavaScript
Raw Normal View History

2024-07-24 17:34:26 +08:00
import { t } from "../../services/i18n.js";
2022-06-16 19:53:33 +02:00
import utils from "../../services/utils.js";
import BasicWidget from "../basic_widget.js";
const TPL = `
<div class="info-dialog modal mx-auto" tabindex="-1" role="dialog" style="z-index: 2000;">
2022-06-16 19:53:33 +02:00
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
2024-07-24 17:34:26 +08:00
<h5 class="modal-title mr-auto">${t("info.modalTitle")}</h5>
2022-06-16 19:53:33 +02:00
2024-07-24 17:34:26 +08:00
<button type="button" class="close" data-dismiss="modal" aria-label="${t("info.closeButton")}">
2022-06-16 19:53:33 +02:00
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="info-dialog-content"></div>
</div>
<div class="modal-footer">
2024-07-24 17:34:26 +08:00
<button class="info-dialog-ok-button btn btn-primary btn-sm">${t("info.okButton")}</button>
2022-06-16 19:53:33 +02:00
</div>
</div>
</div>
</div>`;
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 afterward
2022-06-16 19:53:33 +02:00
}
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;
}
}