upload.js: moved the delete-an-attachment skeleton code to its own function
authorArt Cancro <ajc@citadel.org>
Thu, 9 Nov 2023 23:44:52 +0000 (13:44 -1000)
committerArt Cancro <ajc@citadel.org>
Thu, 9 Nov 2023 23:44:52 +0000 (13:44 -1000)
webcit-ng/static/js/upload.js

index 2d0751bafe0abfe382a103730e95b78560b9e7ad..ac72bbee8e8afc96f0ead6e61d499e767bd1201f 100644 (file)
@@ -74,6 +74,19 @@ function handle_upload_files(files) {
 }
 
 
+// Delete an uploaded item from the list
+delete_upload = async(ref) => {
+
+       response = await fetch(
+               "/ctdl/p/" + ref, { method: "DELETE" }
+       );
+
+       if (response.ok) {                              // If the server accepted the delete, remove it from the screen
+               // FIXME do the delete
+       }
+}
+
+
 function upload_file(file) {
        var url = '/ctdl/p/';
        var xhr = new XMLHttpRequest();
@@ -94,7 +107,7 @@ function upload_file(file) {
                        j_response.forEach((item) => {
                                let new_upl = document.createElement("li");
                                // item["ref"] is what we need
-                               new_upl.innerHTML = `<i class="fa-solid fa-circle-xmark" style="color:red" onClick="alert('` + item["ref"] + `')"></i>`
+                               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") + ")";
                                document.getElementById("ctdl-upload_list").appendChild(new_upl);