diff options
author | Alex Vitkov <alexvitkov98@gmail.com> | 2021-02-12 15:36:38 +0200 |
---|---|---|
committer | Alex Vitkov <alexvitkov98@gmail.com> | 2021-02-12 15:36:38 +0200 |
commit | 34ba723e18a7ba0f785e456e38a9234d6efda9b7 (patch) | |
tree | 68b70f8c7768eec186edfc0c77c8dca334ae5404 /loggedin.js | |
parent | 9b29bb3deb3943dd101d7ab7b01f42ee49951e1b (diff) | |
download | fileup-34ba723e18a7ba0f785e456e38a9234d6efda9b7.tar.gz |
css
Diffstat (limited to 'loggedin.js')
-rw-r--r-- | loggedin.js | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/loggedin.js b/loggedin.js index b275c4a..d4f56ae 100644 --- a/loggedin.js +++ b/loggedin.js @@ -1,4 +1,4 @@ -var FORM_ASYNC = false; +var FORM_ASYNC = true; const upload_form = document.getElementById("upload_form"); const the_file = document.getElementById("the_file"); @@ -22,6 +22,12 @@ class FileView { } } +class PendingUpload { + constructor(fileview) { + this.fileview = fileview; + } +} + var files = []; function on_file_added(_e) { @@ -33,13 +39,15 @@ function on_file_added(_e) { return; } + var fileview = add_file_visuals(filename_input.value, false, "pending"); + // Send the form asynchronously through the fetch api fetch(upload_form.action, { method: upload_form.method, body: new FormData(upload_form) }).then((resp) => { if (resp.status == 200) { - add_file_visuals(filename_input.value, true); + done_upload(fileview); } else { alert("Upload failed"); @@ -47,13 +55,19 @@ function on_file_added(_e) { }, () => { alert("Upload failed") }); - - + + pending_uploads.push(fileview); } else { alert("No files selected"); } +} +function done_upload(fileview) { + var index = pending_uploads.indexOf(fileview); + if (index >= 0) + pending_uploads.splice(index, 1); + load_dir(pwd); } function load_dir(pwd) { @@ -92,6 +106,9 @@ function add_file_visuals(name, is_directory, mimetype) { filename.classList.add('filename'); filename.innerText = name; + if (mimetype == "pending") + fileDiv.classList.add('pending'); + fileDiv.appendChild(img); fileDiv.appendChild(filename); |