ponymail-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From humbed...@apache.org
Subject [7/7] incubator-ponymail git commit: regen JS
Date Mon, 05 Sep 2016 14:35:41 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/a0d9ff37
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/tree/a0d9ff37
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/diff/a0d9ff37

Branch: refs/heads/coffee-and-cake
Commit: a0d9ff37133bb7cef940168c8ae4f8f7d741f20c
Parents: 99d2a38
Author: Daniel Gruno <humbedooh@apache.org>
Authored: Mon Sep 5 16:35:21 2016 +0200
Committer: Daniel Gruno <humbedooh@apache.org>
Committed: Mon Sep 5 16:35:21 2016 +0200

----------------------------------------------------------------------
 site/js/ponymail-coffee.js | 178 ++++++++++++++++++++++++++++++++++------
 1 file changed, 152 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/a0d9ff37/site/js/ponymail-coffee.js
----------------------------------------------------------------------
diff --git a/site/js/ponymail-coffee.js b/site/js/ponymail-coffee.js
index 0d52873..419ea51 100644
--- a/site/js/ponymail-coffee.js
+++ b/site/js/ponymail-coffee.js
@@ -1,5 +1,5 @@
 // Generated by CoffeeScript 1.9.3
-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,
+var BasicEmailDisplay, BasicListView, Calendar, HTML, HTTPRequest, SingleListView, ThreadedEmailDisplay,
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;
 
