aboutsummaryrefslogtreecommitdiffstats
path: root/src/public/js
diff options
context:
space:
mode:
authorMatt Strapp <matt@mattstrapp.net>2022-02-14 15:39:22 -0600
committerMatt Strapp <matt@mattstrapp.net>2022-02-14 15:39:22 -0600
commit150c06a1171be1ad965afc37beeec9863818b508 (patch)
treefbcb8dafdb12df640c10625f73639d43feba4e5a /src/public/js
parentBump eslint from 8.8.0 to 8.9.0 (#6) (diff)
downloadee4511w-web-150c06a1171be1ad965afc37beeec9863818b508.tar
ee4511w-web-150c06a1171be1ad965afc37beeec9863818b508.tar.gz
ee4511w-web-150c06a1171be1ad965afc37beeec9863818b508.tar.bz2
ee4511w-web-150c06a1171be1ad965afc37beeec9863818b508.tar.lz
ee4511w-web-150c06a1171be1ad965afc37beeec9863818b508.tar.xz
ee4511w-web-150c06a1171be1ad965afc37beeec9863818b508.tar.zst
ee4511w-web-150c06a1171be1ad965afc37beeec9863818b508.zip
maybe achieve feature parity
Signed-off-by: Matt Strapp <matt@mattstrapp.net>
Diffstat (limited to '')
-rw-r--r--src/public/js/form.js45
1 files changed, 42 insertions, 3 deletions
diff --git a/src/public/js/form.js b/src/public/js/form.js
index 7085422..f58a27f 100644
--- a/src/public/js/form.js
+++ b/src/public/js/form.js
@@ -1,5 +1,14 @@
+window.onload = function () {
+ document.getElementById('nojs').hidden = true;
+ document.getElementById('block').hidden = false;
+};
+
// File submit AJAX request
document.getElementById('upload').onsubmit = function () {
+ // Reset error message
+ document.getElementById('upload-err').innerText = '';
+ document.getElementById('actuate-err').innerText = '';
+ // Make AJAX request
let xhr = new XMLHttpRequest();
xhr.open('POST', '/api/v1/upload');
let formData = new FormData(this);
@@ -8,11 +17,41 @@ document.getElementById('upload').onsubmit = function () {
if (xhr.readyState === 4) {
let response = JSON.parse(xhr.responseText);
if (xhr.status === 200) {
- console.log(response);
+ actuate(response);
} else {
- console.log(response.error);
+ // Display upload error message to the user
+ document.getElementById('upload-err').innerText = response.error;
+ // DEBUG: Print full error if unknown error occurs
+ if (xhr.status === 500)
+ console.error(response.error_msg);
}
}
};
return false;
-}; \ No newline at end of file
+};
+
+function actuate(file) {
+ let xhr = new XMLHttpRequest();
+ xhr.open('POST', '/api/v1/actuate');
+ let data = {
+ name: file.name,
+ path: file.path,
+ };
+ xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
+ xhr.setRequestHeader('X-CSRF-TOKEN', file.csrf);
+ xhr.send(JSON.stringify(data));
+ xhr.onreadystatechange = function () {
+ if (xhr.readyState === 4) {
+ let response = JSON.parse(xhr.responseText);
+ if (xhr.status === 200) {
+ console.log(response);
+ } else {
+ // Display upload error message to the user
+ document.getElementById('actuate-err').innerText = response.error;
+ // DEBUG: Print full error if unknown error occurs
+ if (xhr.status === 500)
+ console.error(response.error_msg);
+ }
+ }
+ };
+} \ No newline at end of file