Redesigned the user interface #23
This commit is contained in:
parent
f7048d1e9f
commit
d93591bcb2
32 changed files with 846 additions and 1297 deletions
|
@ -1,35 +1,23 @@
|
|||
document.addEventListener("DOMContentLoaded", () => {
|
||||
|
||||
// elements
|
||||
|
||||
let supplyDescriptionElement = document.getElementById("supplydescription");
|
||||
let supplyPriceElement = document.getElementById("supplyprice");
|
||||
|
||||
let supplyFormElement = document.getElementById("supplyform");
|
||||
let statusInfoElement = document.getElementById("statusinfo");
|
||||
let supplySubmitButton = document.getElementById("supplysubmitbtn");
|
||||
|
||||
// custom submit method
|
||||
|
||||
supplyFormElement.addEventListener("submit", (event) => {
|
||||
|
||||
supplySubmitButton.disabled = true;
|
||||
|
||||
event.preventDefault(); // Don't do the default submit action!
|
||||
|
||||
if (isNaN(parseFloat(supplyPriceElement.value)) || supplyDescriptionElement.value == "") {
|
||||
statusInfoElement.innerText = "Please enter a description and price."
|
||||
supplySubmitButton.disabled = false;
|
||||
}
|
||||
|
||||
let xhr = new XMLHttpRequest();
|
||||
let formData = new FormData(supplyFormElement);
|
||||
|
||||
xhr.addEventListener("load", (event) => {
|
||||
|
||||
status_ = event.target.status;
|
||||
response_ = event.target.responseText;
|
||||
|
||||
if (status_ == 200 && response_ == "success") {
|
||||
statusInfoElement.innerText = "Success.";
|
||||
window.location.replace("/");
|
||||
|
@ -39,18 +27,13 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||
statusInfoElement.innerText = "An error occured.";
|
||||
window.setTimeout(() => { window.location.reload() }, 5000);
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
xhr.addEventListener("error", (event) => {
|
||||
statusInfoElement.classList.add("errortext");
|
||||
statusInfoElement.innerText = "An error occured.";
|
||||
window.setTimeout(() => { window.location.reload() }, 5000);
|
||||
})
|
||||
|
||||
xhr.open("POST", "/api/supply");
|
||||
xhr.send(formData);
|
||||
|
||||
});
|
||||
|
||||
})
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue