ponymail-commits mailing list archives

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

Branch: refs/heads/coffee-and-cake
Commit: 44100e943fff6ceff1f2c04ae7728f93d6d9a59b
Parents: 59a16d6
Author: Daniel Gruno <humbedooh@apache.org>
Authored: Mon Sep 5 09:01:07 2016 +0200
Committer: Daniel Gruno <humbedooh@apache.org>
Committed: Mon Sep 5 09:01:07 2016 +0200

----------------------------------------------------------------------
 site/js/ponymail-coffee.js | 247 ++++++++++++++++++++++++++++++++--------
 1 file changed, 199 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/44100e94/site/js/ponymail-coffee.js
----------------------------------------------------------------------
diff --git a/site/js/ponymail-coffee.js b/site/js/ponymail-coffee.js
index ebbd78e..0a7249f 100644
--- a/site/js/ponymail-coffee.js
+++ b/site/js/ponymail-coffee.js
@@ -1,5 +1,5 @@
 // Generated by CoffeeScript 1.9.3
-var 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_listview, ponymail_domain, ponymail_email_open,
ponymail_list, ponymail_list_json, ponymail_listname, ponymail_lists, ponymail_month, ponymail_query,
ponymail_version, readEmail, renderListView, set, setupAccount, spinCheck, testCoffee, testToggle,
toggleMonth, toggleYear, txt;
+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_query, ponymail_stored_email, ponymail_version, readEmail,
renderListView, set, setupAccount, spinCheck, testCoffee, testToggle, toggleMonth, toggleYear,
txt;
 
 calendar_months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August',
'September', 'October', 'November', 'December'];
 
@@ -293,7 +293,11 @@ ponymail_list_json = {};
 
 ponymail_current_listview = null;
 
-ponymail_email_open = false;
+ponymail_email_open = [];
+
+ponymail_current_email = null;
+
+ponymail_stored_email = {};
 
 
 /*
@@ -525,6 +529,169 @@ cog = function(div, size) {
  */
 
 
