diff --git a/index.html b/index.html
index 0519b37..70cbdf0 100644
--- a/index.html
+++ b/index.html
@@ -8,6 +8,7 @@
+
diff --git a/scripts/config.js b/scripts/config.js
index 9492694..c0bc5ed 100644
--- a/scripts/config.js
+++ b/scripts/config.js
@@ -1,5 +1,5 @@
import {requestPVE, requestAPI, goToPage, getURIData, resources} from "./utils.js";
-import {Dialog} from "./dialog.js";
+import {dialog} from "./dialog.js";
window.addEventListener("DOMContentLoaded", init); // do the dumb thing where the disk config refreshes every second
@@ -174,13 +174,9 @@ function addDiskLine (fieldset, busPrefix, busName, device, diskDetails) {
}
async function handleDiskDetach () {
- let dialog = document.createElement("dialog-form");
- document.body.append(dialog);
-
- dialog.header = `Detach ${this.dataset.disk}`;
- dialog.formBody = `
Are you sure you want to detach disk
${this.dataset.disk}
`;
-
- dialog.callback = async (result, form) => {
+ let header = `Detach ${this.dataset.disk}`;
+ let body = `Are you sure you want to detach disk
${this.dataset.disk}
`;
+ dialog(header, body, async (result, form) => {
if (result === "confirm") {
document.querySelector(`img[data-disk="${this.dataset.disk}"]`).src = "images/status/loading.svg";
let body = {
@@ -200,21 +196,16 @@ async function handleDiskDetach () {
populateDisk();
}
}
- };
-
- dialog.show();
+ });
}
async function handleDiskAttach () {
- let dialog = document.createElement("dialog-form");
- document.body.append(dialog);
-
let diskImage = config.data[this.dataset.disk];
- dialog.header = `Attach ${diskImage}`;
- dialog.formBody = ``;
+ let header = `Attach ${diskImage}`;
+ let body = ``;
- dialog.callback = async (result, form) => {
+ dialog(header, body, async (result, form) => {
if (result === "confirm") {
let device = form.get("device");
document.querySelector(`img[data-disk="${this.dataset.disk}"]`).src = "images/status/loading.svg";
@@ -236,19 +227,14 @@ async function handleDiskAttach () {
populateDisk();
}
}
- };
-
- dialog.show();
+ });
}
async function handleDiskResize () {
- let dialog = document.createElement("dialog-form");
- document.body.append(dialog);
+ let header = `Resize ${this.dataset.disk}`;
+ let body = ``;
- dialog.header = `Resize ${this.dataset.disk}`;
- dialog.formBody = ``;
-
- dialog.callback = async (result, form) => {
+ dialog(header, body, async (result, form) => {
if (result === "confirm") {
document.querySelector(`img[data-disk="${this.dataset.disk}"]`).src = "images/status/loading.svg";
let body = {
@@ -269,18 +255,14 @@ async function handleDiskResize () {
populateDisk();
}
}
- };
-
- dialog.show();
+ });
}
async function handleDiskMove () {
let content = type === "qemu" ? "images" : "rootdir";
let storage = await requestPVE(`/nodes/${node}/storage`, "GET", null);
- let dialog = document.createElement("dialog-form");
- document.body.append(dialog);
- dialog.header = `Move ${this.dataset.disk}`;
+ let header = `Move ${this.dataset.disk}`;
let options = "";
storage.data.forEach((element) => {
@@ -288,16 +270,14 @@ async function handleDiskMove () {
options += `"`;
}
});
- let select = ``;
+ let select = ``;
- dialog.formBody = `
+ let body = `
${select}
`;
- dialog.shadowRoot.querySelector("#storage-select").selectedIndex = -1;
-
- dialog.callback = async (result, form) => {
+ dialog(header, body, async (result, form) => {
if (result === "confirm") {
document.querySelector(`img[data-disk="${this.dataset.disk}"]`).src = "images/status/loading.svg";
let body = {
@@ -319,19 +299,14 @@ async function handleDiskMove () {
populateDisk();
}
}
- };
-
- dialog.show();
+ });
}
async function handleDiskDelete () {
- let dialog = document.createElement("dialog-form");
- document.body.append(dialog);
+ let header = `Delete ${this.dataset.disk}`;
+ let body = `Are you sure you want to delete disk
${this.dataset.disk}
`;
- dialog.header = `Delete ${this.dataset.disk}`;
- dialog.formBody = `Are you sure you want to delete disk
${this.dataset.disk}
`;
-
- dialog.callback = async (result, form) => {
+ dialog(header, body, async (result, form) => {
if (result === "confirm") {
document.querySelector(`img[data-disk="${this.dataset.disk}"]`).src = "images/status/loading.svg";
let body = {
@@ -351,18 +326,14 @@ async function handleDiskDelete () {
populateDisk();
}
}
- };
-
- dialog.show();
+ });
}
async function handleDiskAdd () {
let content = type === "qemu" ? "images" : "rootdir";
let storage = await requestPVE(`/nodes/${node}/storage`, "GET", null);
- let dialog = document.createElement("dialog-form");
- document.body.append(dialog);
- dialog.header = "Create New Disk";
+ let header = "Create New Disk";
let options = "";
storage.data.forEach((element) => {
@@ -370,17 +341,15 @@ async function handleDiskAdd () {
options += `"`;
}
});
- let select = ``;
+ let select = ``;
- dialog.formBody = `
+ let body = `
${select}
`;
- dialog.shadowRoot.querySelector("#storage-select").selectedIndex = -1;
-
- dialog.callback = async (result, form) => {
+ dialog(header, body, async (result, form) => {
if (result === "confirm") {
let body = {
node: node,
@@ -401,18 +370,14 @@ async function handleDiskAdd () {
populateDisk();
}
}
- };
-
- dialog.show();
+ });
}
async function handleCDAdd () {
let content = "iso";
let storage = await requestPVE(`/nodes/${node}/storage`, "GET", null);
- let dialog = document.createElement("dialog-form");
- document.body.append(dialog);
- dialog.header = `Add a CDROM`;
+ let header = `Add a CDROM`;
let storageOptions = "";
storage.data.forEach((element) => {
@@ -420,29 +385,15 @@ async function handleCDAdd () {
storageOptions += `"`;
}
});
- let storageSelect = ``;
+ let storageSelect = ``;
- dialog.formBody = `
+ let body = `
${storageSelect}
`;
- dialog.shadowRoot.querySelector("#storage-select").selectedIndex = -1;
-
- dialog.shadowRoot.querySelector("#storage-select").addEventListener("change", async () => {
- let storage = dialog.shadowRoot.querySelector("#storage-select").value;
- let ISOSelect = dialog.shadowRoot.querySelector("#iso-select");
- let isos = await requestPVE(`/nodes/${node}/storage/${storage}/content`, "GET", {content: content});
- isos.data.forEach((element) => {
- if (element.content.includes(content)) {
- ISOSelect.append(new Option(element.volid.replace(`${storage}:${content}/`, ""), element.volid));
- }
- });
- ISOSelect.selectedIndex = -1;
- });
-
- dialog.callback = async (result, form) => {
+ let d = dialog(header, body, async (result, form) => {
if (result === "confirm") {
let body = {
node: node,
@@ -462,9 +413,19 @@ async function handleCDAdd () {
populateDisk();
}
}
- };
+ });
- dialog.show();
+ d.querySelector("#storage-select").addEventListener("change", async () => {
+ let storage = document.querySelector("#storage-select").value;
+ let ISOSelect = document.querySelector("#iso-select");
+ ISOSelect.innerHTML = ``;
+ let isos = await requestPVE(`/nodes/${node}/storage/${storage}/content`, "GET", {content: content});
+ isos.data.forEach((element) => {
+ if (element.content.includes(content)) {
+ ISOSelect.append(new Option(element.volid.replace(`${storage}:${content}/`, ""), element.volid));
+ }
+ });
+ });
}
async function handleFormExit () {
diff --git a/scripts/dialog.js b/scripts/dialog.js
index 250b440..0600ea6 100644
--- a/scripts/dialog.js
+++ b/scripts/dialog.js
@@ -1,60 +1,39 @@
-export class Dialog extends HTMLElement {
- constructor () {
- super();
- let shadowRoot = this.attachShadow({mode: "open"});
+export function dialog (header, body, callback = async (result, form) => {}) {
+ let dialog = document.createElement("dialog");
+ dialog.innerHTML = `
+
+
+
+
+
+
+ `;
+ dialog.className = "w3-container w3-card w3-border-0";
+ dialog.querySelector("#prompt").innerText = header;
+ dialog.querySelector("form").innerHTML = body;
- shadowRoot.innerHTML = `
-
-
-
-
- `;
+ document.body.append(dialog);
+ dialog.showModal();
- this.shadowElement = shadowRoot;
- this.dialog = shadowRoot.querySelector("dialog");
- this.form = shadowRoot.querySelector("form");
- }
+ dialog.addEventListener("close", async () => {
+ await callback(dialog.returnValue, new FormData(dialog.querySelector("form")));
+ dialog.parentElement.removeChild(dialog);
+ });
- set header (header) {
- this.shadowElement.querySelector("#prompt").innerText = header;
- }
-
- set formBody (formBody) {
- this.form.innerHTML = formBody;
- }
-
- set callback (callback) {
- this.dialog.addEventListener("close", async () => {
- await callback(this.dialog.returnValue, new FormData(this.form));
- document.querySelector("dialog-form").remove();
- });
- }
- show () {
- this.dialog.showModal();
- }
+ return dialog;
}
export function alert (message) {
- let form = document.createElement("form");
- form.method = "dialog";
- form.innerHTML = `
- ${message}
-
-
-
- `;
-
let dialog = document.createElement("dialog");
- dialog.classList.add("w3-card");
- dialog.classList.add("w3-container");
- dialog.append(form);
+ dialog.innerHTML = `
+
+ `;
+ dialog.className = "w3-container w3-card w3-border-0";
document.body.append(dialog);
dialog.showModal();
@@ -62,6 +41,6 @@ export function alert (message) {
dialog.addEventListener("close", () => {
dialog.parentElement.removeChild(dialog);
})
-}
-customElements.define("dialog-form", Dialog);
\ No newline at end of file
+ return dialog;
+}
\ No newline at end of file
diff --git a/scripts/index.js b/scripts/index.js
index 30ae543..8b038f6 100644
--- a/scripts/index.js
+++ b/scripts/index.js
@@ -1,5 +1,5 @@
import {requestPVE, requestAPI, goToPage} from "./utils.js";
-import {Dialog} from "./dialog.js";
+import {dialog} from "./dialog.js";
window.addEventListener("DOMContentLoaded", init);
@@ -64,12 +64,9 @@ async function populateInstances () {
}
async function handleInstanceAdd () {
- let dialog = document.createElement("dialog-form");
- document.body.append(dialog);
-
- dialog.header = "Create New Instance";
+ let header = "Create New Instance";
- dialog.formBody = `
+ let body = `