Use the library functions to stringify a date instead of doing it the hard way.
authorArt Cancro <ajc@citadel.org>
Sun, 3 Jul 2022 20:55:42 +0000 (16:55 -0400)
committerArt Cancro <ajc@citadel.org>
Sun, 3 Jul 2022 20:55:42 +0000 (16:55 -0400)
webcit-ng/static/js/util.js
webcit-ng/static/js/view_mail.js

index 10979aba5dcf3963e7e9f4e88563c87f9036ca1d..e25921eb3e410e3eaeea56fa254341bcd52796dc 100644 (file)
@@ -78,37 +78,19 @@ function escapeJS(text) {
 
 
 // Convert a UNIX timestamp to the browser's local time
-// Shamelessly swiped from https://gist.github.com/kmaida/6045266
+// See also: https://timestamp.online/article/how-to-convert-timestamp-to-datetime-in-javascript
+// In the future we could let the user select from several available formats.
 function convertTimestamp(timestamp) {
-       var d = new Date(timestamp * 1000),                     // Convert the passed timestamp to milliseconds
-               yyyy = d.getFullYear(),
-               mm = ('0' + (d.getMonth() + 1)).slice(-2),      // Months are zero based. Add leading 0.
-               dd = ('0' + d.getDate()).slice(-2),             // Add leading 0.
-               hh = d.getHours(),
-               h = hh,
-               min = ('0' + d.getMinutes()).slice(-2),         // Add leading 0.
-               ampm = 'AM',
-               time;
-                       
-       if (hh > 12) {
-               h = hh - 12;
-               ampm = 'PM';
-       }
-       else if (hh === 12) {
-               h = 12;
-               ampm = 'PM';
-       }
-       else if (hh == 0) {
-               h = 12;
-       }
-       
-       // ie: 2013-02-18, 8:35 AM      
-       time = yyyy + '-' + mm + '-' + dd + ', ' + h + ':' + min + ' ' + ampm;
-               
-       return time;
+       var ts = new Date(timestamp * 1000);
+       return(ts.toLocaleString());
 }
 
 
+// An old version of convertTimestamp() did it the hard way.
+// It used https://gist.github.com/kmaida/6045266 as a reference.
+// check git history prior to 2022-jul-03 if you want to see it.
+
+
 // Get the value of a cookie from the HTTP session
 // Shamelessly swiped from https://stackoverflow.com/questions/5639346/what-is-the-shortest-function-for-reading-a-cookie-by-name-in-javascript
 const getCookieValue = (name) => (
index 38245621b462b6078ff46fd24abf68247e48e550..f3ee2acfab91bf6b4b2546cd1b3ab41106c119a2 100644 (file)
@@ -4,6 +4,12 @@
 // disclosure are subject to the GNU General Public License v3.
 
 
+// A message has been selected...
+function select_message(msgnum) {
+       reading_pane = document.getElementById("ctdl-reading-pane").innerHTML = "message selected " + msgnum ;
+}
+
+
 // Set up the mailbox view
 function mail_display() {
        target_div = document.getElementById("ctdl-main");
@@ -18,16 +24,19 @@ function mail_display() {
                msgs = await(response.json());
                if (response.ok) {
 
-                       box =   "<table border=1 width=100%><tr>"
+                       box =   "<table class=\"w3-table-all\" width=100%>"
+                               + "<tr class=\"w3-blue\">"
                                + "<th>" + _("Subject") + "</th>"
                                + "<th>" + _("Sender") + "</th>"
                                + "<th>" + _("Date") + "</th>"
                                + "<th>#</th>"
                                + "</tr>";
 
-
                        for (var i=0; i<msgs.length; ++i) {
-                               box +=  "<tr id=\"ctdl-msgsum-" + msgs[i]["msgnum"] + "\">"
+                               box +=  "<tr "
+                                       + "id=\"ctdl-msgsum-" + msgs[i]["msgnum"] + "\""
+                                       + "onClick=\"select_message(" + msgs[i]["msgnum"] + ")\""
+                                       + ">"
                                        + "<td>" + msgs[i]["subject"] + "</td>"
                                        + "<td>" + msgs[i]["author"] + " &lt;" + msgs[i]["addr"] + "&gt;</td>"
                                        + "<td>" + convertTimestamp(msgs[i]["time"]) + "</td>"