set minimum size on unit change,

check min  size value on unit change

Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
Arthur Lu 2023-01-16 16:06:19 -08:00
parent a4ea5a2a60
commit 680bb92242

View File

@ -31,7 +31,6 @@ async function init () {
type = uriData.type; type = uriData.type;
vmid = uriData.vmid; vmid = uriData.vmid;
await populateResources(); await populateResources();
await populateAddDisk();
let cancelButton = document.querySelector("#cancel"); let cancelButton = document.querySelector("#cancel");
cancelButton.addEventListener("click", () => { cancelButton.addEventListener("click", () => {
@ -142,8 +141,10 @@ function addDiskLine (fieldset, busPrefix, busName, device, storage, storageOpti
let sizeInput = document.createElement("input"); let sizeInput = document.createElement("input");
sizeInput.type = "number"; sizeInput.type = "number";
sizeInput.min = size; sizeInput.min = size;
sizeInput.minSize = size;
sizeInput.max = 1023; // just use the next unit sizeInput.max = 1023; // just use the next unit
sizeInput.value = size; sizeInput.value = size;
sizeInput.id = `${busPrefix}${device}:size`;
if (!diskConfig[type][busPrefix].resizable) { if (!diskConfig[type][busPrefix].resizable) {
sizeInput.disabled = true; sizeInput.disabled = true;
} }
@ -157,6 +158,8 @@ function addDiskLine (fieldset, busPrefix, busName, device, storage, storageOpti
if (!diskConfig[type][busPrefix].resizable) { if (!diskConfig[type][busPrefix].resizable) {
sizeUnitSelect.disabled = true; sizeUnitSelect.disabled = true;
} }
sizeUnitSelect.id = `${busPrefix}${device}:unit`;
sizeUnitSelect.addEventListener("change", handleUnitChange);
field.append(sizeUnitSelect); field.append(sizeUnitSelect);
let deleteDiv = document.createElement("div"); let deleteDiv = document.createElement("div");
@ -169,6 +172,20 @@ function addDiskLine (fieldset, busPrefix, busName, device, storage, storageOpti
field.append(deleteDiv); field.append(deleteDiv);
} }
function handleUnitChange () {
let newUnitIndex = this.selectedIndex;
let sizeInput = document.querySelector(`${this.id.replace("unit", "size")}`);
if (newUnitIndex == 0) {
sizeInput.min = sizeInput.minSize;
if (sizeInput.value < sizeInput.min) {
sizeInput.value = sizeInput.min;
}
}
else {
sizeInput.min = 1;
}
}
function getOrderedUsed(entry){ function getOrderedUsed(entry){
let ordered_keys = Object.keys(entry.used).sort((a,b) => {parseInt(a) - parseInt(b)}); // ordered integer list let ordered_keys = Object.keys(entry.used).sort((a,b) => {parseInt(a) - parseInt(b)}); // ordered integer list
return ordered_keys; return ordered_keys;