remove appendFormBody

Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
Arthur Lu 2023-02-14 22:55:09 +00:00
parent 424f33c840
commit 1149ff5c7a
2 changed files with 17 additions and 40 deletions

View File

@ -262,37 +262,23 @@ async function handleDiskMove () {
dialog.header = `Move ${this.dataset.disk}`; dialog.header = `Move ${this.dataset.disk}`;
let storageLabel = document.createElement("label"); let options = "";
storageLabel.for = "storage-select";
storageLabel.innerText = "Storage";
dialog.formBodyAppend(storageLabel);
let storageSelect = document.createElement("select");
storageSelect.name = "storage-select";
storageSelect.id = "storage-select";
storage.data.forEach((element) => { storage.data.forEach((element) => {
if (element.content.includes(content)){ if (element.content.includes(content)){
storageSelect.add(new Option(element.storage)); options += `<option value="${element.storage}">${element.storage}</option>"`;
} }
}); });
dialog.formBodyAppend(storageSelect); let select = `<label for="storage-select">Storage</label><select name="storage-select" id="storage-select">${options}</select>`;
let deleteLabel = document.createElement("label"); dialog.formBody = `
deleteLabel.for = "delete-check"; ${select}
deleteLabel.innerText = "Delete Source"; <label for="delete-check">Delete Source</label><input name="delete-check" id="delete-check" type="checkbox" checked>
dialog.formBodyAppend(deleteLabel); `;
let deleteCheckbox = document.createElement("input");
deleteCheckbox.type = "checkbox";
deleteCheckbox.name = "delete-check"
deleteCheckbox.id = "delete-check"
deleteCheckbox.checked = true;
dialog.formBodyAppend(deleteCheckbox);
dialog.callback = async (result, form) => { dialog.callback = async (result, form) => {
if (result === "confirm") { if (result === "confirm") {
document.querySelector(`img[data-disk="${this.dataset.disk}"]`).src = "images/actions/loading.svg"; document.querySelector(`img[data-disk="${this.dataset.disk}"]`).src = "images/actions/loading.svg";
let action = {storage: storageSelect.value, delete: deleteCheckbox.checked ? "1": "0"} let action = {storage: form.get("storage-select"), delete: form.get("delete-check") === "on" ? "1": "0"}
if (type === "qemu") { // if vm, move disk if (type === "qemu") { // if vm, move disk
action.disk = this.dataset.disk; action.disk = this.dataset.disk;
} }
@ -357,25 +343,20 @@ async function handleDiskAdd () {
let diskImage = config.data[this.dataset.disk]; let diskImage = config.data[this.dataset.disk];
dialog.header = `Create A New Disk`; dialog.header = `Create A New Disk`;
dialog.formBody = `
<label for="device">${type === "qemu" ? "SATA" : "MP"}</label><input name="device" id="device" type="number" min="0" max="${type === "qemu" ? "5" : "255"}" value="0"></input>
<label for="size">Size (GiB)</label><input name="size" id="size" type="number" min="0" max="131072" value="0"></input>
`;
let storageLabel = document.createElement("label"); let options = "";
storageLabel.for = "storage-select";
storageLabel.innerText = "Storage";
dialog.formBodyAppend(storageLabel);
let storageSelect = document.createElement("select");
storageSelect.name = "storage-select";
storageSelect.id = "storage-select";
storage.data.forEach((element) => { storage.data.forEach((element) => {
if (element.content.includes(content)){ if (element.content.includes(content)){
storageSelect.add(new Option(element.storage)); options += `<option value="${element.storage}">${element.storage}</option>"`;
} }
}); });
dialog.formBodyAppend(storageSelect); let select = `<label for="storage-select">Storage</label><select name="storage-select" id="storage-select">${options}</select>`;
dialog.formBody = `
<label for="device">${type === "qemu" ? "SATA" : "MP"}</label><input name="device" id="device" type="number" min="0" max="${type === "qemu" ? "5" : "255"}" value="0"></input>
${select}
<label for="size">Size (GiB)</label><input name="size" id="size" type="number" min="0" max="131072" value="0"></input>
`;
dialog.callback = () => { dialog.callback = () => {

View File

@ -33,10 +33,6 @@ export class Dialog extends HTMLElement {
this.form.innerHTML = formBody; this.form.innerHTML = formBody;
} }
formBodyAppend (element) {
this.form.append(element);
}
set callback (callback) { set callback (callback) {
this.dialog.addEventListener("close", async () => { this.dialog.addEventListener("close", async () => {
await callback(this.dialog.returnValue, new FormData(this.form)); await callback(this.dialog.returnValue, new FormData(this.form));