"/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
}
}
// 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>`
+ ` `
+ item["uploadfilename"] + " (" + item["contenttype"] + ", " + item["contentlength"] + " " + _("bytes") + ")";
}
+// Helper function for flush_uploads()
+flush_one_upload = async(ref) => {
+ response = await fetch(
+ "/ctdl/p/" + ref, { method: "DELETE" }
+ );
+ // We don't have any interest in the server response.
+}
+
+
// Flush all uploaded files and close the window
function flush_uploads() {
upload_window = document.getElementById('ctdl-upload');
upload_window.style.display='none';
}
- // FIXME tell the server to delete the files
+ // tell the server to delete the files
uploads.forEach(u => {
- console.log(u.ref);
+ flush_one_upload(u.ref);
});
uploads=[];
+ document.getElementById("num_attachments").innerHTML = uploads.length;
deactivate_uploads(); // this makes the window get destroyed too
}