1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-22 17:10:10 +00:00

form: change contact-via radios to checks

This commit is contained in:
Harvey Tindall 2023-06-23 12:30:52 +01:00
parent c0f2409fcc
commit bfeab3648c
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
2 changed files with 63 additions and 64 deletions

View File

@ -85,21 +85,21 @@
{{ if or (.telegramEnabled) (or .discordEnabled .matrixEnabled) }} {{ if or (.telegramEnabled) (or .discordEnabled .matrixEnabled) }}
<div id="contact-via" class="unfocused"> <div id="contact-via" class="unfocused">
<label class="row switch pb-4 unfocused"> <label class="row switch pb-4 unfocused">
<input type="radio" name="contact-via" value="email" id="contact-via-email" class="mr-2"><span>Contact through Email</span> <input type="checkbox" name="contact-via" value="email" id="contact-via-email" class="mr-2"><span>Contact through Email</span>
</label> </label>
{{ if .telegramEnabled }} {{ if .telegramEnabled }}
<label class="row switch pb-4 unfocused"> <label class="row switch pb-4 unfocused">
<input type="radio" name="contact-via" value="telegram" id="contact-via-telegram" class="mr-2"><span>Contact through Telegram</span> <input type="checkbox" name="contact-via" value="telegram" id="contact-via-telegram" class="mr-2"><span>Contact through Telegram</span>
</label> </label>
{{ end }} {{ end }}
{{ if .discordEnabled }} {{ if .discordEnabled }}
<label class="row switch pb-4 unfocused"> <label class="row switch pb-4 unfocused">
<input type="radio" name="contact-via" value="discord" id="contact-via-discord" class="mr-2"><span>Contact through Discord</span> <input type="checkbox" name="contact-via" value="discord" id="contact-via-discord" class="mr-2"><span>Contact through Discord</span>
</label> </label>
{{ end }} {{ end }}
{{ if .matrixEnabled }} {{ if .matrixEnabled }}
<label class="row switch pb-4 unfocused"> <label class="row switch pb-4 unfocused">
<input type="radio" name="contact-via" value="matrix" id="contact-via-matrix" class="mr-2"><span>Contact through Matrix</span> <input type="checkbox" name="contact-via" value="matrix" id="contact-via-matrix" class="mr-2"><span>Contact through Matrix</span>
</label> </label>
{{ end }} {{ end }}
</div> </div>

View File

