diff --git a/scripts/elements.js b/scripts/elements.js index 5d26c91..3ffb592 100644 --- a/scripts/elements.js +++ b/scripts/elements.js @@ -1,4 +1,4 @@ -import { request } from "./utils.js"; +import {request, goToPage} from "./utils.js"; const waitFor = delay => new Promise(resolve => setTimeout(resolve, delay)); @@ -123,7 +123,11 @@ class Instance extends HTMLElement { let configButton = this.shadowElement.querySelector("#configure-btn"); configButton.src = data.status === "running" ? "images/actions/config-inactive.svg" : "images/actions/config-active.svg"; - configButton + configButton.addEventListener("click", () => { + if (!this.actionLock && this.status !== "running") { + goToPage("https://client.tronnet.net/config.html", {type: this.type, vmid: this.vmid}); + } + }) } } diff --git a/scripts/index.js b/scripts/index.js index 79df572..bdcd43d 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -1,4 +1,4 @@ -import {requestTicket, setTicket, request} from "./utils.js"; +import {request, goToPage} from "./utils.js"; window.addEventListener("DOMContentLoaded", init); @@ -9,7 +9,7 @@ async function init () { async function populateInstances () { let cookie = document.cookie; if (cookie === "") { - window.location.href = "login.html"; + goToPage("https://client.tronnet.net/login.html"); } let nodes = await request("/nodes", "GET", null); diff --git a/scripts/login.js b/scripts/login.js index 56bf9d4..40e1f22 100644 --- a/scripts/login.js +++ b/scripts/login.js @@ -14,7 +14,7 @@ function init (){ status.innerText = "Authenticating..."; let ticket = await requestTicket(formData.get("username"), formData.get("password")); setTicket(ticket.data.ticket, ticket.data.CSRFPreventionToken); - window.location.href = "index.html"; + goToPage("https://client.tronnet.net/index.html"); } catch (error) { if(error instanceof ResponseError) { // response error is usually 401 auth failed diff --git a/scripts/utils.js b/scripts/utils.js index b302b78..5ae8034 100644 --- a/scripts/utils.js +++ b/scripts/utils.js @@ -76,4 +76,12 @@ export async function request (path, method, body = null, auth = true) { let data = await response.json(); return data; +} + +export function goToPage (page, data={}) { + let url = new URL(url); + for(let k in data) { + url.searchParams.append(k, data[k]); + } + window.location.href = url.toString(); } \ No newline at end of file