mirror of
https://github.com/zadam/trilium.git
synced 2025-10-30 09:56:36 +01:00
added BS dialog for confirm
This commit is contained in:
38
src/public/javascripts/dialogs/confirm.js
Normal file
38
src/public/javascripts/dialogs/confirm.js
Normal file
@@ -0,0 +1,38 @@
|
||||
const $dialog = $("#confirm-dialog");
|
||||
const $confirmContent = $("#confirm-dialog-content");
|
||||
const $okButton = $("#confirm-dialog-ok-button");
|
||||
const $cancelButton = $("#confirm-dialog-cancel-button");
|
||||
|
||||
let resolve;
|
||||
|
||||
function confirm(message) {
|
||||
glob.activeDialog = $dialog;
|
||||
|
||||
$confirmContent.text(message);
|
||||
|
||||
$dialog.modal();
|
||||
|
||||
return new Promise((res, rej) => { resolve = res; });
|
||||
}
|
||||
|
||||
$dialog.on('shown.bs.modal', () => $okButton.trigger("focus"));
|
||||
|
||||
$dialog.on("hidden.bs.modal", () => {
|
||||
if (resolve) {
|
||||
resolve(false);
|
||||
}
|
||||
});
|
||||
|
||||
function doResolve(ret) {
|
||||
resolve(ret);
|
||||
resolve = null;
|
||||
|
||||
$dialog.modal("hide");
|
||||
}
|
||||
|
||||
$cancelButton.click(() => doResolve(false));
|
||||
$okButton.click(() => doResolve(true));
|
||||
|
||||
export default {
|
||||
confirm
|
||||
}
|
||||
Reference in New Issue
Block a user