mirror of
https://github.com/FAUSheppy/jeffrey_miller_flask_ftp
synced 2025-12-06 13:41:36 +01:00
68 lines
1.7 KiB
JavaScript
68 lines
1.7 KiB
JavaScript
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 deleteUser(username){
|
|
xhr = new XMLHttpRequest();
|
|
xhr.open("POST", "/delete-user");
|
|
xhr.onload = formSubmitFinished
|
|
formData = new FormData();
|
|
formData.append("username", username)
|
|
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 + "?code=0"
|
|
}
|
|
}
|
|
|
|
/*
|
|
function setMainBackgroundOpacity(opacity){
|
|
mainContainer = document.getElementById("main-container")
|
|
mainContainer.style.opacity = opacity
|
|
}
|
|
*/
|
|
|
|
function showErrorMessage(target){
|
|
alert(target.responseText)
|
|
}
|