From 4cfd550a4763b9363aa6099818b20db737b231bf Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Sat, 17 Dec 2022 16:37:26 -0800 Subject: [PATCH] update power action button in element updater --- scripts/elements.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/elements.js b/scripts/elements.js index a9e01ac..3d62475 100644 --- a/scripts/elements.js +++ b/scripts/elements.js @@ -63,7 +63,9 @@ class Instance extends HTMLElement { powerButton.addEventListener("click", async () => { let targetAction = this.status === "running" ? "shutdown" : "start"; let targetStatus = this.status === "running" ? "stopped" : "running"; + await request(`/nodes/${this.node}/${this.type}/${this.vmid}/status/${targetAction}`, "POST", {node: this.node, vmid: this.vmid}); + while (true) { let data = await request(`/nodes/${this.node}/${this.type}/${this.vmid}/status/current`); console.log(data); @@ -72,9 +74,14 @@ class Instance extends HTMLElement { } await waitFor(1000); } + this.status = targetStatus; + let typeImg = this.shadowElement.querySelector("#instance-type"); typeImg.src = `images/instances/${this.type}/${this.status}.svg`; + + let powerButton = this.shadowElement.querySelector("#power-btn"); + powerButton.src = this.status === "running" ? "images/actions/stop.svg" : "images/actions/start.svg"; }); let configButton = this.shadowElement.querySelector("#configure-btn");