2022-03-16 12:11:30 +01:00
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
|
|
|
|
|
|
// elements
|
|
|
|
|
2022-11-04 20:35:28 +01:00
|
|
|
let depositForm = document.getElementById("depositform");
|
|
|
|
let statusInfo = document.getElementById("statusinfo");
|
|
|
|
let depositSubmitButton = document.getElementById("depositsubmitbtn");
|
2022-03-16 12:11:30 +01:00
|
|
|
|
|
|
|
// event listener for deposit form
|
|
|
|
// this implements a custom submit method
|
|
|
|
|
2022-11-04 20:35:28 +01:00
|
|
|
depositForm.addEventListener("submit", (event) => {
|
2022-03-16 12:11:30 +01:00
|
|
|
|
2022-11-04 20:35:28 +01:00
|
|
|
depositSubmitButton.disabled = true;
|
2022-03-16 12:11:30 +01:00
|
|
|
|
|
|
|
event.preventDefault(); // Don't do the default submit action!
|
|
|
|
|
|
|
|
let xhr = new XMLHttpRequest();
|
2022-11-04 20:35:28 +01:00
|
|
|
let formData = new FormData(depositForm);
|
2022-03-16 12:11:30 +01:00
|
|
|
|
|
|
|
xhr.addEventListener("load", (event) => {
|
|
|
|
|
|
|
|
status_ = event.target.status;
|
|
|
|
response_ = event.target.responseText;
|
|
|
|
|
|
|
|
if (status_ == 200 && response_ == "success") {
|
2022-11-04 20:35:28 +01:00
|
|
|
statusInfo.innerText = "Success. Redirecting soon.";
|
2022-03-16 12:11:30 +01:00
|
|
|
window.location.replace("/");
|
|
|
|
}
|
|
|
|
else {
|
2022-11-04 20:35:28 +01:00
|
|
|
statusInfo.classList.add("errortext");
|
|
|
|
statusInfo.innerText = "An error occured. Redirecting in 5 seconds...";
|
2022-03-16 12:11:30 +01:00
|
|
|
window.setTimeout(() => { window.location.replace("/") }, 5000);
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
xhr.addEventListener("error", (event) => {
|
2022-11-04 20:35:28 +01:00
|
|
|
statusInfo.classList.add("errortext");
|
|
|
|
statusInfo.innerText = "An error occured. Redirecting in 5 seconds...";
|
2022-03-16 12:11:30 +01:00
|
|
|
window.setTimeout(() => { window.location.replace("/") }, 5000);
|
|
|
|
})
|
|
|
|
|
|
|
|
xhr.open("POST", "/api/deposit");
|
|
|
|
xhr.send(formData);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
})
|