view_mail.js: make the function names more consistent with webcit
authorArt Cancro <ajc@citadel.org>
Tue, 26 Sep 2023 03:47:52 +0000 (23:47 -0400)
committerArt Cancro <ajc@citadel.org>
Tue, 26 Sep 2023 03:47:52 +0000 (23:47 -0400)
(They were previously the same names used in the example, natch)
Also we're incrementing num_attachments

webcit-ng/static/js/view_mail.js

index 91180d9e62fd07818684c3475c00de0ad4fd5cd2..e63fff6d030aabd21596649005476842ca7aaf6d 100644 (file)
@@ -548,7 +548,7 @@ function activate_uploads(parent_div) {
                                <div id="drop-area" class="ctdl-upload-drop-area">
                                        <form class="my-form">
                                                <p>${_("Drop files here to upload")}</p>
-                                               <input type="file" id="fileElem" multiple accept="*/*" onChange="handleFiles(this.files)">
+                                               <input type="file" id="fileElem" multiple accept="*/*" onChange="handle_upload_files(this.files)">
                                        </form>
                                </div>
                        </div>
@@ -558,15 +558,15 @@ function activate_uploads(parent_div) {
                //let dropArea = document.getElementById("ctdl-upload");
                let dropArea = document.getElementById(parent_div);
                ;['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
-                       dropArea.addEventListener(eventName, preventDefaults, false)
+                       dropArea.addEventListener(eventName, upload_prevent_defaults, false)
                })
                ;["dragenter", "dragover"].forEach(eventName => {
-                       dropArea.addEventListener(eventName, highlight, false)
+                       dropArea.addEventListener(eventName, upload_highlight, false)
                })
                ;['dragleave', 'drop'].forEach(eventName => {
-                       dropArea.addEventListener(eventName, unhighlight, false)
+                       dropArea.addEventListener(eventName, upload_unhighlight, false)
                })
-               dropArea.addEventListener('drop', handleDrop, false);
+               dropArea.addEventListener('drop', upload_handle_drop, false);
 
                // make the modal smaller than the containing window but pretty big
                //document.getElementById("ctdl-upload").style.width =
@@ -577,25 +577,25 @@ function activate_uploads(parent_div) {
 
 
 // prevent drag and drop events from propagating up through the DOM
-function preventDefaults(e) {
+function upload_prevent_defaults(e) {
        e.preventDefault();
        e.stopPropagation();
 }
 
 
-function handleDrop(e) {
+function upload_handle_drop(e) {
        let dt = e.dataTransfer;
        let files = dt.files;
-       handleFiles(files);
+       handle_upload_files(files);
 }
 
 
-function handleFiles(files) {
-       ([...files]).forEach(uploadFile)
+function handle_upload_files(files) {
+       ([...files]).forEach(upload_file)
 }
 
 
-function uploadFile(file) {
+function upload_file(file) {
        var url = '/ctdl/a/upload';
        var xhr = new XMLHttpRequest();
        var formData = new FormData();
@@ -605,6 +605,7 @@ function uploadFile(file) {
                if (xhr.readyState == 4 && xhr.status == 200) {
                        document.getElementById("ctdl-upload_list").innerHTML += "<li>succeeeeed</li>";
                        console.log("upload succeeded");
+                       num_attachments += 1;
                }
                else if (xhr.readyState == 4 && xhr.status != 200) {
                        document.getElementById("ctdl-upload_list").innerHTML += "<li>EPIC FAIL</li>";
@@ -614,17 +615,18 @@ function uploadFile(file) {
  
        formData.append('file', file);
        xhr.send(formData);
+       console.log("uploading...");
 }
 
 
-function highlight(e) {
+function upload_highlight(e) {
        let dropArea = document.getElementById("ctdl-upload");
        dropArea.classList.add('highlight')
 
        document.getElementById("ctdl-upload").style.display = "block";         /* also make it appear */
 }
       
-function unhighlight(e) {
+function upload_unhighlight(e) {
        let dropArea = document.getElementById("ctdl-upload");
        dropArea.classList.remove('highlight')
 }