]> code.citadel.org Git - citadel.git/blob - webcit-ng/static/js/view_mail.js
Rendering a single row in a mailbox now has its own function
[citadel.git] / webcit-ng / static / js / view_mail.js
1 // Copyright (c) 2016-2022 by the citadel.org team
2 //
3 // This program is open source software.  Use, duplication, or
4 // disclosure are subject to the GNU General Public License v3.
5
6
7 // A message has been selected...
8 function select_message(msgnum) {
9         reading_pane = document.getElementById("ctdl-reading-pane").innerHTML = "message selected " + msgnum ;
10 }
11
12
13 // render one row in the mailbox table (this could be called from one of several places)
14 function mail_render_row(msg) {
15         row     = "<tr "
16                 + "id=\"ctdl-msgsum-" + msg["msgnum"] + "\""
17                 + "onClick=\"select_message(" + msg["msgnum"] + ")\""
18                 + ">"
19                 + "<td>" + msg["subject"] + "</td>"
20                 + "<td>" + msg["author"] + " &lt;" + msg["addr"] + "&gt;</td>"
21                 + "<td>" + convertTimestamp(msg["time"]) + "</td>"
22                 + "<td>" + msg["msgnum"] + "</td>"
23                 + "</tr>";
24         return(row);
25 }
26
27
28 // Set up the mailbox view
29 function mail_display() {
30         target_div = document.getElementById("ctdl-main");
31         target_div.innerHTML = "<div id=\"ctdl-mailbox-pane\">mailbox pane</div><div id=\"ctdl-reading-pane\">reading pane</div>";
32         mailbox_pane = document.getElementById("ctdl-mailbox-pane");
33         reading_pane = document.getElementById("ctdl-reading-pane");
34
35         activate_loading_modal();
36         url = "/ctdl/r/" + escapeHTMLURI(current_room) + "/mailbox";
37         fetch_mailbox = async() => {
38                 response = await fetch(url);
39                 msgs = await(response.json());
40                 if (response.ok) {
41
42                         box =   "<table class=\"w3-table-all\" width=100%>"
43                                 + "<tr class=\"w3-blue\">"
44                                 + "<th>" + _("Subject") + "</th>"
45                                 + "<th>" + _("Sender") + "</th>"
46                                 + "<th>" + _("Date") + "</th>"
47                                 + "<th>#</th>"
48                                 + "</tr>";
49
50                         for (var i=0; i<msgs.length; ++i) {
51                                 box += mail_render_row(msgs[i]);
52                         }
53
54                         box +=  "</table>";
55                         mailbox_pane.innerHTML = box;
56                 }
57         }
58         fetch_mailbox();
59         deactivate_loading_modal();
60 }