39 lines
1.1 KiB
JavaScript

function _confirm({ message, title, callbackyes, callbackno, yesLabel, noLabel }) {
const dialogTemplate = jfa.page.getDialogTemplate().content;
let spanTitle = dialogTemplate.querySelector(".modal__title__text");
spanTitle.textContent = title || "Confirm";
let bodyMessage = dialogTemplate.querySelector(".modal__body-message");
bodyMessage.textContent = message;
const dialog = dialogTemplate.querySelector("#dialog-container");
const modal = bootstrap.Modal.getOrCreateInstance(dialog);
let buttonNo = dialogTemplate.querySelector(".modal__footer__button-no");
if (noLabel) {
buttonNo.textContent = noLabel;
}
buttonNo.addEventListener("click", function () {
buttonNo.blur();
modal.hide();
callbackno?.();
});
let buttonYes = dialogTemplate.querySelector(".modal__footer__button-yes");
if (yesLabel) {
buttonYes.textContent = yesLabel;
}
buttonYes.addEventListener("click", function () {
buttonYes.blur();
modal.hide();
callbackyes?.();
});
modal.show();
}
export default {
confirm: _confirm
};