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

remove hardcoded string from form.ts

This commit is contained in:
Harvey Tindall 2020-10-30 23:14:29 +00:00
parent d64d5c194f
commit 0f4e77364b
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2

View File

@ -41,15 +41,18 @@ var defaultPwValStrings: pwValStrings = {
} }
} }
const toggleSpinner = (): void => { const toggleSpinner = (ogText?: string): string => {
const submitButton = document.getElementById('submitButton') as HTMLButtonElement; const submitButton = document.getElementById('submitButton') as HTMLButtonElement;
if (document.getElementById('createAccountSpinner')) { if (document.getElementById('createAccountSpinner')) {
submitButton.innerHTML = `<span>Create Account</span>`; submitButton.innerHTML = ogText ? ogText : `<span>Create Account</span>`;
submitButton.disabled = false; submitButton.disabled = false;
return "";
} else { } else {
let ogText = submitButton.innerHTML;
submitButton.innerHTML = ` submitButton.innerHTML = `
<span id="createAccountSpinner" class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>Creating... <span id="createAccountSpinner" class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>Creating...
`; `;
return ogText;
} }
}; };
@ -84,7 +87,7 @@ var code = window.location.href.split('/').pop();
if (el) { if (el) {
el.remove(); el.remove();
} }
toggleSpinner(); const ogText = toggleSpinner();
let send: Object = serializeForm('accountForm'); let send: Object = serializeForm('accountForm');
send["code"] = code; send["code"] = code;
if (!window.usernameEnabled) { if (!window.usernameEnabled) {
@ -92,7 +95,7 @@ var code = window.location.href.split('/').pop();
} }
_post("/newUser", send, function (): void { _post("/newUser", send, function (): void {
if (this.readyState == 4) { if (this.readyState == 4) {
toggleSpinner(); toggleSpinner(ogText);
let data: Object = this.response; let data: Object = this.response;
const errorGiven = ("error" in data) const errorGiven = ("error" in data)
if (errorGiven || data["success"] === false) { if (errorGiven || data["success"] === false) {