1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +00:00
webvirtcloud/static/js/bulk_migrate.js
catborise a492031d12 feat(bulk migrate): choose the VMs by tag
The Bulk Migrate page gets a "Choose by tag" list of its VMs' tags:
choosing one ticks the VMs with it that can migrate and unticks the
others, as a choice to review before Migrate; spread over the hosts, the
list is placed again as for any other tick. The job still gets the VMs
ticked, never the tag.
2026-11-18 21:20:19 +03:00

51 lines
2.2 KiB
JavaScript

// The Bulk Migrate page: another destination reloads the list; the header
// box ticks or unticks every VM that can migrate, "Also migrate the
// shut-off VMs" the shut-off ones, a tag chosen those with it (data-tags)
// and no others. Spread over the hosts, a change reloads
// the list too: where each VM goes depends on the others. The Migrate
// button counts the ticked VMs and is off while none is.
const choose = document.getElementById("bulk-migrate-choose");
const spreading = choose?.dataset.spread !== undefined;
function tick(selector, checked) {
document.querySelectorAll(selector).forEach(function (box) {
box.checked = checked;
});
}
function count() {
const ticked = document.querySelectorAll(".bulk-migrate-vm:checked").length;
const button = document.getElementById("bulk-migrate-submit");
if (button) {
button.disabled = ticked === 0;
document.getElementById("bulk-migrate-count").textContent = ticked;
}
}
document.getElementById("bulk-migrate-target")?.addEventListener("change", function (event) {
if (event.target.value !== "spread") {
// one host: the VMs ticked are the page's own choice again
choose.querySelectorAll("input[name=shown]").forEach((input) => input.remove());
}
event.target.form.submit();
});
document.getElementById("bulk-migrate-all")?.addEventListener("change", function (event) {
tick(".bulk-migrate-vm:not(:disabled)", event.target.checked);
});
document.getElementById("bulk-migrate-shut-off")?.addEventListener("change", function (event) {
tick(".bulk-migrate-vm[data-shut-off]:not(:disabled)", event.target.checked);
});
document.getElementById("bulk-migrate-tag")?.addEventListener("change", function (event) {
const tag = event.target.value;
if (tag) {
document.querySelectorAll(".bulk-migrate-vm:not(:disabled)").forEach(function (box) {
box.checked = (box.dataset.tags || "").split(" ").includes(tag);
});
}
});
document.addEventListener("change", function (event) {
if (spreading && event.target.id !== "bulk-migrate-parallel" && event.target.id !== "bulk-migrate-target") {
choose.submit();
return;
}
count();
});
count();