2022-12-19 06:14:57 +00:00
|
|
|
import {request, goToPage, getURIData} from "./utils.js";
|
|
|
|
|
|
|
|
window.addEventListener("DOMContentLoaded", init);
|
|
|
|
|
|
|
|
async function init () {
|
2022-12-20 23:15:08 +00:00
|
|
|
let cookie = document.cookie;
|
|
|
|
if (cookie === "") {
|
|
|
|
goToPage("login.html");
|
|
|
|
}
|
|
|
|
|
2022-12-19 06:14:57 +00:00
|
|
|
let uriData = getURIData();
|
2022-12-20 00:13:43 +00:00
|
|
|
let node = uriData.node;
|
|
|
|
let type = uriData.type;
|
|
|
|
let vmid = uriData.vmid;
|
|
|
|
await populateForm(node, type, vmid);
|
2022-12-20 23:42:13 +00:00
|
|
|
|
|
|
|
let cancelButton = document.querySelector("#cancel");
|
|
|
|
cancelButton.addEventListener("click", () => {
|
|
|
|
goToPage("index.html");
|
|
|
|
});
|
2022-12-20 00:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function populateForm (node, type, vmid) {
|
2022-12-20 00:21:24 +00:00
|
|
|
let config = await request(`/nodes/${node}/${type}/${vmid}/config`);
|
2022-12-20 00:13:43 +00:00
|
|
|
console.log(config);
|
2022-12-20 01:59:34 +00:00
|
|
|
|
2022-12-20 02:21:48 +00:00
|
|
|
addFormLine("cores", "Cores", {type: "number", value: config.data.cores, min: 1, max: 8192});
|
|
|
|
addFormLine("memory", "Memory", {type: "number", value: config.data.memory, min: 16});
|
2022-12-20 23:37:04 +00:00
|
|
|
|
|
|
|
let i = 0;
|
|
|
|
while(Object.hasOwn(config.data, `sata${i}`)){
|
|
|
|
addFormLine(`sata${i}`, `SATA ${i}`, {type: "text", value: config.data[`sata${i}`]});
|
2022-12-20 23:38:53 +00:00
|
|
|
i++;
|
2022-12-20 23:37:04 +00:00
|
|
|
}
|
2022-12-20 01:59:34 +00:00
|
|
|
}
|
|
|
|
|
2022-12-20 02:21:48 +00:00
|
|
|
function addFormLine (id, labelName, inputAttr) {
|
2022-12-20 02:46:28 +00:00
|
|
|
let form = document.querySelector("#user-configurable");
|
|
|
|
|
2022-12-20 01:59:34 +00:00
|
|
|
let label = document.createElement("label");
|
|
|
|
label.for = id;
|
2022-12-20 02:21:48 +00:00
|
|
|
label.innerHTML = labelName;
|
2022-12-20 02:46:28 +00:00
|
|
|
form.append(label);
|
2022-12-20 01:59:34 +00:00
|
|
|
|
|
|
|
let input = document.createElement("input");
|
|
|
|
input.id = id;
|
|
|
|
input.name = id;
|
2022-12-20 02:08:16 +00:00
|
|
|
for (let k in inputAttr) {
|
2022-12-20 02:12:39 +00:00
|
|
|
input.setAttribute(k, inputAttr[k])
|
2022-12-20 01:59:34 +00:00
|
|
|
}
|
2022-12-20 02:46:28 +00:00
|
|
|
form.append(input);
|
2022-12-19 06:14:57 +00:00
|
|
|
}
|