add selector for size unit
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
parent
abe70d0b72
commit
eaf51064ac
@ -104,7 +104,7 @@ function addResourceLine (fieldset, iconHref, labelText, inputAttr, unitText=nul
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addDiskLine (fieldset, busPrefix, busName, device, storage, storageOptions, size) {
|
function addDiskLine (fieldset, busPrefix, busName, device, storage, storageOptions, size, sizeUnit, sizeUnitOptions) {
|
||||||
let field = document.querySelector(`#${fieldset}`);
|
let field = document.querySelector(`#${fieldset}`);
|
||||||
|
|
||||||
let icon = document.createElement("img");
|
let icon = document.createElement("img");
|
||||||
@ -141,13 +141,21 @@ 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 = 0;
|
sizeInput.min = size;
|
||||||
sizeInput.value = size.replace("G", "");
|
sizeInput.max = 1023; // just use the next unit
|
||||||
|
sizeInput.value = size;
|
||||||
if (!diskConfig[type][busPrefix].resizable) {
|
if (!diskConfig[type][busPrefix].resizable) {
|
||||||
sizeInput.disabled = true;
|
sizeInput.disabled = true;
|
||||||
}
|
}
|
||||||
field.append(sizeInput);
|
field.append(sizeInput);
|
||||||
|
|
||||||
|
let sizeUnit = document.createElement("select");
|
||||||
|
sizeUnitOptions.forEach((element) => {
|
||||||
|
sizeUnit.add(new Option(element));
|
||||||
|
});
|
||||||
|
sizeUnit.value = sizeUnit;
|
||||||
|
field.append(sizeUnit);
|
||||||
|
|
||||||
let deleteDiv = document.createElement("div");
|
let deleteDiv = document.createElement("div");
|
||||||
deleteDiv.classList.add("last-item");
|
deleteDiv.classList.add("last-item");
|
||||||
let deleteBtn = document.createElement("img");
|
let deleteBtn = document.createElement("img");
|
||||||
@ -174,5 +182,22 @@ function parseDisk (disk) { // disk in format: STORAGE: FILENAME, ARG1=..., ARG2
|
|||||||
let val = element.split("=")[1];
|
let val = element.split("=")[1];
|
||||||
parsed[key] = val;
|
parsed[key] = val;
|
||||||
});
|
});
|
||||||
|
if (parsed.size.includes("K")) {
|
||||||
|
parsed.sizeUnit = "KiB";
|
||||||
|
parsed.sizeUnitAllowed = ["KiB", "MiB", "GiB", "TiB"];
|
||||||
|
}
|
||||||
|
else if (parsed.size.includes("M")) {
|
||||||
|
parsed.sizeUnit = "MiB";
|
||||||
|
parsed.sizeUnitAllowed = ["MiB", "GiB", "TiB"];
|
||||||
|
}
|
||||||
|
else if (parsed.size.includes("G")) {
|
||||||
|
parsed.sizeUnit = "GiB";
|
||||||
|
parsed.sizeUnitAllowed = ["GiB", "TiB"];
|
||||||
|
}
|
||||||
|
else if (parsed.size.includes("T")) {
|
||||||
|
parsed.sizeUnit = "TiB";
|
||||||
|
parsed.sizeUnitAllowed = ["TiB"];
|
||||||
|
}
|
||||||
|
parsed.size = parsed.size.replace("T", "").replace("G", "").replace("M", "").replace("K", "");
|
||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user