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 = `
|
2022-09-18 13:52:19 +02:00
|
|
|
<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-09-03 18:15:10 +02:00
|
|
|
<h5 class="modal-title">${t("info.modalTitle")}</h5>
|
|
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="${t("info.closeButton")}"></button>
|
2022-06-16 19:53:33 +02:00
|
|
|
</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;
|
2023-05-05 23:17:23 +02:00
|
|
|
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);
|
2024-09-03 18:15:10 +02:00
|
|
|
this.modal = bootstrap.Modal.getOrCreateInstance(this.$widget);
|
2022-06-16 19:53:33 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-09-03 18:15:10 +02:00
|
|
|
this.$okButton.on('click', () => this.modal.hide());
|
2022-06-16 19:53:33 +02:00
|
|
|
}
|
|
|
|
|
2024-09-03 18:15:10 +02:00
|
|
|
showInfoDialogEvent({ message, callback }) {
|
2022-06-16 19:53:33 +02:00
|
|
|
this.$originallyFocused = $(':focus');
|
|
|
|
|
|
|
|
this.$infoContent.text(message);
|
|
|
|
|
|
|
|
utils.openDialog(this.$widget);
|
|
|
|
|
|
|
|
this.resolve = callback;
|
|
|
|
}
|
|
|
|
}
|