ponymail-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From humbed...@apache.org
Subject [3/3] incubator-ponymail git commit: regen JS
Date Mon, 05 Sep 2016 08:50:05 GMT
regen JS


Project: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/commit/6340e088
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/tree/6340e088
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/diff/6340e088

Branch: refs/heads/coffee-and-cake
Commit: 6340e088e76a743a4bdc096f06825d25356d510e
Parents: c7f5104
Author: Daniel Gruno <humbedooh@apache.org>
Authored: Mon Sep 5 10:49:49 2016 +0200
Committer: Daniel Gruno <humbedooh@apache.org>
Committed: Mon Sep 5 10:49:49 2016 +0200

----------------------------------------------------------------------
 site/js/ponymail-coffee.js | 244 +++++++++++++++++++++++++++++++++++-----
 1 file changed, 217 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/6340e088/site/js/ponymail-coffee.js
----------------------------------------------------------------------
diff --git a/site/js/ponymail-coffee.js b/site/js/ponymail-coffee.js
index 4d146fd..366db70 100644
--- a/site/js/ponymail-coffee.js
+++ b/site/js/ponymail-coffee.js
@@ -1,5 +1,7 @@
 // Generated by CoffeeScript 1.9.3
-var BasicEmailDisplay, BasicListView, Calendar, HTML, HTTPRequest, calendar_months, cog,
dbRead, dbWrite, dealWithKeyboard, e, genColors, get, hasRead, hsl2rgb, isArray, isHash, listView,
listviewScaffolding, markRead, maxLists, parseURL, pendingURLStatus, pending_spinner_at, pending_url_operations,
pm_snap, pm_storage_available, pm_storage_globvar, ponymail_current_email, ponymail_current_listview,
ponymail_domain, ponymail_email_open, ponymail_list, ponymail_list_json, ponymail_listname,
ponymail_lists, ponymail_month, ponymail_preferences, ponymail_query, ponymail_quote_regex,
ponymail_stored_email, ponymail_url_regex, ponymail_version, readEmail, renderListView, set,
setupAccount, spinCheck, testCoffee, testToggle, toggleMonth, toggleQuote, toggleYear, txt;
+var BasicEmailDisplay, BasicListView, Calendar, HTML, HTTPRequest, SingleListView, calendar_months,
cog, dbRead, dbWrite, dealWithKeyboard, e, genColors, get, hasRead, hsl2rgb, isArray, isHash,
listView, listviewScaffolding, markRead, maxLists, parseURL, pendingURLStatus, pending_spinner_at,
pending_url_operations, pm_snap, pm_storage_available, pm_storage_globvar, ponymail_current_email,
ponymail_current_listview, ponymail_domain, ponymail_email_open, ponymail_list, ponymail_list_json,
ponymail_listname, ponymail_lists, ponymail_month, ponymail_preferences, ponymail_query, ponymail_quote_regex,
ponymail_stored_email, ponymail_url_regex, ponymail_version, readEmail, renderListView, set,
setupAccount, spinCheck, testCoffee, testToggle, toggleMonth, toggleQuote, toggleYear, txt,
+  extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key))
child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype =
parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return
child; },
+  hasProp = {}.hasOwnProperty;
 
 calendar_months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August',
'September', 'October', 'November', 'December'];
 
