Display "brief" datestamps in mailbox: date if not today, time if today.
authorArt Cancro <ajc@citadel.org>
Fri, 22 Jul 2022 18:42:49 +0000 (14:42 -0400)
committerArt Cancro <ajc@citadel.org>
Fri, 22 Jul 2022 18:42:49 +0000 (14:42 -0400)
webcit-ng/static/js/roomlist.js
webcit-ng/static/js/util.js
webcit-ng/static/js/view_forum.js
webcit-ng/static/js/view_mail.js
webcit-ng/static/js/views.js

index 3c0764ae8331057a17917d5426355e453ec26966..485f08e50496f1b00df639e2683484a00b1ff8f5 100644 (file)
@@ -58,7 +58,7 @@ function display_room_list_renderer(floor_list, room_list) {
                                + " w3-left\">"
                                + escapeHTML(room_list[i].name)
                                + "</span><span class=\"ctdl-roomlist-mtime w3-right\">"
-                               + convertTimestamp(room_list[i].mtime)
+                               + string_timestamp(room_list[i].mtime)
                                + "</span></div>";
                }
        }
index 629f0713455f0cd70ed7a40c3bdb699607a4cdf7..25589056a3b59c6ce6da0885f75645ab5994c249 100644 (file)
@@ -78,14 +78,25 @@ function escapeJS(text) {
 
 // Convert a UNIX timestamp to the browser's local time
 // 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) {
+// format should be: 0=full (date+time), 1=brief (date if not today, time if today)
+function string_timestamp(timestamp, format) {
        var ts = new Date(timestamp * 1000);
-       return(ts.toLocaleString());
+       if (format == 1) {
+               var now_ts = new Date(Date.now());
+               if (ts.toLocaleDateString() == now_ts.toLocaleDateString()) {
+                       return(ts.toLocaleTimeString());
+               }
+               else {
+                       return(ts.toLocaleDateString());
+               }
+       }
+       else {
+               return(ts.toLocaleString());
+       }
 }
 
 
-// An old version of convertTimestamp() did it the hard way.
+// An old version of string_timestamp() 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.
 
index 18602b8ea5d53b96ed20dbb3a65f351991c2ed5b..783fbc7defeab76eece5992b68ddfbb0edef8b0e 100644 (file)
@@ -187,7 +187,7 @@ function forum_render_one(msg, existing_div) {
                + msg.from
                + "</a></span>"                                                 // end username
                + "<span class=\"ctdl-msgdate\">"
-               + convertTimestamp(msg.time)
+               + string_timestamp(msg.time,0)
                + "</span>"                                                     // end msgdate
                + "</span>"                                                     // end header info on left side
                + "<span class=\"ctdl-msg-header-buttons\">"                    // begin buttons on right side
@@ -296,7 +296,7 @@ function open_reply_box(parent_div, is_quoted, references, msgid) {
        + current_user                                                  // user = me !
        + "</span>"
        + "<span class=\"ctdl-msgdate\">"
-       + convertTimestamp(Date.now() / 1000)                           // the current date/time (temporary for display)
+       + string_timestamp((Date.now() / 1000),0)                       // the current date/time (temporary for display)
        + "</span>"
        + "</span>"                                                     // end header info on left side
        + "<span class=\"ctdl-msg-header-buttons\">"                    // begin buttons on right side
index 6566808e21416aff7ab5675fb7cc9f97296a9da1..8522e77a851a45d7b6f11eeb18e94716a6edfb32 100644 (file)
@@ -27,23 +27,17 @@ function mail_render_one(msg, target_div) {
                + msg.from
                + "</a></span>"                                                 // end username
                + "<span class=\"ctdl-msgdate\">"
-               + convertTimestamp(msg.time)
+               + string_timestamp(msg.time,0)
                + "</span>"                                                     // end msgdate
                + "</span>"                                                     // end header info on left side
                + "<span class=\"ctdl-msg-header-buttons\">"                    // begin buttons on right side
        
-               + "<span class=\"ctdl-msg-button\">"                            // Reply
-               + "<a href=\"javascript:open_reply_box('"+div+"',false,'"+msg.wefw+"','"+msg.msgn+"');\">"
+               + "<span class=\"ctdl-msg-button\">"                            // Reply (mail is always Quoted)
+               + "<a href=\"javascript:mail_compose(true,'"+msg.wefw+"','"+msg.msgn+"');\">"
                + "<i class=\"fa fa-reply\"></i> " 
                + _("Reply")
                + "</a></span>"
        
-               + "<span class=\"ctdl-msg-button\">"                            // ReplyQuoted
-               + "<a href=\"javascript:open_reply_box('"+div+"',true,'"+msg.wefw+"','"+msg.msgn+"');\">"
-               + "<i class=\"fa fa-comment\"></i> " 
-               + _("ReplyQuoted")
-               + "</a></span>";
-       
                if (can_delete_messages) {
                        outmsg +=
                        "<span class=\"ctdl-msg-button\">"
@@ -121,7 +115,7 @@ function mail_render_row(msg) {
                + ">"
                + "<td>" + msg["subject"] + "</td>"
                + "<td>" + msg["author"] + " &lt;" + msg["addr"] + "&gt;</td>"
-               + "<td>" + convertTimestamp(msg["time"]) + "</td>"
+               + "<td>" + string_timestamp(msg["time"],1) + "</td>"
                + "<td class=\"w3-right-align\">" + msg["msgnum"] + "</td>"
                + "</tr>";
        return(row);
@@ -217,7 +211,10 @@ function render_mailbox_display() {
 }
 
 
-// Enter a new mail message (called by the dispatcher in views.js)
-function mail_entmsg() {
-       alert("no handler for entering new mail yet");
+// Compose a new mail message (called by the Reply button here, or by the dispatcher in views.js)
+function mail_compose(is_quoted, references, msgid) {
+       console.log("mail_compose() called");
+       console.log("is_quoted: " + is_quoted);
+       console.log("references: " + references);
+       console.log("msgid: " + msgid);
 }
index 3096bfe02ed5607994d8abd1624c6e61eb022d69..9c3261bc21416c304c54952ec654c5b4e83e5bb6 100644 (file)
@@ -53,7 +53,7 @@ function entmsg_dispatcher() {
                        forum_entmsg();
                        break;
                default:
-                       mail_entmsg();
+                       mail_compose(false, "", "");
                        break;
        }
 }