1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +00:00

fix(ui): a block or a job's cancel asks first; every delete and save says it is done

- Block in the Users list asks first: the user is signed out and their
  API tokens are deleted, which unblocking does not bring back. Block
  and Unblock then say what they did.
- Cancel on a job's page and in the job panel asks first, naming the
  job; the button says Cancel the job, apart from the dialog's Cancel.
- Deleting a user or a group, removing a host from the panel or an
  owner from a VM, and deleting an interface, a network filter or a
  secret say so, as the other deletes do.
- Renaming a tag and saving a VM's title and description say so.
This commit is contained in:
catborise 2026-11-21 20:47:26 +03:00
parent 00a44f7621
commit e79817e7db
22 changed files with 247 additions and 39 deletions

View file

@ -1,39 +1,33 @@
// A button with data-confirm asks in the page's confirm dialog before it acts:
// the dialog's title and its confirming button carry the button's own words
// (or its accessible name, for an icon), its body the data-confirm question.
// Confirmed, the button is clicked again, so its form sends its name and value.
// A button in another dialog hides that one while asking (Bootstrap does not
// stack dialogs) and shows it again after; Cancel gives the focus back.
document.addEventListener("click", function (event) {
var button = event.target.closest("button[data-confirm]");
if (!button || button.dataset.confirmed) return;
event.preventDefault();
// confirmAction asks in the page's confirm dialog before act runs: action is its
// title and its confirming button's words, question its body. opener is what
// asked (or null): in another dialog, that one is hidden while asking (Bootstrap
// does not stack dialogs) and shown again after; not confirmed, it takes the focus
// back, or its menu's toggle, as a menu's item is hidden with its menu.
function confirmAction(action, question, danger, act, opener) {
var dialog = document.getElementById("confirm-dialog");
var parent = button.closest(".modal");
var action = button.textContent.trim() || button.getAttribute("aria-label") || button.title;
var parent = opener && opener.closest(".modal");
var ok = dialog.querySelector("[data-confirm-ok]");
var confirmed = false;
dialog.querySelector(".modal-title").textContent = action;
dialog.querySelector(".modal-body").textContent = button.dataset.confirm;
dialog.querySelector(".modal-body").textContent = question;
ok.textContent = action;
ok.className = "btn " + (/\b(btn-|btn-outline-|text-)danger\b/.test(button.className) ? "btn-danger" : "btn-primary");
ok.disabled = false;
ok.className = "btn " + (danger ? "btn-danger" : "btn-primary");
ok.disabled = true; // until shown: Bootstrap does not hide a dialog still coming in
dialog.addEventListener("shown.bs.modal", function () { ok.disabled = false; }, {once: true});
ok.onclick = function () {
ok.disabled = true; // once: the dialog is still open while it hides
confirmed = true;
bootstrap.Modal.getInstance(dialog).hide();
button.dataset.confirmed = "1";
button.click();
delete button.dataset.confirmed;
act();
};
dialog.addEventListener("hidden.bs.modal", function () {
if (parent) {
// a form sent in place (the flavors) keeps its dialog; a page sent away does not care
bootstrap.Modal.getOrCreateInstance(parent).show();
} else if (!confirmed) {
// a menu's item is hidden with its menu: its toggle takes the focus
var menu = button.closest(".dropdown");
(menu ? menu.querySelector("[data-bs-toggle=dropdown]") : button).focus();
} else if (!confirmed && opener && opener.isConnected) {
var menu = opener.closest(".dropdown-menu");
var toggle = menu && menu.parentElement.querySelector("[data-bs-toggle=dropdown]");
(toggle || opener).focus();
}
}, {once: true});
var ask = function () { bootstrap.Modal.getOrCreateInstance(dialog).show(); };
@ -43,4 +37,18 @@ document.addEventListener("click", function (event) {
} else {
ask();
}
}
// A button with data-confirm asks first, in its own words (or its accessible name,
// for an icon); confirmed, it is clicked again, so its form sends its name and value.
document.addEventListener("click", function (event) {
var button = event.target.closest("button[data-confirm]");
if (!button || button.dataset.confirmed) return;
event.preventDefault();
var action = button.textContent.trim() || button.getAttribute("aria-label") || button.title;
confirmAction(action, button.dataset.confirm, /\b(btn-|btn-outline-|text-)danger\b/.test(button.className), function () {
button.dataset.confirmed = "1";
button.click();
delete button.dataset.confirmed;
}, button);
}, true);