aboutsummaryrefslogtreecommitdiffstats
path: root/src/public
diff options
context:
space:
mode:
Diffstat (limited to 'src/public')
-rw-r--r--src/public/css/style.css4
-rw-r--r--src/public/js/form.js21
2 files changed, 21 insertions, 4 deletions
diff --git a/src/public/css/style.css b/src/public/css/style.css
index b1651df..a106926 100644
--- a/src/public/css/style.css
+++ b/src/public/css/style.css
@@ -28,7 +28,7 @@ p {
/* Used for id=button1 */
-#actuate_but {
+#actuate-but {
background-color: #0a3f73;
border: solid;
border-color: #d5d6d2;
@@ -45,7 +45,7 @@ p {
/* Used for id=button1 - What the button looks like when a user puts one's cursor on it */
-#actuate_but:hover {
+#actuate-but:hover {
background-color: white;
color: maroon;
cursor: pointer;
diff --git a/src/public/js/form.js b/src/public/js/form.js
index 581d5a3..3fbeb50 100644
--- a/src/public/js/form.js
+++ b/src/public/js/form.js
@@ -1,3 +1,5 @@
+// This is split into comments so it doesn't look as gross with the closure tabs
+
window.onload = function () {
document.getElementById('nojs').hidden = true;
document.getElementById('block').hidden = false;
@@ -10,6 +12,7 @@ document.getElementById('upload').onsubmit = function () {
document.getElementById('upload-err').innerText = '';
document.getElementById('actuate-err').innerText = '';
document.getElementById('upload-response').innerText = '';
+ document.getElementById('download-link').innerText = '';
// Make AJAX request
let xhr = new XMLHttpRequest();
xhr.open('POST', '/api/v1/upload');
@@ -43,8 +46,7 @@ function actuate(file) {
let xhr = new XMLHttpRequest();
xhr.open('POST', '/api/v1/actuate');
let data = {
- name: file.name,
- path: file.path,
+ file: file.file
};
xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
xhr.setRequestHeader('X-CSRF-TOKEN', file.csrf);
@@ -54,6 +56,7 @@ function actuate(file) {
let response = JSON.parse(xhr.responseText);
if (xhr.status === 200) {
console.log(response);
+ createDownload(response.file);
} else {
// Display upload error message to the user
document.getElementById('actuate-err').innerText = response.error;
@@ -61,6 +64,20 @@ function actuate(file) {
if (xhr.status === 500)
console.error(response.error_msg);
}
+ return;
}
};
+}
+
+
+// Creates the download element
+function createDownload(response) {
+ const tempName = response.filename;
+ const downloadName = response.name.split('.')[ 0 ];
+ const downloadLink = document.createElement('a');
+ downloadLink.setAttribute('href', `/api/v1/download/?filename=${tempName}`);
+ downloadLink.setAttribute('download', `${downloadName}.csv`);
+ downloadLink.innerText = 'Download CSV of results here.';
+ document.getElementById('download-link').appendChild(downloadLink);
+ return;
} \ No newline at end of file