]> code.citadel.org Git - citadel.git/blobdiff - webcit-ng/static/js/mail_folder_list.js
Grammar change in the license declaration.
[citadel.git] / webcit-ng / static / js / mail_folder_list.js
index 309f7894604445c93216f3d568eef61e62f9b2b4..fff055d749385c43b58541680d291b40130d4232 100644 (file)
@@ -3,7 +3,7 @@
 // Copyright (c) 2016-2023 by the citadel.org team
 //
 // This program is open source software.  Use, duplication, or
-// disclosure are subject to the GNU General Public License v3.
+// disclosure is subject to the GNU General Public License v3.
 
 
 // Display the mail folder list in the specified div
@@ -81,8 +81,40 @@ function mail_folder_dragleave(event) {
 }
 
 
+// Something has been dropped onto a folder.
 function mail_folder_drop(event, destination_room) {
        event.preventDefault();
-       console.log("mail_folder_drop(" + destination_room + ")");
        event.target.classList.toggle("ctdl_mail_folder_droppable", false);
+       var msgs = event.dataTransfer.getData("text").split(",");
+       for (var i=0; i<msgs.length; ++i) {
+               mail_move(msgs[i], destination_room);
+       }
+}
+
+
+// mail_folder_drop() calls this function for each message being moved
+mail_move = async(msgdivid, destination_room) => {
+       let msgdiv = document.getElementById(msgdivid);
+       let m = parseInt(msgdivid.substring(12));                               // derive msgnum from row id
+       let source = "/ctdl/r/" + escapeHTMLURI(current_room) + "/" + m;
+       let destination = "/ctdl/r/" + escapeHTMLURI(destination_room);
+
+       let response = await fetch(
+               source, {
+                       method: "MOVE",
+                       headers: {
+                               "Destination" : destination
+                       }
+               }
+       );
+
+       // If the server accepted the MOVE operation, delete the row from our screen.
+       if (response.ok) {
+               var table = document.getElementById("ctdl-onscreen-mailbox");
+               for (var i = 0, row; row = table.rows[i]; i++) {
+                       if (row.id == msgdivid) {
+                               table.deleteRow(i);
+                       }
+               }
+       }
 }