+/* readMail: figure out how to display an email/thread */
+
+readEmail = function(obj) {
+
+  /* find the original email ID and point of origin */
+  var closedOne, email, j, len, mid, parent;
+  mid = null;
+  parent = null;
+  if (typeof obj === 'string') {
+    mid = obj;
+    parent = document.body;
+  } else if (typeof obj === 'object') {
+    mid = obj.getAttribute("data");
+    parent = obj;
+  }
+
+  /* We good to go? */
+  if ((!mid) || (!parent)) {
+    alert("Couldn't find the email or insertion point!");
+    return;
+  }
+
+  /* First check if the MID is already open
+   * If so, close it instead
+   */
+  closedOne = false;
+  for (j = 0, len = ponymail_email_open.length; j < len; j++) {
+    email = ponymail_email_open[j];
+    if (mid === email.mid) {
+      email.hide();
+      closedOne = true;
+    }
+  }
+  if (!closedOne) {
+
+    /* We have an(other) email open now */
+    ponymail_current_email = new BasicEmailDisplay(parent, mid);
+    return ponymail_email_open.push(ponymail_current_email);
+  }
+};
+
+BasicEmailDisplay = (function() {
+  function BasicEmailDisplay(parent1, mid1) {
+    var me, r;
+    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;
+
+    /* Do we have this email in cache? */
+    if (ponymail_stored_email[this.mid]) {
+      this.render(ponymail_stored_email[this.mid]);
+    } else {
+
+      /* Not stored, fetch the email first */
+      r = new HTTPRequest("api/email.lua?", {
+        get: {
+          id: this.mid
+        },
+        callback: function(json, state) {
+          return me.render(json, state);
+        }
+      });
+    }
+  }
+
+  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;
+    }
+
+    /* Display email headers */
+    headers = new HTML('div');
+    from_line = new HTML('div', {}, [
+      new HTML('div', {
+        "class": "header_key"
+      }, "From: "), new HTML('div', {
+        "class": "header_value"
+      }, json.from)
+    ]);
+    headers.inject(from_line);
+    subject_line = new HTML('div', {}, [
+      new HTML('div', {
+        "class": "header_key"
+      }, "Subject: "), new HTML('div', {
+        "class": "header_value"
+      }, json.subject)
+    ]);
+    headers.inject(subject_line);
+    date_line = new HTML('div', {}, [
+      new HTML('div', {
+        "class": "header_key"
+      }, "Date: "), new HTML('div', {
+        "class": "header_value"
+      }, new Date(json.epoch * 1000).ISOBare())
+    ]);
+    headers.inject(date_line);
+
+    /* <a.b.c> -> a@b.c */
+    this.list = json.list_raw.replace(/<([^.]+)\.(.+)>/, (function(_this) {
+      return function(a, b, c) {
+        return b + "@" + c;
+      };
+    })(this));
+    list_line = new HTML('div', {}, [
+      new HTML('div', {
+        "class": "header_key"
+      }, "List: "), new HTML('div', {
+        "class": "header_value"
+      }, new HTML('a', {
+        href: "list.html?" + this.list
+      }, this.list))
+    ]);
+    headers.inject(list_line);
+    this.placeholder.inject(headers);
+
+    /* Now inject the body */
+    b = new HTML('pre', {}, json.body);
+    return this.placeholder.inject(b);
+  };
+
+  BasicEmailDisplay.prototype.hide = function() {
+    this.placeholder.show(false);
+    ponymail_email_open.remove(this);
+    return ponymail_current_email = null;
+  };
+
+  return 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
@@ -792,43 +959,32 @@ pm_snap = null;
 /* dealWithKeyboard: Handles what happens when you hit the escape key */
 
 dealWithKeyboard = function(e) {
-  var dp, i, j, kiddos, len, splash, thread, tid;
+  var dp, email, j, len, splash;
   splash = get('splash');
 
   /* escape key: hide composer/settings/thread */
   if (e.keyCode === 27) {
     if (splash && splash.style.display === 'block') {
       splash.style.display = "none";
-    } else if (location.href.search(/list\.html/) !== -1) {
+    } else if (location.href.search(/list\d?\.html/) !== -1) {
 
       /* should only work for the list view */
 
       /* If datepicker popup is shown, hide it on escape */
-      tid = (current_thread || "").toString().replace(/@<.+>/, "");
-      thread = get('thread_' + tid) || get('thread_treeview_' + tid);
-
-      /* minimize datepicker if shown */
       dp = get('datepicker_popup');
       if (dp && dp.style.display === "block") {
         dp.show(false);
-      } else if (thread) {
+      } else if (ponymail_email_open.length > 0) {
 
-        /* Otherwise, collapse a thread ?? */
-        if (thread.style.display === 'block') {
-          if (prefs.displayMode === 'treeview') {
-            toggleEmails_threaded(current_thread, true);
-            toggleEmails_treeview(current_thread, true);
-          } else {
-            toggleEmails_threaded(current_thread, true);
-          }
+        /* Close the currently open email? */
+        if (ponymail_current_email) {
+          ponymail_current_email.hide();
         } else {
 
-          /* Close all threads? */
-          kiddos = [];
-          traverseThread(document.body, '(thread|helper)_', 'DIV');
-          for (j = 0, len = kiddos.length; j < len; j++) {
-            i = kiddos[j];
-            kiddos[i].style.display = 'none';
+          /* Close all email ? */
+          for (j = 0, len = ponymail_email_open.length; j < len; j++) {
+            email = ponymail_email_open[j];
+            email.hide();
           }
         }
       }
@@ -848,7 +1004,7 @@ dealWithKeyboard = function(e) {
     } else if (e.keyCode === 82) {
 
       /* R key: reply */
-      if (openEmail() && last_opened_email) {
+      if (ponymail_current_email && ponymail_email_open.length > 0) {
         compose(last_opened_email, null, 'reply');
       }
     } else if (e.keyCode === 83) {
@@ -1184,7 +1340,7 @@ BasicListView = (function() {
             fontWeight: readStyle
           },
           href: "thread.html/" + thread.tid,
-          onclick: "readEmail(this.parentNode.parentNode); return false;"
+          onclick: "readEmail(this.parentNode.parentNode.parentNode); return false;"
         }, original.subject), new HTML('br'), new HTML('span', {
           "class": "listview_item_body"
         }, thread.body)
@@ -1225,7 +1381,9 @@ BasicListView = (function() {
         id: uid,
         data: thread.tid,
         "class": "listview_item"
-      }, [avatar, sender, subject, date, stats]);
+      }, new HTML('div', {
+        "class": "listview_summary"
+      }, [avatar, sender, subject, date, stats]));
       return item;
     }
   };
@@ -1517,28 +1675,6 @@ markRead = function(mid) {
   return true;
 };
 
-readEmail = function(obj) {
-  var insertPoint, mailDiv, mid;
-  mid = null;
-  insertPoint = null;
-
-  /* Did we get this from a div? if so, find out things */
-  if (typeof obj === 'object') {
-    mid = obj.getAttribute("data");
-    insertPoint = obj;
-  } else if (typeof obj === 'string') {
-    mid = obj;
-    insertPoint = new HTML('div');
-    document.body.inject(insertPoint);
-  }
-  if (mid && insertPoint) {
-    markRead(mid);
-    mailDiv = new HTML('div');
-    insertPoint.inject(mailDiv);
-    return mailDiv.inject("foo bar baz!");
-  }
-};
-
 
 /*
  Licensed to the Apache Software Foundation (ASF) under one or more
@@ -1615,6 +1751,21 @@ isHash = function(value) {
 };
 
 
+/* Remove an array element by value */
+
+Array.prototype.remove = function(val) {
+  var i, item, j, len;
+  for (i = j = 0, len = this.length; j < len; i = ++j) {
+    item = this[i];
+    if (item === val) {
+      this.splice(i, 1);
+      return this;
+    }
+  }
+  return this;
+};
+
+
 /*
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with


Mime
View raw message