@ -67,9 +67,9 @@ if (window.telegramEnabled) {
telegramButton.classList.add("unfocused"); telegramButton.classList.add("unfocused");
document.getElementById("contact-via").classList.remove("unfocused"); document.getElementById("contact-via").classList.remove("unfocused");
document.getElementById("contact-via-email").parentElement.classList.remove("unfocused"); document.getElementById("contact-via-email").parentElement.classList.remove("unfocused");
const radio = document.getElementById("contact-via-telegram") as HTMLInputElement; const checkbox = document.getElementById("contact-via-telegram") as HTMLInputElement;
radio.parentElement.classList.remove("unfocused"); checkbox.parentElement.classList.remove("unfocused");
radio.checked = true; checkbox.checked = true;
validator.validate(); validator.validate();
} }
}; };
@ -99,9 +99,9 @@ if (window.discordEnabled) {
discordButton.classList.add("unfocused"); discordButton.classList.add("unfocused");
document.getElementById("contact-via").classList.remove("unfocused"); document.getElementById("contact-via").classList.remove("unfocused");
document.getElementById("contact-via-email").parentElement.classList.remove("unfocused"); document.getElementById("contact-via-email").parentElement.classList.remove("unfocused");
const radio = document.getElementById("contact-via-discord") as HTMLInputElement; const checkbox = document.getElementById("contact-via-discord") as HTMLInputElement;
radio.parentElement.classList.remove("unfocused") checkbox.parentElement.classList.remove("unfocused")
radio.checked = true; checkbox.checked = true;
validator.validate(); validator.validate();
} }
}; };
@ -131,9 +131,9 @@ if (window.matrixEnabled) {
matrixButton.classList.add("unfocused"); matrixButton.classList.add("unfocused");
document.getElementById("contact-via").classList.remove("unfocused"); document.getElementById("contact-via").classList.remove("unfocused");
document.getElementById("contact-via-email").parentElement.classList.remove("unfocused"); document.getElementById("contact-via-email").parentElement.classList.remove("unfocused");
const radio = document.getElementById("contact-via-matrix") as HTMLInputElement; const checkbox = document.getElementById("contact-via-matrix") as HTMLInputElement;
radio.parentElement.classList.remove("unfocused"); checkbox.parentElement.classList.remove("unfocused");
radio.checked = true; checkbox.checked = true;
validator.validate(); validator.validate();
} }
}; };
@ -298,7 +298,7 @@ const create = (event: SubmitEvent) => {
if (window.captcha && !window.reCAPTCHA && !captchaVerified) { if (window.captcha && !window.reCAPTCHA && !captchaVerified) {
} }
toggleLoader(submitSpan); addLoader(submitSpan);
let send: sendDTO = { let send: sendDTO = {
code: window.code, code: window.code,
username: usernameField.value, username: usernameField.value,
@ -307,22 +307,22 @@ const create = (event: SubmitEvent) => {
}; };
if (telegramVerified) { if (telegramVerified) {
send.telegram_pin = window.telegramPIN; send.telegram_pin = window.telegramPIN;
const radio = document.getElementById("contact-via-telegram") as HTMLInputElement; const checkbox = document.getElementById("contact-via-telegram") as HTMLInputElement;
if (radio.checked) { if (checkbox.checked) {
send.telegram_contact = true; send.telegram_contact = true;
} }
} }
if (discordVerified) { if (discordVerified) {
send.discord_pin = window.discordPIN; send.discord_pin = window.discordPIN;
const radio = document.getElementById("contact-via-discord") as HTMLInputElement; const checkbox = document.getElementById("contact-via-discord") as HTMLInputElement;
if (radio.checked) { if (checkbox.checked) {
send.discord_contact = true; send.discord_contact = true;
} }
} }
if (matrixVerified) { if (matrixVerified) {
send.matrix_pin = matrixPIN; send.matrix_pin = matrixPIN;
const radio = document.getElementById("contact-via-matrix") as HTMLInputElement; const checkbox = document.getElementById("contact-via-matrix") as HTMLInputElement;
if (radio.checked) { if (checkbox.checked) {
send.matrix_contact = true; send.matrix_contact = true;
} }
} }
@ -335,56 +335,55 @@ const create = (event: SubmitEvent) => {
} }
} }
_post("/newUser", send, (req: XMLHttpRequest) => { _post("/newUser", send, (req: XMLHttpRequest) => {
if (req.readyState == 4) { if (req.readyState != 4) return;
let vals = req.response as ValidatorRespDTO; removeLoader(submitSpan);
let valid = true; let vals = req.response as ValidatorRespDTO;
for (let type in vals) { let valid = true;
if (requirements[type]) requirements[type].valid = vals[type]; for (let type in vals) {
if (!vals[type]) valid = false; if (requirements[type]) requirements[type].valid = vals[type];
} if (!vals[type]) valid = false;
if (req.status == 200 && valid) { }
if (window.redirectToJellyfin == true) { if (req.status == 200 && valid) {
const url = ((document.getElementById("modal-success") as HTMLDivElement).querySelector("a.submit") as HTMLAnchorElement).href; if (window.redirectToJellyfin == true) {
window.location.href = url; const url = ((document.getElementById("modal-success") as HTMLDivElement).querySelector("a.submit") as HTMLAnchorElement).href;
} else { window.location.href = url;
if (window.userPageEnabled) {
const userPageNoticeArea = document.getElementById("modal-success-user-page-area");
const link = `<a href="${window.userPageAddress}" target="_blank">${userPageNoticeArea.getAttribute("my-account-term")}</a>`;
userPageNoticeArea.innerHTML = userPageNoticeArea.textContent.replace("{myAccount}", link);
}
window.successModal.show();
}
} else { } else {
submitSpan.classList.add("~critical"); if (window.userPageEnabled) {
submitSpan.classList.remove("~urge"); const userPageNoticeArea = document.getElementById("modal-success-user-page-area");
if (req.response["error"] as string) { const link = `<a href="${window.userPageAddress}" target="_blank">${userPageNoticeArea.getAttribute("my-account-term")}</a>`;
submitSpan.textContent = window.messages[req.response["error"]]; userPageNoticeArea.innerHTML = userPageNoticeArea.textContent.replace("{myAccount}", link);
} else {
submitSpan.textContent = window.messages["errorPassword"];
} }
setTimeout(() => { window.successModal.show();
submitSpan.classList.add("~urge");
submitSpan.classList.remove("~critical");
submitSpan.textContent = submitText;
}, 1000);
} }
} else if (req.status != 401 && req.status != 400){
submitSpan.classList.add("~critical");
submitSpan.classList.remove("~urge");
if (req.response["error"] as string) {
submitSpan.textContent = window.messages[req.response["error"]];
} else {
submitSpan.textContent = window.messages["errorPassword"];
}
setTimeout(() => {
submitSpan.classList.add("~urge");
submitSpan.classList.remove("~critical");
submitSpan.textContent = submitText;
}, 1000);
} }
}, true, (req: XMLHttpRequest) => { }, true, (req: XMLHttpRequest) => {
if (req.readyState == 4) { if (req.readyState != 4) return;
toggleLoader(submitSpan); removeLoader(submitSpan);
if (req.status == 401 || req.status == 400) { if (req.status == 401 || req.status == 400) {
if (req.response["error"] as string) { if (req.response["error"] as string) {
if (req.response["error"] == "confirmEmail") { if (req.response["error"] == "confirmEmail") {
window.confirmationModal.show(); window.confirmationModal.show();
return; return;
}
if (req.response["error"] in window.messages) {
submitSpan.textContent = window.messages[req.response["error"]];
} else {
submitSpan.textContent = req.response["error"];
}
setTimeout(() => { submitSpan.textContent = submitText; }, 1000);
} }
if (req.response["error"] in window.messages) {
submitSpan.textContent = window.messages[req.response["error"]];
} else {
submitSpan.textContent = req.response["error"];
}
setTimeout(() => { submitSpan.textContent = submitText; }, 1000);
} }
} }
}); });