modularize redirect function
This commit is contained in:
parent
f5e360046d
commit
fe27bba986
@ -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});
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
Loading…
Reference in New Issue
Block a user