1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 01:16:10 +00:00

fix(instances): the VM list's bulk actions show in a bar while VMs are chosen

The actions on the chosen VMs stood above the table at all times, as two
rows of disabled buttons and empty text boxes. They are now a bar at the
foot of the window that appears once a VM is chosen and names how many
are. The snapshot name and the tag are asked in small menus of the bar,
and the table's head has the box that chooses the VMs shown.
This commit is contained in:
catborise 2026-11-21 19:12:04 +03:00
parent 85c727d397
commit 3167cf12fe
9 changed files with 92 additions and 41 deletions

View file

@ -1,4 +1,4 @@
// The VM list's bulk power form. Only the chosen VMs on screen count: one a
// The VM list's bulk action bar. Only the chosen VMs on screen count: one a
// filter or a collapsed host hides is neither counted nor sent, so a VM chosen
// before the filters changed is not powered unseen. "Choose the VMs shown"
// chooses or clears those on screen, and shows whether all, some or none are.
@ -14,12 +14,28 @@
var boxes = onScreen();
var chosen = boxes.filter(function (box) { return box.checked; }).length;
var tooMany = chosen > Number(count.dataset.max); // the server takes at most that many
form.querySelectorAll("button[name='action']").forEach(function (button) { button.disabled = chosen === 0 || tooMany; });
count.textContent = chosen ? (tooMany ? count.dataset.tooMany : count.dataset.text).replace("%(count)s", chosen) : "";
form.querySelectorAll("button[name='action']").forEach(function (button) { button.disabled = tooMany; });
count.textContent = (tooMany ? count.dataset.tooMany : count.dataset.text).replace("%(count)s", chosen);
count.classList.toggle("text-danger", tooMany);
// the bar at the window's foot, while any VM is chosen; the page ends above it
form.hidden = chosen === 0;
if (form.hidden) {
document.body.style.removeProperty("padding-bottom");
} else { // over base.html's pb-5
document.body.style.setProperty("padding-bottom", form.offsetHeight + "px", "important");
}
shown.disabled = boxes.length === 0;
shown.checked = boxes.length > 0 && chosen === boxes.length;
shown.indeterminate = chosen > 0 && chosen < boxes.length;
}
document.getElementById("bulk-power-clear").addEventListener("click", function () {
document.querySelectorAll("input[name='vm'][form='bulk-power']").forEach(function (box) { box.checked = false; });
update();
});
// a menu of the bar opens on its text box
form.addEventListener("shown.bs.dropdown", function (event) {
event.target.parentElement.querySelector("input[type='text']").focus();
});
shown.addEventListener("change", function () {
var choose = shown.checked;
onScreen().forEach(function (box) { box.checked = choose; });
@ -40,12 +56,15 @@
later = setTimeout(update, 50);
}).observe(document.querySelector(".table-responsive") || document.body,
{attributes: true, attributeFilter: ["hidden", "class"], subtree: true});
// Enter in a text box (a tag, a snapshot's name) would send the form with its first button,
// Start: it sends nothing
// Enter in a text box would send the form with its first button, Start: in a snapshot's
// name it takes the snapshots, in a tag (added or removed?) it sends nothing
form.querySelectorAll("input[type='text']").forEach(function (box) {
box.addEventListener("keydown", function (event) {
if (event.key === "Enter") {
if (event.key === "Enter" && !event.isComposing) { // not an input method's choice
event.preventDefault();
if (box.name === "snapshot_name") {
form.querySelector("button[value='snapshot']").click();
}
}
});
});
@ -64,11 +83,11 @@
update();
})();
// whether VMs on screen are chosen, or a snapshot name or tag typed: the list's reload
// whether VMs on screen are chosen, or a snapshot name or tag typed in the bar shown: the list's reload
// (poll.js pageInUse) waits meanwhile
function bulkPowerChosen() {
return Array.prototype.some.call(document.querySelectorAll("input[name='vm'][form='bulk-power']:checked"),
function (box) { return box.getClientRects().length > 0; })
|| Array.prototype.some.call(document.querySelectorAll("#bulk-power input[type='text']"),
|| Array.prototype.some.call(document.querySelectorAll("#bulk-power:not([hidden]) input[type='text']"),
function (box) { return box.value.trim() !== ""; });
}