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

fix(ui): forms ask one thing at a time, offer the host's pools and say less twice

- A backup schedule asks Which VMs first (a compute's, chosen VMs or a
  tag's) and shows that one field only (policy_scope.js); the other two
  are not read, so a choice left in them is neither saved nor an error.
- A backup target's, a restore's and a disk restore's storage pool
  field offers the chosen compute's active file pools, the ones a
  restore copies into (a target's: directory and NFS only), from
  vmbackups.views.pools, which reads them without a refresh
  (pool_choices.js); a name can still be typed and is checked as before.
- A field's label is no longer repeated inside it as a placeholder, and
  a list's empty choice says Choose… instead of Django's dashes
  (webvirtcloud.bootstrap.FieldRenderer).
- The schedule, target, e-mail OTP and VM delete forms put Cancel and
  their main button at the right, as the other forms do.
This commit is contained in:
catborise 2026-11-22 00:09:10 +03:00
parent 7359fbb147
commit 4881c3cd3e
23 changed files with 228 additions and 69 deletions

View file

@ -0,0 +1,12 @@
// A backup schedule's Which VMs: only the field of the choice made shows (vmbackups.forms.PolicyForm).
(function () {
var choices = document.querySelectorAll("input[name='scope']");
function show() {
var chosen = document.querySelector("input[name='scope']:checked");
document.querySelectorAll("[data-scope]").forEach(function (field) {
field.hidden = !chosen || field.dataset.scope !== chosen.value;
});
}
choices.forEach(function (choice) { choice.addEventListener("change", show); });
show();
})();

View file

@ -0,0 +1,23 @@
// A form's storage pool field (data-pools: compute 0's pool list, vmbackups.views.pools) offers
// the pools of the compute chosen in the same form. A name can still be typed: the server checks it
// as before. An answer for a compute no longer chosen is left out.
document.querySelectorAll("input[data-pools]").forEach(function (input) {
var compute = input.form.elements.compute;
if (!compute) return;
var list = document.createElement("datalist");
list.id = input.id + "-choices";
input.after(list);
input.setAttribute("list", list.id);
input.setAttribute("autocomplete", "off");
function offer() {
var asked = compute.value;
list.replaceChildren();
if (!asked) return;
$.getJSON(input.dataset.pools.replace("/0/", "/" + encodeURIComponent(asked) + "/")).done(function (pools) {
if (compute.value !== asked) return;
list.replaceChildren.apply(list, pools.map(function (pool) { return new Option(pool.name); }));
});
}
compute.addEventListener("change", offer);
offer();
});