mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 04:36:48 +00:00
fix(instances): a dependent list on the create pages shows only the latest choice
The machine types, volumes, templates and disk buses load when their parent changes. A slow answer for an earlier choice could arrive last and fill the list for the newer one, and while a list loaded it still held the previous choice's items, which could be submitted. Each list now empties when its load starts, and a newer load aborts the older request, so only the answer for the current choice fills it. Chosen volumes stay: they are found by name in any pool. Fixes #177 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
4f0ae3b30d
commit
49cf16ecbe
4 changed files with 56 additions and 10 deletions
|
|
@ -530,9 +530,17 @@
|
|||
return "/computes/" + COMPUTE + "/storage/" + encodeURIComponent(pool) + "/volumes";
|
||||
}
|
||||
|
||||
// A dependent list is empty while it loads, and a newer load aborts the
|
||||
// older one: an answer for the previous choice never fills it.
|
||||
function load_list(list, url, fill) {
|
||||
if (list.request) list.request.abort();
|
||||
list.request = $.getJSON(url, fill);
|
||||
return list.request;
|
||||
}
|
||||
|
||||
function load_volumes(pool) {
|
||||
return $.getJSON(volumes_url(pool), function (data) {
|
||||
images_control.clearOptions();
|
||||
images_control.clearOptions(); // keeps the chosen volumes
|
||||
return load_list(images_control, volumes_url(pool), function (data) {
|
||||
data['vols'].forEach(item => images_control.addOption({value: item, text: item}));
|
||||
});
|
||||
}
|
||||
|
|
@ -544,14 +552,17 @@
|
|||
}
|
||||
|
||||
function load_templates(pool) {
|
||||
return $.getJSON(volumes_url(pool), function (data) {
|
||||
document.querySelector("#template").replaceChildren(...data['vols'].map(item => new Option(item, item)));
|
||||
const list = document.querySelector("#template");
|
||||
list.replaceChildren();
|
||||
return load_list(list, volumes_url(pool), function (data) {
|
||||
list.replaceChildren(...data['vols'].map(item => new Option(item, item)));
|
||||
});
|
||||
}
|
||||
|
||||
function load_buses(bus_select, disk_type) {
|
||||
const url = "/computes/" + COMPUTE + "/archs/{{ arch|escapejs }}/machines/{{ machine|escapejs }}/disks/" + disk_type + "/buses";
|
||||
return $.getJSON(url, function (data) {
|
||||
bus_select.replaceChildren();
|
||||
return load_list(bus_select, url, function (data) {
|
||||
bus_select.replaceChildren(...data['bus'].map(item => new Option(item, item)));
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue