Use the library functions to stringify a date instead of doing it the hard way.
[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 // Set up the mailbox view
14 function mail_display() {
15         target_div = document.getElementById("ctdl-main");
16         target_div.innerHTML = "<div id=\"ctdl-mailbox-pane\">mailbox pane</div><div id=\"ctdl-reading-pane\">reading pane</div>";
17         mailbox_pane = document.getElementById("ctdl-mailbox-pane");
18         reading_pane = document.getElementById("ctdl-reading-pane");
19
20         activate_loading_modal();
21         url = "/ctdl/r/" + escapeHTMLURI(current_room) + "/mailbox";
22         fetch_mailbox = async() => {
23                 response = await fetch(url);
24                 msgs = await(response.json());
25                 if (response.ok) {
26
27                         box =   "<table class=\"w3-table-all\" width=100%>"
28                                 + "<tr class=\"w3-blue\">"
29                                 + "<th>" + _("Subject") + "</th>"
30                                 + "<th>" + _("Sender") + "</th>"
31                                 + "<th>" + _("Date") + "</th>"
32                                 + "<th>#</th>"
33                                 + "</tr>";
34
35                         for (var i=0; i<msgs.length; ++i) {
36                                 box +=  "<tr "
37                                         + "id=\"ctdl-msgsum-" + msgs[i]["msgnum"] + "\""
38                                         + "onClick=\"select_message(" + msgs[i]["msgnum"] + ")\""
39                                         + ">"
40                                         + "<td>" + msgs[i]["subject"] + "</td>"
41                                         + "<td>" + msgs[i]["author"] + " &lt;" + msgs[i]["addr"] + "&gt;</td>"
42                                         + "<td>" + convertTimestamp(msgs[i]["time"]) + "</td>"
43                                         + "<td>" + msgs[i]["msgnum"] + "</td>"
44                                         + "</tr>";
45                         }
46
47                         box +=  "</table>";
48                         mailbox_pane.innerHTML = box;
49                 }
50         }
51         fetch_mailbox();
52         deactivate_loading_modal();
53 }