@@ -354,7 +354,7 @@ HTML = (function() {
         val = params[key];
 
         /* Standard string value? */
-        if (typeof val === "string") {
+        if (typeof val === "string" || typeof val === 'number') {
           this.element.setAttribute(key, val);
         } else if (isArray(val)) {
 
@@ -365,6 +365,9 @@ HTML = (function() {
           /* Are we trying to set multiple sub elements, like a style? */
           for (subkey in val) {
             subval = val[subkey];
+            if (!this.element[key]) {
+              throw "No such attribute, " + key + "!";
+            }
             this.element[key][subkey] = subval;
           }
         }
@@ -538,7 +541,7 @@ cog = function(div, size) {
 readEmail = function(obj) {
 
   /* find the original email ID and point of origin */
-  var closedOne, email, j, len, mid, parent;
+  var closedOne, email, index, j, len, mid, parent;
   mid = null;
   parent = null;
   if (typeof obj === 'string') {
@@ -569,8 +572,11 @@ readEmail = function(obj) {
   }
   if (!closedOne) {
 
+    /* Get thread index value if set, for threads */
+    index = parent.getAttribute("data-index");
+
     /* We have an(other) email open now */
-    ponymail_current_email = new BasicEmailDisplay(parent, mid);
+    ponymail_current_email = new ThreadedEmailDisplay(parent, mid, index);
     return ponymail_email_open.push(ponymail_current_email);
   }
 };
@@ -616,13 +622,16 @@ BasicEmailDisplay = (function() {
   BasicEmailDisplay.prototype.render = function(json, state) {
 
     /* Store email in cache if not there already */
-    var b, date_line, from_line, headers, list_line, subject_line;
-    if (!ponymail_stored_email[this.mid]) {
-      ponymail_stored_email[this.mid] = json;
+    var b, date_line, from_line, headers, htmlbody, list_line, placeholder, subject_line;
+    if (!ponymail_stored_email[json.mid]) {
+      ponymail_stored_email[json.mid] = json;
     }
+    placeholder = get('placeholder_' + this.mid + "_" + json.mid) || get('placeholder_' +
json.mid);
 
     /* Display email headers */
-    headers = new HTML('div');
+    headers = new HTML('div', {
+      "class": "email_header"
+    });
     from_line = new HTML('div', {}, [
       new HTML('div', {
         "class": "header_key"
@@ -664,16 +673,16 @@ BasicEmailDisplay = (function() {
       }, this.list))
     ]);
     headers.inject(list_line);
-    this.placeholder.inject(headers);
+    placeholder.inject(headers);
 
     /* parse body, convert quotes */
-    this.htmlbody = this.quotify(json.body);
+    htmlbody = this.quotify(json.body);
 
     /* Now inject the body */
     b = new HTML('pre', {
       "class": "email_body"
-    }, this.htmlbody);
-    return this.placeholder.inject(b);
+    }, htmlbody);
+    return placeholder.inject(b);
   };
 
 
@@ -826,6 +835,121 @@ toggleQuote = function(div) {
  */
 
 
+/* threaded email display class - extends BasicEmail Display */
+
+ThreadedEmailDisplay = (function(superClass) {
+  extend(ThreadedEmailDisplay, superClass);
+
+  function ThreadedEmailDisplay(parent1, mid1, index) {
+    var me, thread;
+    this.parent = parent1;
+    this.mid = mid1;
+    this.placeholder = get("placeholder_" + this.mid) || new HTML('div', {
+      "class": "email_placeholder",
+      id: "placeholder_" + this.mid
+    });
+
+    /* Inject into listview or body */
+    this.parent.inject(this.placeholder);
+
+    /* Make sure it's empty, may have been used before! */
+    this.placeholder = this.placeholder.empty();
+    this.placeholder.show(true);
+    me = this;
+
+    /* Find the thread or fake one */
+    thread = {
+      tid: this.mid
+    };
+    if (index && ponymail_current_listview && ponymail_current_listview.json.thread_struct[index])
{
+      thread = ponymail_current_listview.json.thread_struct[index];
+    }
+    this.threadedFetch(this.placeholder, thread, 1);
+    return this;
+  }
+
+  ThreadedEmailDisplay.prototype.threadedFetch = function(parent, thread, nestedness) {
+
+    /* Make the thread item placeholder */
+    var bcolor, bcolors, bodyplace, item, j, len, me, place, r, ref, replyplace;
+    bodyplace = new HTML('div', {
+      id: "placeholder_" + this.mid + "_" + thread.tid,
+      "class": "email_boxed"
+    });
+
+    /* Assign a random color to the left */
+    bcolors = ['#C93F20', '#20C94A', '#2063C9', '#C9AA20', '#AD20C9', '#99C920', '#20C9C3'];
+    bcolor = bcolors[Math.round(Math.random() * bcolors.length)];
+    bodyplace.style.borderLeft = "4px solid " + bcolor;
+    replyplace = new HTML('div', {
+      id: "thread_replies_" + this.mid + "_" + thread.tid,
+      style: {
+        marginLeft: "20px"
+      }
+    });
+    place = new HTML('div', {
+      id: "thread_parent_" + this.mid + "_" + thread.tid,
+      style: {
+        float: "left",
+        width: "100%"
+      }
+    }, [bodyplace, replyplace]);
+    parent.inject(place);
+
+    /* Do we have this email in cache? */
+    if (ponymail_stored_email[thread.tid]) {
+      this.render(ponymail_stored_email[thread.tid]);
+    } else {
+      me = this;
+
+      /* Not stored, fetch the email first */
+      r = new HTTPRequest("api/email.lua?", {
+        get: {
+          id: thread.tid
+        },
+        callback: function(json, state) {
+          return me.render(json, state);
+        },
+        state: {
+          nest: Math.min(nestedness + 1, 5)
+        }
+      });
+    }
+
+    /* Now do the same for each child item */
+    if (thread.children && isArray(thread.children) && thread.children.length
> 0) {
+      ref = thread.children;
+      for (j = 0, len = ref.length; j < len; j++) {
+        item = ref[j];
+        this.threadedFetch(replyplace, item, Math.min(nestedness + 1, 5));
+      }
+    }
+    return this;
+  };
+
+  return ThreadedEmailDisplay;
+
+})(BasicEmailDisplay);
+
+
+/*
+ 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.
+ */
+
+
 /**
  * Pending URLs watcher:
  * Wathes which URLs have been pending a result for a while
@@ -1351,21 +1475,21 @@ BasicListView = (function() {
   BasicListView.prototype.renderItems = function() {
 
     /* For each email result,... */
-    var item, j, lastitem, len, lvitem, original, ref;
+    var i, item, j, lastitem, len, lvitem, original, ref;
     this.lvitems = new HTML('div', {
       "class": "listview_table"
     });
     lastitem = null;
     ref = this.json.thread_struct.slice(this.pos, this.pos + this.rpp);
-    for (j = 0, len = ref.length; j < len; j++) {
-      item = ref[j];
+    for (i = j = 0, len = ref.length; j < len; i = ++j) {
+      item = ref[i];
       original = this.findEmail(item.tid);
 
       /* Be sure we actually have an email here */
       if (original) {
 
         /* Call listViewItem to compile a list view HTML element */
-        lvitem = this.listViewItem(original, item);
+        lvitem = this.listViewItem(original, item, i + this.pos);
         lastitem = lvitem;
 
         /* Inject new item into the list view */
@@ -1395,19 +1519,20 @@ BasicListView = (function() {
   /* countEmail: func for counting how many emails are in a thread */
 
   BasicListView.prototype.countEmail = function(thread) {
-    var item, j, len, n, ref;
-    n = 0;
-    if (thread.children) {
-      ref = (isArray(thread.children) ? thread.children : []);
+    var item, j, len, nc, nnc, ref;
+    nc = 0;
+    if (thread.children && isArray(thread.children)) {
+      ref = thread.children;
       for (j = 0, len = ref.length; j < len; j++) {
         item = ref[j];
-        n++;
-        if (isArray(item.children) && item.children.length > 0) {
-          n += this.countEmail(item.children);
+        nc++;
+        if (item.children && isArray(item.children) && item.children.length
> 0) {
+          nnc = this.countEmail(item);
+          nc += nnc;
         }
       }
     }
-    return n;
+    return nc;
   };
 
 
@@ -1446,7 +1571,7 @@ BasicListView = (function() {
     }
   };
 
-  BasicListView.prototype.listViewItem = function(original, thread) {
+  BasicListView.prototype.listViewItem = function(original, thread, index) {
 
     /* Be sure we actually have an email here */
     var avatar, date, date_style, envelopeimg, item, noeml, now, people, peopleimg, readStyle,
sender, stats, subject, uid;
@@ -1528,6 +1653,7 @@ BasicListView = (function() {
       item = new HTML('div', {
         id: uid,
         data: thread.tid,
+        'data-index': index,
         "class": "listview_item"
       }, new HTML('div', {
         "class": "listview_summary"
@@ -1743,7 +1869,7 @@ renderListView = function(json, state) {
     cal = new Calendar(json.firstYear, json.lastYear, ponymail_month);
     get('calendar').empty().inject(cal);
   }
-  return lv = new SingleListView(json);
+  return lv = new BasicListView(json);
 };
 
 


Mime
View raw message