2019-06-10 22:45:03 +02:00
|
|
|
import utils from "../services/utils.js";
|
|
|
|
|
2018-11-12 20:17:48 +01:00
|
|
|
const $dialog = $("#info-dialog");
|
|
|
|
const $infoContent = $("#info-dialog-content");
|
|
|
|
const $okButton = $("#info-dialog-ok-button");
|
|
|
|
|
|
|
|
let resolve;
|
2019-07-02 21:54:37 +02:00
|
|
|
let $originallyFocused; // element focused before the dialog was opened so we can return to it afterwards
|
2018-11-12 20:17:48 +01:00
|
|
|
|
2019-08-20 21:40:47 +02:00
|
|
|
export function info(message) {
|
2019-07-02 21:54:37 +02:00
|
|
|
$originallyFocused = $(':focus');
|
|
|
|
|
2018-11-12 20:17:48 +01:00
|
|
|
$infoContent.text(message);
|
|
|
|
|
2020-02-09 10:00:13 +01:00
|
|
|
utils.openDialog($dialog);
|
2018-11-12 20:17:48 +01:00
|
|
|
|
2018-11-12 21:18:22 +01:00
|
|
|
return new Promise((res, rej) => { resolve = res; });
|
2018-11-12 20:17:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$dialog.on('shown.bs.modal', () => $okButton.trigger("focus"));
|
|
|
|
|
|
|
|
$dialog.on("hidden.bs.modal", () => {
|
|
|
|
if (resolve) {
|
|
|
|
resolve();
|
|
|
|
}
|
2019-07-02 21:54:37 +02:00
|
|
|
|
|
|
|
if ($originallyFocused) {
|
2019-11-09 17:45:22 +01:00
|
|
|
$originallyFocused.trigger('focus');
|
2019-07-02 21:54:37 +02:00
|
|
|
$originallyFocused = null;
|
|
|
|
}
|
2018-11-12 20:17:48 +01:00
|
|
|
});
|
|
|
|
|
2019-11-09 17:39:48 +01:00
|
|
|
$okButton.on('click', () => $dialog.modal("hide"));
|