From d1546f5511a944f5eea966cfb51ddda5fe57946a Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Tue, 14 Feb 2023 22:55:09 +0000 Subject: [PATCH] remove appendFormBody Signed-off-by: Arthur Lu --- scripts/config.js | 53 +++++++++++++++-------------------------------- scripts/dialog.js | 4 ---- 2 files changed, 17 insertions(+), 40 deletions(-) diff --git a/scripts/config.js b/scripts/config.js index a59bcae..3060ded 100644 --- a/scripts/config.js +++ b/scripts/config.js @@ -262,37 +262,23 @@ async function handleDiskMove () { dialog.header = `Move ${this.dataset.disk}`; - let storageLabel = document.createElement("label"); - storageLabel.for = "storage-select"; - storageLabel.innerText = "Storage"; - dialog.formBodyAppend(storageLabel); - - let storageSelect = document.createElement("select"); - storageSelect.name = "storage-select"; - storageSelect.id = "storage-select"; + let options = ""; storage.data.forEach((element) => { if (element.content.includes(content)){ - storageSelect.add(new Option(element.storage)); + options += `"`; } }); - dialog.formBodyAppend(storageSelect); + let select = ``; - let deleteLabel = document.createElement("label"); - deleteLabel.for = "delete-check"; - deleteLabel.innerText = "Delete Source"; - 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.formBody = ` + ${select} + + `; dialog.callback = async (result, form) => { if (result === "confirm") { 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 action.disk = this.dataset.disk; } @@ -357,25 +343,20 @@ async function handleDiskAdd () { let diskImage = config.data[this.dataset.disk]; dialog.header = `Create A New Disk`; - dialog.formBody = ` - - - `; - let storageLabel = document.createElement("label"); - storageLabel.for = "storage-select"; - storageLabel.innerText = "Storage"; - dialog.formBodyAppend(storageLabel); - - let storageSelect = document.createElement("select"); - storageSelect.name = "storage-select"; - storageSelect.id = "storage-select"; + let options = ""; storage.data.forEach((element) => { if (element.content.includes(content)){ - storageSelect.add(new Option(element.storage)); + options += `"`; } }); - dialog.formBodyAppend(storageSelect); + let select = ``; + + dialog.formBody = ` + + ${select} + + `; dialog.callback = () => { diff --git a/scripts/dialog.js b/scripts/dialog.js index 18f491d..d321143 100644 --- a/scripts/dialog.js +++ b/scripts/dialog.js @@ -32,10 +32,6 @@ export class Dialog extends HTMLElement { set formBody (formBody) { this.form.innerHTML = formBody; } - - formBodyAppend (element) { - this.form.append(element); - } set callback (callback) { this.dialog.addEventListener("close", async () => {