mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-08 11:16:47 +00:00
As the storage pages; reviewed with Codex. - The list is a card per network: its name with Active or Stopped and Autostart badges, its type (network_mode: Isolated, NAT, Routed, Open, Bridge, Macvtap, SR-IOV), its device, and each address with its DHCP range; a bridge or macvtap network's addresses come from the outside network. - A network's page: its heading starts or stops it, the menu sets autostart and deletes a stopped one. A Network card tells its state, type, bridge or interface, MAC and what the type does; a card per address (every <ip>, each with its DHCP range dialog, which libvirt takes on a stopped network); its fixed addresses of every subnet in one table, searched, each with Edit and Delete, one dialog adding and editing them; the VMs whose definition names it, connected or configured, linked (wvmNetwork.get_vms, one domain listing, a VM undefined meanwhile left out); its bandwidth limits where libvirt sets them (not on macvtap or SR-IOV networks), in KiB/s, from the saved definition with a note that a running network takes them when restarted; its XML in an accordion. The page reads the running and the saved definition once each, and only to render itself: its actions, which all redirect, read nothing of it first. - The New network dialog is one form, as the New pool one: the type as radio cards (the radio_card.html include, now shared by both), the chosen type's fields only, IPv6 with its box, a bridge or interface suggested from the host's (get_host_interfaces, not the bridges libvirt made for its own networks); a refused network or one libvirt refuses opens the dialog again with what was entered, the reasons beside the fields and focus on the first. - What the New pool and New network dialogs share is one script, static/js/choice_dialog.js: the radio cards show their fieldsets (data-kinds) and a refused form opens again focused on its first refused field; each dialog keeps only its own changes. - The fixed-address dialogs per family go to the page's own dialog.
38 lines
1.8 KiB
JavaScript
38 lines
1.8 KiB
JavaScript
// A create dialog of one form whose radio cards choose what is made (the
|
|
// New pool and New network dialogs): a fieldset shows for the choices in
|
|
// its data-kinds, the others are hidden and disabled, so neither checked
|
|
// nor sent; onChoose(value) does what else a choice changes. A form the
|
|
// server refused (data-open on the dialog) opens again with what was
|
|
// entered: the choice sent back, or the first when it is offered no more,
|
|
// and focus on the first refused field shown, or on the reasons.
|
|
function choiceDialog(dialog, radioName, onChoose) {
|
|
var form = dialog.querySelector("form");
|
|
var radios = form.querySelectorAll("input[name=" + radioName + "]");
|
|
function choose(value) {
|
|
form.querySelectorAll("fieldset[data-kinds]").forEach(function (fields) {
|
|
fields.hidden = fields.disabled = !fields.dataset.kinds.split(" ").includes(value);
|
|
});
|
|
onChoose(value);
|
|
}
|
|
radios.forEach(function (radio) {
|
|
radio.addEventListener("change", function () { choose(radio.value); });
|
|
});
|
|
var chosen = form.querySelector("input[name=" + radioName + "]:checked") || radios[0];
|
|
chosen.checked = true;
|
|
choose(chosen.value);
|
|
if (dialog.hasAttribute("data-open")) {
|
|
dialog.addEventListener("shown.bs.modal", function () {
|
|
var refused = Array.from(form.querySelectorAll("[aria-invalid=true]")).find(function (field) {
|
|
return !field.closest("fieldset[hidden]");
|
|
});
|
|
var reasons = form.querySelector(".form-errors");
|
|
if (refused) {
|
|
refused.focus();
|
|
} else if (reasons) {
|
|
reasons.tabIndex = -1;
|
|
reasons.focus();
|
|
}
|
|
}, {once: true});
|
|
bootstrap.Modal.getOrCreateInstance(dialog).show();
|
|
}
|
|
}
|