try global vars

This commit is contained in:
Arthur Lu 2023-01-11 02:57:37 -08:00
parent 7e71d098c4
commit 4f8f4ae863

View File

@ -2,6 +2,22 @@ import {request, goToPage, getURIData} from "./utils.js";
window.addEventListener("DOMContentLoaded", init); window.addEventListener("DOMContentLoaded", init);
let diskConfig = {
lxc: {
prefixOrder: ["mp"],
mp: {name: "MP", limit: 255, used: {}}
},
qemu: {
prefixOrder: ["sata", "ide"],
ide: {name: "IDE", limit: 3, used: {}},
sata: {name: "SATA", limit: 5, used: {}}
}
}
let node;
let type;
let vmid;
async function init () { async function init () {
let cookie = document.cookie; let cookie = document.cookie;
if (cookie === "") { if (cookie === "") {
@ -9,9 +25,9 @@ async function init () {
} }
let uriData = getURIData(); let uriData = getURIData();
let node = uriData.node; node = uriData.node;
let type = uriData.type; type = uriData.type;
let vmid = uriData.vmid; vmid = uriData.vmid;
await populateForm(node, type, vmid); await populateForm(node, type, vmid);
let cancelButton = document.querySelector("#cancel"); let cancelButton = document.querySelector("#cancel");
@ -29,18 +45,6 @@ async function populateForm (node, type, vmid) {
let config = await request(`/nodes/${node}/${type}/${vmid}/config`); let config = await request(`/nodes/${node}/${type}/${vmid}/config`);
console.log(config); console.log(config);
let diskConfig = {
lxc: {
prefixOrder: ["mp"],
mp: {name: "MP", limit: 255, used: {}}
},
qemu: {
prefixOrder: ["sata", "ide"],
ide: {name: "IDE", limit: 3, used: {}},
sata: {name: "SATA", limit: 5, used: {}}
}
}
let name = type === "qemu" ? "name" : "hostname"; let name = type === "qemu" ? "name" : "hostname";
addMetaLine("name", "Name", {type: "text", value: config.data[name]}); addMetaLine("name", "Name", {type: "text", value: config.data[name]});
addResourceLine("resources", "images/resources/cpu.svg", "Cores", {type: "number", value: config.data.cores, min: 1, max: 8192}, "Threads"); // TODO add max from quota API addResourceLine("resources", "images/resources/cpu.svg", "Cores", {type: "number", value: config.data.cores, min: 1, max: 8192}, "Threads"); // TODO add max from quota API
@ -73,10 +77,10 @@ async function populateForm (node, type, vmid) {
addDiskBus.value = def; addDiskBus.value = def;
handleDiskBusChange(diskConfig); handleDiskBusChange(diskConfig);
addDiskBus.addEventListener("change", handleDiskBusChange({c: diskConfig, t: type})); addDiskBus.addEventListener("change", handleDiskBusChange());
addDiskDevice.addEventListener("input", handleDiskDeviceChange({c: diskConfig, t: type})); addDiskDevice.addEventListener("input", handleDiskDeviceChange());
addDiskDevice.addEventListener("focus", handleDiskDeviceChange({c: diskConfig, t: type})); addDiskDevice.addEventListener("focus", handleDiskDeviceChange());
let addDiskStorage = document.querySelector("#add-disk #storage"); let addDiskStorage = document.querySelector("#add-disk #storage");
let addDiskSize = document.querySelector("#add-disk #size"); let addDiskSize = document.querySelector("#add-disk #size");
@ -100,9 +104,7 @@ function getNextAvaliable(entry){
return nextAvaliable; return nextAvaliable;
} }
function handleDiskBusChange (data) { function handleDiskBusChange () {
let diskConfig = data.c;
let type = data.t;
let bus = document.querySelector("#add-disk #bus").value; let bus = document.querySelector("#add-disk #bus").value;
let entry = diskConfig[type][bus]; let entry = diskConfig[type][bus];
let limit = entry.limit; let limit = entry.limit;
@ -118,9 +120,7 @@ function handleDiskBusChange (data) {
handleDiskDeviceChange(); handleDiskDeviceChange();
} }
function handleDiskDeviceChange (data) { function handleDiskDeviceChange () {
let diskConfig = data.diskConfig;
let type = data.type;
let value = document.querySelector("#add-disk #device").value; let value = document.querySelector("#add-disk #device").value;
let bus = document.querySelector("#add-disk #bus").value; let bus = document.querySelector("#add-disk #bus").value;
let entry = diskConfig[type][bus]; let entry = diskConfig[type][bus];