From 3f3ab52a09cc60346bcf45e46cc93513d209dc2c Mon Sep 17 00:00:00 2001 From: starnakin Date: Mon, 27 Nov 2023 19:11:15 +0100 Subject: [PATCH] use post init to onclick --- .../static/js/views/accounts/LoginView.js | 22 ++++++++++++------- .../static/js/views/accounts/RegisterView.js | 12 +++++----- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/frontend/static/js/views/accounts/LoginView.js b/frontend/static/js/views/accounts/LoginView.js index ce3df84..e545358 100644 --- a/frontend/static/js/views/accounts/LoginView.js +++ b/frontend/static/js/views/accounts/LoginView.js @@ -1,5 +1,5 @@ import AbstractView from "../AbstractView.js"; -import { client } from "../../index.js"; +import { client, navigateTo } from "../../index.js"; async function login() { @@ -8,7 +8,13 @@ async function login() let response = await client.login(username, password); let response_data = await response.json(); - + + if (response_data == "user connected") + { + navigateTo("/home"); + return; + } + ["username", "user", "password"].forEach(error_field => { let error_display = document.getElementById(`error_${error_field}`); if (error_display != null) @@ -26,11 +32,11 @@ export default class extends AbstractView { constructor(params) { super(params); this.setTitle("Login"); - document.body.addEventListener("click", e => { - e.preventDefault(); - if (e.target.type == "button") - login(); - }); + } + + async postInit() + { + document.getElementById("button").onclick = login; } async getHtml() { @@ -42,7 +48,7 @@ export default class extends AbstractView { - + Register diff --git a/frontend/static/js/views/accounts/RegisterView.js b/frontend/static/js/views/accounts/RegisterView.js index d048321..e5c7c1f 100644 --- a/frontend/static/js/views/accounts/RegisterView.js +++ b/frontend/static/js/views/accounts/RegisterView.js @@ -26,11 +26,11 @@ export default class extends AbstractView { constructor(params) { super(params); this.setTitle("register"); - document.body.addEventListener("click", e => { - e.preventDefault(); - if (e.target.type == "button") - register(); - }); + } + + async postInit() + { + document.getElementById("button").onclick = register; } async getHtml() { @@ -42,7 +42,7 @@ export default class extends AbstractView { - + Login