From 45b0de26c78725720f03fa5d4c8b5c5676d0fd1b Mon Sep 17 00:00:00 2001 From: Izalia Mae Date: Fri, 21 Jun 2024 04:44:13 -0400 Subject: [PATCH] add ability to submit forms with enter key --- relay/frontend/static/api.js | 1 - relay/frontend/static/config.js | 12 ++++++++++++ relay/frontend/static/domain_ban.js | 8 ++++++++ relay/frontend/static/instance.js | 8 ++++++++ relay/frontend/static/login.js | 25 +++++++++++++++++++------ relay/frontend/static/software_ban.js | 16 ++++++++++++++++ relay/frontend/static/user.js | 8 ++++++++ relay/frontend/static/whitelist.js | 6 ++++++ 8 files changed, 77 insertions(+), 7 deletions(-) diff --git a/relay/frontend/static/api.js b/relay/frontend/static/api.js index e7f376a..6aaefd7 100644 --- a/relay/frontend/static/api.js +++ b/relay/frontend/static/api.js @@ -123,7 +123,6 @@ async function request(method, path, body = null) { } else { if (Object.hasOwn(message, "created")) { - console.log(message.created) message.created = new Date(message.created); } } diff --git a/relay/frontend/static/config.js b/relay/frontend/static/config.js index 417c48a..612f4f3 100644 --- a/relay/frontend/static/config.js +++ b/relay/frontend/static/config.js @@ -35,6 +35,18 @@ async function handle_config_change(event) { } +document.querySelector("#name").addEventListener("keydown", async (event) => { + if (event.which === 13) { + await handle_config_change(event); + } +}); + +document.querySelector("#note").addEventListener("keydown", async (event) => { + if (event.which === 13 && event.ctrlKey) { + await handle_config_change(event); + } +}); + for (const elem of elems) { elem.addEventListener("change", handle_config_change); } diff --git a/relay/frontend/static/domain_ban.js b/relay/frontend/static/domain_ban.js index 4de2ebf..cdffbd3 100644 --- a/relay/frontend/static/domain_ban.js +++ b/relay/frontend/static/domain_ban.js @@ -114,6 +114,14 @@ document.querySelector("#new-ban").addEventListener("click", async (event) => { await ban(); }); +for (var elem of document.querySelectorAll("#add-item input")) { + elem.addEventListener("keydown", async (event) => { + if (event.which === 13) { + await ban(); + } + }); +} + for (var row of document.querySelector("fieldset.section table").rows) { if (!row.querySelector(".update-ban")) { continue; diff --git a/relay/frontend/static/instance.js b/relay/frontend/static/instance.js index a07b647..9519ebc 100644 --- a/relay/frontend/static/instance.js +++ b/relay/frontend/static/instance.js @@ -126,6 +126,14 @@ document.querySelector("#add-instance").addEventListener("click", async (event) await add_instance(); }) +for (var elem of document.querySelectorAll("#add-item input")) { + elem.addEventListener("keydown", async (event) => { + if (event.which === 13) { + await add_instance(); + } + }); +} + for (var row of document.querySelector("#instances").rows) { if (!row.querySelector(".remove a")) { continue; diff --git a/relay/frontend/static/login.js b/relay/frontend/static/login.js index 9c68f17..c61a7f4 100644 --- a/relay/frontend/static/login.js +++ b/relay/frontend/static/login.js @@ -1,10 +1,10 @@ -async function login(event) { - fields = { - username: document.querySelector("#username"), - password: document.querySelector("#password") - } +const fields = { + username: document.querySelector("#username"), + password: document.querySelector("#password") +} - values = { +async function login(event) { + const values = { username: fields.username.value.trim(), password: fields.password.value.trim() } @@ -26,4 +26,17 @@ async function login(event) { } +document.querySelector("#username").addEventListener("keydown", async (event) => { + if (event.which === 13) { + fields.password.focus(); + fields.password.select(); + } +}); + +document.querySelector("#password").addEventListener("keydown", async (event) => { + if (event.which === 13) { + await login(event); + } +}); + document.querySelector(".submit").addEventListener("click", login); diff --git a/relay/frontend/static/software_ban.js b/relay/frontend/static/software_ban.js index 663929a..bb54dbe 100644 --- a/relay/frontend/static/software_ban.js +++ b/relay/frontend/static/software_ban.js @@ -113,6 +113,22 @@ document.querySelector("#new-ban").addEventListener("click", async (event) => { await ban(); }); +for (var elem of document.querySelectorAll("#add-item input")) { + elem.addEventListener("keydown", async (event) => { + if (event.which === 13) { + await ban(); + } + }); +} + +for (var elem of document.querySelectorAll("#add-item textarea")) { + elem.addEventListener("keydown", async (event) => { + if (event.which === 13 && event.ctrlKey) { + await ban(); + } + }); +} + for (var row of document.querySelector("#bans").rows) { if (!row.querySelector(".update-ban")) { continue; diff --git a/relay/frontend/static/user.js b/relay/frontend/static/user.js index 9c74359..5bc16ec 100644 --- a/relay/frontend/static/user.js +++ b/relay/frontend/static/user.js @@ -76,6 +76,14 @@ document.querySelector("#new-user").addEventListener("click", async (event) => { await add_user(); }); +for (var elem of document.querySelectorAll("#add-item input")) { + elem.addEventListener("keydown", async (event) => { + if (event.which === 13) { + await add_user(); + } + }); +} + for (var row of document.querySelector("#users").rows) { if (!row.querySelector(".remove a")) { continue; diff --git a/relay/frontend/static/whitelist.js b/relay/frontend/static/whitelist.js index 70d4db1..c2b31e4 100644 --- a/relay/frontend/static/whitelist.js +++ b/relay/frontend/static/whitelist.js @@ -55,6 +55,12 @@ document.querySelector("#new-item").addEventListener("click", async (event) => { await add_whitelist(); }); +document.querySelector("#add-item").addEventListener("keydown", async (event) => { + if (event.which === 13) { + await add_whitelist(); + } +}); + for (var row of document.querySelector("fieldset.section table").rows) { if (!row.querySelector(".remove a")) { continue;