all repos — felt @ b8994d80a976013648e028c851160ddfa94d42b5

virtual tabletop for dungeons and dragons (and similar) using Go, MongoDB, and websockets

UI stuff; save and load username in cookie
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAmPxmY4ACgkQO3+8IhRO
Y5hNRg/+IPoTKPFKoILiQYnCYD5s01S6xftGkG0D8oMGPbytKkbV27GzeSke//J/
9cTNHm23AR5AcwpTBRGGOtlC08aixNq6cqxFPAe+19RgHti6UzNYWnNJGtzC5Qzv
l7Xq1tbrtvxPV41+wBHwhF/IxEBU7G/mcRhX386hPe+6B8vCVwQOY9QEhFJL8Uor
HJxRChbXzwtqHG4lUzrzClGKMYsHHkJ3n7bJn6ZfQ6A5QpmHhdN4rWl30+T6aBne
+dr7KNO0j4Sk1hViAhd+djAhtQAyqevmFg5nTsYWwa37GbyBQwfpOV+2lH/CEx7G
pYT5AqniyVS4UK7Gl+hdX3aTvT4pvTjXzhJ1DLNm/c+fjQsVf+7Iq0sVolVPO0CS
vyspW6MDs8ehSvtzczqvcDbrUUiEIVltrX+iQc58pROEDXHiVFEzJ2CHt+3zDVs2
LU8e05aBm9MhpCaAaC/Lcc2Vu8HQd8ncGhELu9Haj56hjZjucUP0fomqzKKGOL9V
jy5ZWAPVog7BTp2KGfjng/Yx8C1HAxtDIST64XrWnuy1SAVkFu0T8ncN1DF3kdEA
y+ijJ1FYtMm7Cp1RTKNC3aSp3TuH91GtkSVkrw/xuR44X0JZAJhFEs9DTdtfFeMZ
F6bCKDtcpxzYoPXdQMuNE0WiGeDEar66p4wFVM1+mSnpYyzDw4c=
=sQSB
-----END PGP SIGNATURE-----
commit

b8994d80a976013648e028c851160ddfa94d42b5

parent

849c27b7cf23ad0a417941c508f4fb6b402f51b8

4 files changed, 42 insertions(+), 11 deletions(-)

jump to
M static/admin.jsstatic/admin.js

@@ -55,7 +55,7 @@ }

} async function doLogin() { - const adminUsrInput = document.getElementById("input_admin_usr"); + const adminUsrInput = document.getElementById("name_entry"); const adminPassInput = document.getElementById("input_admin_pass"); if (adminUsrInput && adminPassInput) {

@@ -66,6 +66,13 @@ getTables();

} else { setErr("Incorrect credentials"); } + } +} + +function showAdminModal(show) { + const modal = document.getElementById("admin_modal") + if (modal) { + modal.style.display = show ? "block" : "none"; } }
M static/index.htmlstatic/index.html

@@ -5,24 +5,22 @@ <meta charset="UTF-8" />

<title>Felt</title> <meta name="viewport" content="width=device-width" /> <link href="./style.css" rel="stylesheet" /> - </head> <body> <div id="errWrapper" style='display:none'><button id="closeErr" onclick="closeErr()">x</button><div id="errDiv"></div></div> <nav> - <input id="name_entry"> - <button id="goto_table">Join Table</button> - <button id="admin_login">Admin Login</button> + <input id="name_entry" onblur="saveName()"> + <button id="goto_table" onclick="showAdminModal(false);showTableModal(true)">Join Table</button> + <button id="admin_login" onclick="showTableModal(false);showAdminModal(true)">Admin Login</button> </nav> - <form id="table_modal" onsubmit="return false"> + <form id="table_modal" onsubmit="return false" style="display:none;"> <label>Table Name<input id="input_table_name"></label> <label>Table Passcode<input id="input_table_pass"></label> - <button type="submit" id="table_join" onclick="dial()">Join</button> + <button type="submit" id="table_join" onclick="dial();showTableModal(false);">Join</button> </form> - <form id="admin_modal" onsubmit="return false"> - <label>usr<input id="input_admin_usr"></label> + <form id="admin_modal" onsubmit="return false" style="display:none;"> <label>pass<input type="password" id="input_admin_pass"></label> - <button type="submit" id="admin_login" onclick="doLogin()">login</button> + <button type="submit" id="admin_login" onclick="doLogin();showAdminModal(false)">login</button> </form> <div id="dice_log"></div> <select id="num_dice">
M static/socket.jsstatic/socket.js

@@ -7,6 +7,13 @@ let table = null;

let conn = null; +function showTableModal(show) { + const modal = document.getElementById("table_modal"); + if (modal) { + modal.style.display = show ? "block" : "none"; + } +} + function dial() { // get tableKey from UI const tblNameInput = document.getElementById("input_table_name");
M static/util.jsstatic/util.js

@@ -14,4 +14,23 @@ function closeErr() {

if (errWrapper) { errWrapper.style.display = "none"; } -}+} + +function saveName() { + const username = document.getElementById("name_entry"); + if (username) { + document.cookie = "username=" + username.value; + } +} + +function loadName() { + const username = document.getElementById("name_entry"); + if (username) { + const cookies = document.cookie.split(";") + if (cookies[0].trim().startsWith("username=")) { + username.value = cookies[0].trim().split("=")[1]; + } + } +} + +loadName();