ProxmoxAAS-Dashboard/scripts/config.js

43 lines
1.4 KiB
JavaScript
Raw Normal View History

import {request, goToPage, getURIData} from "./utils.js";
window.addEventListener("DOMContentLoaded", init);
async function init () {
let uriData = getURIData();
let node = uriData.node;
let type = uriData.type;
let vmid = uriData.vmid;
await populateForm(node, type, vmid);
}
async function populateForm (node, type, vmid) {
2022-12-20 00:21:24 +00:00
let config = await request(`/nodes/${node}/${type}/${vmid}/config`);
console.log(config);
2022-12-20 01:59:34 +00:00
addFormLine("cores", {innerText: "Cores:"}, {type: "number", value: config.data.cores, min: 1, max: 8192});
addFormLine("memory", {innerText: "Memory"}, {type: "number", value: config.data.memory, min: 16});
}
function addFormLine (id, labelAttr, inputAttr) {
let labelWrapperDiv = document.createElement("div");
let label = document.createElement("label");
label.for = id;
2022-12-20 02:08:16 +00:00
for (let k in labelAttr) {
2022-12-20 02:12:39 +00:00
label.setAttribute(k, labelAttr[k])
label[k] = labelAttr.k;
2022-12-20 01:59:34 +00:00
}
labelWrapperDiv.append(label);
let labelContainer = document.querySelector("#labels");
labelContainer.append(labelWrapperDiv);
let inputWrapperDiv = document.createElement("div");
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
}
inputWrapperDiv.append(input);
let inputContainer = document.querySelector("#inputs");
inputContainer.append(inputWrapperDiv);
}