diff --git a/static/submit.js b/static/submit.js new file mode 100644 index 0000000..f4674fe --- /dev/null +++ b/static/submit.js @@ -0,0 +1,58 @@ +function submitForm(){ + + /* check input fields */ + nameField = document.getElementById("name") + passwordField = document.getElementById("password") + + nameField.style.borderColor = "gray" + passwordField.style.borderColor = "gray" + + invalidField = false + if(nameField.value == ""){ + nameField.style.borderWidth = "2px" + nameField.style.borderColor = "red" + invalidField = true + } + + if(passwordField.value == ""){ + passwordField.style.borderWidth = "2px" + passwordField.style.borderColor = "red" + invalidField = true + } + + if(invalidField){ + return + } + + /* show the waiting dialog + dialog = document.getElementById("waiting-dialog") + dialog.style.disply = "block" + setMainBackgroundOpacity(0.5) + */ + + /* submit the form */ + xhr = new XMLHttpRequest(); + xhr.open("POST", "/create-user"); + xhr.onload = formSubmitFinished + formData = new FormData(document.getElementById("user-form")); + xhr.send(formData); +} + +function formSubmitFinished(event){ + if(event.target.status < 200 || event.target.status >= 300){ + showErrorMessage(event.target); // blocking + }else{ + window.location.href = event.target.responseText + } +} + +/* +function setMainBackgroundOpacity(opacity){ + mainContainer = document.getElementById("main-container") + mainContainer.style.opacity = opacity +} +*/ + +function showErrorMessage(target){ + alert(target.responseText) +}