]> code.citadel.org Git - citadel.git/blobdiff - webcit-ng/static/js/upload.js
view_mail.js: remove upload from local array when deleted.
[citadel.git] / webcit-ng / static / js / upload.js
index 5541213724bc4044b88cd177202a4c6e652eb21b..257ff75624b31d7ff801fbffc21af4b6a803e259 100644 (file)
@@ -81,8 +81,11 @@ delete_upload = async(ref) => {
                "/ctdl/p/" + ref, { method: "DELETE" }
        );
 
-       if (response.ok) {                              // If the server accepted the delete, remove it from the screen
-               // FIXME do the delete
+       if (response.ok) {                                                                      // If the server accepted the delete...
+               var el = document.getElementById(ref);                                          // ...remove it from the screen...
+               el.parentNode.removeChild(el);
+               uploads = uploads.filter((r) => r.ref != ref);                                  // ...remove it from the array...
+               document.getElementById("num_attachments").innerHTML = uploads.length;          // ...and update our count
        }
 }
 
@@ -106,7 +109,7 @@ function upload_file(file) {
                        // Add these uploads to the displayed list
                        j_response.forEach((item) => {
                                let new_upl = document.createElement("li");
-                               // item["ref"] is what we need
+                               new_upl.setAttribute("id", item["ref"]);        // set the element id to the upload reference
                                new_upl.innerHTML = `<i class="fa-solid fa-circle-xmark" style="color:red" onClick="delete_upload('` + item["ref"] + `')"></i>`
                                + `&nbsp;`
                                + item["uploadfilename"] + " (" + item["contenttype"] + ", " + item["contentlength"] + " " + _("bytes") + ")";
@@ -187,6 +190,7 @@ function flush_uploads() {
                flush_one_upload(u.ref);
        });
         uploads=[];
+       document.getElementById("num_attachments").innerHTML = uploads.length;
 
        deactivate_uploads();   // this makes the window get destroyed too
 }