Don't send the rendered list to the console anymore.
[citadel.git] / webcit-ng / static / js / mail_folder_list.js
1 // Display the mail folder list
2 //
3 // Copyright (c) 2016-2023 by the citadel.org team
4 //
5 // This program is open source software.  Use, duplication, or
6 // disclosure are subject to the GNU General Public License v3.
7
8
9 // Display the mail folder list in the specified div
10 function display_mail_folder_list(target_div) {
11
12         display_mail_folder_list_async = async(target_div) => {
13                 let rendered_list = "hi from display_mail_folder_list_async()";
14
15                 // load the room list from the Citadel Server
16                 response = await fetch("/ctdl/r/", { method: "GET" } );
17                 if (response.ok) {
18                         roomlist = await response.json();
19                         rendered_list = render_mail_folder_list(roomlist);
20                 }
21                 else {
22                         rendered_list = "❌ " + response.status;
23                 }
24
25                 document.getElementById(target_div).innerHTML = rendered_list;
26         }
27
28         document.getElementById(target_div).innerHTML = "<img src=\"/ctdl/s/images/throbber.gif\" />";  // show throbber
29         document.getElementById(target_div).style.display = "block";
30         display_mail_folder_list_async(target_div);
31 }
32
33
34 // Given a JSON object containing the output of the `/ctdl/r` API call, return a rendered mail folder list.
35 function render_mail_folder_list(roomlist_json) {
36
37         // Sort first by floor then by room order
38         roomlist_json.sort(function(a, b) {
39                 if (a.floor > b.floor) return 1;
40                 if (a.floor < b.floor) return -1;
41                 if (a.name == "Mail") return -1;
42                 if (b.name == "Mail") return 1;
43                 if (a.rorder > b.rorder) return 1;
44                 if (a.rorder < b.rorder) return -1;
45                 return 0;
46         });
47
48         // Turn it into displayable markup
49         let rendered_list = "";
50         rendered_list += "<ul class=\"ctdl_mail_folders\">\n";
51         for (let i=0; i<roomlist_json.length; ++i) {
52                 if (roomlist_json[i].current_view == views.VIEW_MAILBOX) {
53                         rendered_list += "<li "
54                                         + "onmouseup=\"mail_mouseup('" + roomlist_json[i].name + "');\" "
55                                         + "onClick=\"gotoroom('" + roomlist_json[i].name + "');\">"
56                                         + ((roomlist_json[i].name == "Mail") ? _("INBOX") : escapeHTML(roomlist_json[i].name))
57                                         + "</li>\n"
58                         ;
59                 }
60         }
61         rendered_list += "</ul>";
62         return rendered_list;
63 }
64
65
66 // The user released the mouse button over a folder name -- this is probably a drop event
67 function mail_mouseup(roomname) {
68         console.log("mail_mouseup " + roomname);
69
70         // todo:
71         // 1. First check to see if a drag operation is in progress.  Exit if there is no such case.
72         // 2. Perform the MOVE operation on the selected rows.
73
74 }
75