@@ -1253,7 +1255,7 @@ BasicListView = (function() {
   /* scroll: scroll to a position and show N emails/threads */
 
   BasicListView.prototype.scroll = function(rpp, pos) {
-    var dStat, diff, f, item, j, l, len, lvitems, nbutton, nno, now, np, original, pbutton,
pno, pp, ref, tmpthis, topButtons;
+    var dStat, diff, f, l, nbutton, nno, now, np, pbutton, pno, pp, tmpthis, topButtons;
     this.lastScroll = new Date().getTime();
 
     /* Clear the list view */
@@ -1276,7 +1278,7 @@ BasicListView = (function() {
     this.lv.inject(dStat);
 
     /* First, build the prev/next buttons if needed */
-    if (pos > 0 || (pos + rpp) < this.json.thread_struct.length) {
+    if (pos > 0 || (pos + rpp) < this.listsize) {
       topButtons = new HTML('div', {
         style: {
           float: "left",
@@ -1299,8 +1301,8 @@ BasicListView = (function() {
       }
 
       /* Next button */
-      if ((pos + rpp) < this.json.thread_struct.length) {
-        nno = Math.min(rpp, this.json.thread_struct.length - pos - rpp);
+      if ((pos + rpp) < this.listsize) {
+        nno = Math.min(rpp, this.listsize - pos - rpp);
         np = pos + rpp;
         nbutton = new HTML('input', {
           type: 'button',
@@ -1315,27 +1317,7 @@ BasicListView = (function() {
       }
       this.lv.inject(topButtons);
     }
-
-    /* For each email result,... */
-    lvitems = new HTML('div', {
-      "class": "listview_table"
-    });
-    ref = this.json.thread_struct.slice(pos, pos + rpp);
-    for (j = 0, len = ref.length; j < len; j++) {
-      item = ref[j];
-      original = this.findEmail(item.tid);
-
-      /* Be sure we actually have an email here */
-      if (original) {
-
-        /* Call listViewItem to compile a list view HTML element */
-        item = this.listViewItem(original, item);
-
-        /* Inject new item into the list view */
-        lvitems.inject(item);
-      }
-    }
-    this.lv.inject(lvitems);
+    this.renderItems();
 
     /* If we made buttons, clone them at the bottom */
     if (topButtons) {
@@ -1360,6 +1342,34 @@ BasicListView = (function() {
   };
 
 
+  /* renderItems: render the list view emails/theads */
+
+  BasicListView.prototype.renderItems = function() {
+
+    /* For each email result,... */
+    var item, j, len, lvitems, original, ref;
+    lvitems = new HTML('div', {
+      "class": "listview_table"
+    });
+    ref = this.json.thread_struct.slice(this.pos, this.pos + this.rpp);
+    for (j = 0, len = ref.length; j < len; j++) {
+      item = ref[j];
+      original = this.findEmail(item.tid);
+
+      /* Be sure we actually have an email here */
+      if (original) {
+
+        /* Call listViewItem to compile a list view HTML element */
+        item = this.listViewItem(original, item);
+
+        /* Inject new item into the list view */
+        lvitems.inject(item);
+      }
+    }
+    return this.lv.inject(lvitems);
+  };
+
+
   /* findEmail: find an email given an ID */
 
   BasicListView.prototype.findEmail = function(id) {
@@ -1718,7 +1728,7 @@ renderListView = function(json, state) {
     cal = new Calendar(json.firstYear, json.lastYear, ponymail_month);
     get('calendar').empty().inject(cal);
   }
-  return lv = new BasicListView(json);
+  return lv = new SingleListView(json);
 };
 
 
@@ -1741,6 +1751,186 @@ renderListView = function(json, state) {
 
 
 /**
+ * Single email list view - extends BasicListView
+ */
+
+SingleListView = (function(superClass) {
+  extend(SingleListView, superClass);
+
+
+  /* json: from stats.lua, rpp = results per page, pos = starting position (from 0) */
+
+  function SingleListView(json1, rpp1, pos1) {
+    var date, hd, m, ref, y;
+    this.json = json1;
+    this.rpp = rpp1 != null ? rpp1 : 15;
+    this.pos = pos1 != null ? pos1 : 0;
+
+    /* Set the header first */
+    hd = get('header');
+    if (this.json.list) {
+      if (ponymail_month.length > 0) {
+        ref = ponymail_month.split("-", 2), y = ref[0], m = ref[1];
+        date = calendar_months[parseInt(m) - 1] + (", " + y);
+        hd.empty().inject([
+          this.json.list + " (" + date + "):", new HTML('a', {
+            href: "api/mbox.lua?list=" + ponymail_list + "&date=" + ponymail_month,
+            title: "Download as mbox archive"
+          }, new HTML('img', {
+            src: 'images/floppy.svg',
+            style: {
+              marginLeft: "10px",
+              width: "20px",
+              height: "20px",
+              verticalAlign: 'middle'
+            }
+          }))
+        ]);
+      } else {
+        hd.empty().inject(this.json.list + ", past 30 days:");
+      }
+    }
+
+    /* Get and clear the list view */
+    this.lv = get('listview');
+    this.lv = this.lv.empty();
+
+    /* Set some internal vars */
+    this.listsize = 0;
+
+    /* If we got results, use scroll() to display from result 0 on */
+    if (isArray(this.json.emails) && this.json.emails.length > 0) {
+
+      /* Set some internal vars */
+      this.listsize = this.json.emails.length;
+
+      /* Reverse thread struct, but only if we're not using an
+       * already reversed cache
+       */
+      if (!this.json.cached) {
+        this.json.emails.reverse();
+      }
+      this.scroll(this.rpp, this.pos);
+    } else {
+
+      /* No results, just say...that */
+      this.lv.inject("No emails found matching this criterion.");
+    }
+    ponymail_current_listview = this;
+    return this;
+  }
+
+  SingleListView.prototype.renderItems = function() {
+
+    /* For each email result,... */
+    var item, j, len, lvitems, original, ref;
+    lvitems = new HTML('div', {
+      "class": "listview_table"
+    });
+    ref = this.json.emails.slice(this.pos, this.pos + this.rpp);
+    for (j = 0, len = ref.length; j < len; j++) {
+      original = ref[j];
+
+      /* Be sure we actually have an email here */
+      if (original) {
+
+        /* Call listViewItem to compile a list view HTML element */
+        item = this.listViewItem(original, null);
+
+        /* Inject new item into the list view */
+        lvitems.inject(item);
+      }
+    }
+    return this.lv.inject(lvitems);
+  };
+
+  SingleListView.prototype.listViewItem = function(original, thread) {
+
+    /* Be sure we actually have an email here */
+    var avatar, date, date_style, item, now, readStyle, sender, subject, uid;
+    if (original) {
+      now = new Date().getTime() / 1000;
+
+      /* Render the email in the LV */
+
+      /* First set some data points for later */
+      uid = parseInt(Math.random() * 999999999999).toString(16);
+
+      /* Gravatar */
+      avatar = new HTML('img', {
+        "class": "gravatar",
+        src: "https://secure.gravatar.com/avatar/" + original.gravatar + ".png?s=24&r=g&d=mm"
+      });
+
+      /* Sender, without the <foo@bar> part - just the name */
+      sender = new HTML('div', {
+        style: {
+          fontWeight: "bold"
+        }
+      }, original.from.replace(/\s*<.+>/, "").replace(/"/g, ''));
+
+      /* readStyle: bold if new email, normal if read before */
+      readStyle = "bold";
+      if (hasRead(original.id)) {
+        readStyle = "normal";
+      }
+
+      /* Subject, PLUS a bit of the body with a break before */
+      subject = new HTML('div', {}, [
+        new HTML('a', {
+          style: {
+            fontWeight: readStyle
+          },
+          href: "thread.html/" + original.id,
+          onclick: "readEmail(this.parentNode.parentNode.parentNode); return false;"
+        }, original.subject)
+      ]);
+
+      /* Add date; yellow if <= 1day, grey otherwise */
+      date_style = "listview_grey";
+      if ((now - 86400 * 4) < original.epoch) {
+        date_style = "listview_yellow";
+      }
+      date = new HTML('div', {
+        "class": "listview_right " + date_style
+      }, new Date(original.epoch * 1000).ISOBare());
+
+      /* Finally, pull it all together in a div and add that to the listview */
+      item = new HTML('div', {
+        id: uid,
+        data: original.id,
+        "class": "listview_item"
+      }, new HTML('div', {
+        "class": "listview_summary"
+      }, [avatar, sender, subject, date]));
+      return item;
+    }
+  };
+
+  return SingleListView;
+
+})(BasicListView);
+
+
+/*
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+
+/**
  * Init: Test if localStorage is available or not
  * If not, fall back to plain global var storage (not effective, but meh)
  */


Mime
View raw message