This completes the effort to server-side-preload the attachments from
the original message. They appear as attachments in the forwarded copy
of the message in the composer, using the same API. A lot of effort
went into making the 'attach' and 'forward attachments' functions DRY
with respect to each other.
el.parentNode.removeChild(el);
uploads = uploads.filter((r) => r.ref != ref); // ...remove it from the array...
update_attachment_count();
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 = `<i class="fa-solid fa-circle-xmark" style="color:red" onClick="delete_upload('` + item["ref"] + `')"></i>`
+ + ` `
+ + 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();
function upload_file(file) {
var url = '/ctdl/p/';
var xhr = new XMLHttpRequest();
var j_response = JSON.parse(xhr.response);
// Add these uploads to the displayed list
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 = `<i class="fa-solid fa-circle-xmark" style="color:red" onClick="delete_upload('` + item["ref"] + `')"></i>`
- + ` `
- + 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)
}
else if (xhr.readyState == 4 && xhr.status != 200) {
// remove the "uploading in progress" message (there was an error, so just let it disappear)
});
uploads=[];
update_attachment_count();
});
uploads=[];
update_attachment_count();
- // document.getElementById(attachment_counter_divs[0]).innerHTML = uploads.length;
deactivate_uploads(); // this makes the window get destroyed too
}
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);
+ })
+ })
+}
if (is_quoted) {
mail_display_message(quoted_msgnum, document.getElementById(quoted_div_name), 0);
}
if (is_quoted) {
mail_display_message(quoted_msgnum, document.getElementById(quoted_div_name), 0);
}
+
+ // If this is a forwarded messages, preload its attachments into the forwarded copy.
- console.log("FIXME we have to load the attachments from message " + quoted_msgnum);
+ forward_attachments(quoted_msgnum);