summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
6653346)
Actually it's an array of strings, and the upload module will
update every div stored in there with the attachment count.
var uploads_in_progress = 0;
var uploads = [] ; // everything the user has uploaded
var uploads_in_progress = 0;
var uploads = [] ; // everything the user has uploaded
+var attachment_counter_divs = [] ; // list of divs containing attachment counters
// Remove the upload window completely (even if it's hidden)
function deactivate_uploads() {
// Remove the upload window completely (even if it's hidden)
function deactivate_uploads() {
// Turn the specified div into a place where we can upload. (Note: permanently changes the drag-and-drop behavior of that div.)
function activate_uploads(parent_div) {
// Turn the specified div into a place where we can upload. (Note: permanently changes the drag-and-drop behavior of that div.)
function activate_uploads(parent_div) {
+
+ attachment_counter_divs = [ "num_attachments" ] ;
+
document.getElementById(parent_div).innerHTML += `
<div class="ctdl-upload" id="ctdl-upload">
<div id="ctdl_attachments_title" class="ctdl-compose-attachments-title">
document.getElementById(parent_div).innerHTML += `
<div class="ctdl-upload" id="ctdl-upload">
<div id="ctdl_attachments_title" class="ctdl-compose-attachments-title">
- <div><h1><i class="fa fa-paperclip" style="color:grey"></i>` + _("Attachments:") + ` <span id="num_attachments">` + uploads.length + `</span></h1></div>
+ <div><h1><i class="fa fa-paperclip" style="color:grey"></i>` + _("Attachments:") + ` <span id="${attachment_counter_divs[0]}">` + uploads.length + `</span></h1></div>
<div><h1><i class="fas fa-window-close" style="color:red" onClick="show_or_hide_upload_window()"></i></h1></div>
</div>
<br>
<div><h1><i class="fas fa-window-close" style="color:red" onClick="show_or_hide_upload_window()"></i></h1></div>
</div>
<br>
+// update the attachment counter div(s) with the current number of items
+function update_attachment_count() {
+ for (let i = 0; i < attachment_counter_divs.length; ++i) {
+ document.getElementById(attachment_counter_divs[i]).innerHTML = uploads.length;
+ }
+}
+
+
// Delete an uploaded item from the list
delete_upload = async(ref) => {
// Delete an uploaded item from the list
delete_upload = async(ref) => {
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...
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
+ update_attachment_count();
+ // document.getElementById(attachment_counter_divs[0]).innerHTML = uploads.length; // ...and update our count
// append it to the global list of uploads
uploads.push(item);
});
// append it to the global list of uploads
uploads.push(item);
});
- document.getElementById("num_attachments").innerHTML = uploads.length;
+ update_attachment_count();
+ // document.getElementById(attachment_counter_divs[0]).innerHTML = uploads.length;
}
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)
let dropArea = document.getElementById("ctdl-upload");
dropArea.classList.add('highlight')
let dropArea = document.getElementById("ctdl-upload");
dropArea.classList.add('highlight')
- document.getElementById("ctdl-upload").style.display = "block"; /* also make it appear */
+ document.getElementById("ctdl-upload").style.display = "block"; // also make it appear
function show_or_hide_upload_window() {
if (document.getElementById("ctdl-upload").style.display == "block") {
function show_or_hide_upload_window() {
if (document.getElementById("ctdl-upload").style.display == "block") {
- document.getElementById("ctdl-upload").style.display = "none"; /* turn it off */
+ document.getElementById("ctdl-upload").style.display = "none"; // turn it off
- document.getElementById("ctdl-upload").style.display = "block"; /* turn it on */
+ document.getElementById("ctdl-upload").style.display = "block"; // turn it on
flush_one_upload(u.ref);
});
uploads=[];
flush_one_upload(u.ref);
});
uploads=[];
- document.getElementById("num_attachments").innerHTML = uploads.length;
+ 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
}