X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit-ng%2Fstatic%2Fjs%2Fupload.js;h=3f6a33519f4372f64f0102c0e3d1b3eda048577a;hb=d2c2d7a6285d47e5942fdfc610d4d07e356dc99e;hp=54713f5dd9c6493564aad330e6a0453d9b3d1911;hpb=05b61a4c3411f03872b249634f4d568b84ed7a82;p=citadel.git diff --git a/webcit-ng/static/js/upload.js b/webcit-ng/static/js/upload.js index 54713f5dd..3f6a33519 100644 --- a/webcit-ng/static/js/upload.js +++ b/webcit-ng/static/js/upload.js @@ -97,11 +97,25 @@ delete_upload = async(ref) => { el.parentNode.removeChild(el); uploads = uploads.filter((r) => r.ref != ref); // ...remove it from the array... update_attachment_count(); - // document.getElementById(attachment_counter_divs[0]).innerHTML = uploads.length; // ...and update our count } } +// When an upload (or reupload) is complete, call this function to add it to the on-screen attachments list. +function add_upload_to_displayed_list(item) { + let new_upl = document.createElement("li"); + new_upl.setAttribute("id", item["ref"]); // set the element id to the upload reference + new_upl.innerHTML = `` + + ` ` + + item["uploadfilename"] + " (" + item["contenttype"] + ", " + item["contentlength"] + " " + _("bytes") + ")"; + document.getElementById("ctdl-upload_list").appendChild(new_upl); + + // append it to the global list of uploads + uploads.push(item); + update_attachment_count(); +} + + function upload_file(file) { var url = '/ctdl/p/'; var xhr = new XMLHttpRequest(); @@ -119,19 +133,7 @@ function upload_file(file) { var j_response = JSON.parse(xhr.response); // Add these uploads to the displayed list - j_response.forEach((item) => { - let new_upl = document.createElement("li"); - new_upl.setAttribute("id", item["ref"]); // set the element id to the upload reference - new_upl.innerHTML = `` - + ` ` - + item["uploadfilename"] + " (" + item["contenttype"] + ", " + item["contentlength"] + " " + _("bytes") + ")"; - document.getElementById("ctdl-upload_list").appendChild(new_upl); - - // append it to the global list of uploads - uploads.push(item); - }); - update_attachment_count(); - // document.getElementById(attachment_counter_divs[0]).innerHTML = uploads.length; + j_response.forEach((item) => add_upload_to_displayed_list(item)); } else if (xhr.readyState == 4 && xhr.status != 200) { // remove the "uploading in progress" message (there was an error, so just let it disappear) @@ -204,7 +206,20 @@ function flush_uploads() { }); uploads=[]; update_attachment_count(); - // document.getElementById(attachment_counter_divs[0]).innerHTML = uploads.length; deactivate_uploads(); // this makes the window get destroyed too } + + +// Preload a forwarded message's attachments into the new copy currently being composed. +function forward_attachments(msgnum) { + fetch( + "/ctdl/p/" + msgnum, { method: "GET" } + ) + .then(response => response.json()) + .then(j => { + j.forEach((item) => { + add_upload_to_displayed_list(item); + }) + }) +}