You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by hu...@apache.org on 2016/09/02 19:17:45 UTC

[7/7] incubator-ponymail git commit: regen JS

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/5cc21173
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/tree/5cc21173
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/diff/5cc21173

Branch: refs/heads/coffee-and-cake
Commit: 5cc2117355a78b541955969efaea3d1c2b80d552
Parents: ff2ab2f
Author: Daniel Gruno <hu...@apache.org>
Authored: Fri Sep 2 21:17:24 2016 +0200
Committer: Daniel Gruno <hu...@apache.org>
Committed: Fri Sep 2 21:17:24 2016 +0200

----------------------------------------------------------------------
 site/js/ponymail-coffee.js | 292 +++++++++++++++++++++++++++++++++++++---
 1 file changed, 275 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/5cc21173/site/js/ponymail-coffee.js
----------------------------------------------------------------------
diff --git a/site/js/ponymail-coffee.js b/site/js/ponymail-coffee.js
index 714a957..d704781 100644
--- a/site/js/ponymail-coffee.js
+++ b/site/js/ponymail-coffee.js
@@ -1,5 +1,5 @@
 // Generated by CoffeeScript 1.9.3
-var Calendar, HTML, HTTPRequest, calendar_months, cog, dbRead, dbWrite, e, genColors, get, hsl2rgb, isArray, isHash, pm_storage_available, pm_storage_globvar, set, testCoffee, testToggle, toggleMonth, toggleYear, txt;
+var Calendar, HTML, HTTPRequest, calendar_months, cog, dbRead, dbWrite, e, genColors, get, hsl2rgb, isArray, isHash, listView, listviewScaffolding, pendingURLStatus, pending_url_operations, pm_storage_available, pm_storage_globvar, set, testCoffee, testToggle, toggleMonth, toggleYear, txt;
 
 calendar_months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
 
@@ -13,23 +13,32 @@ calendar_months = ['January', 'February', 'March', 'April', 'May', 'June', 'July
 
 Calendar = (function() {
   function Calendar(start, end, jumpTo) {
-    var div, eMonth, eYear, j, m, month, monthDiv, monthsDiv, now, ref, ref1, ref2, ref3, ref4, sMonth, sYear, yDiv, year, years;
+    var div, eMonth, eYear, j, month, monthDiv, monthsDiv, now, o, ref, ref1, ref2, ref3, ref4, sMonth, sYear, uid, yDiv, year, years;
     now = new Date();
+    uid = parseInt(Math.random() * 100000000).toString(16);
 
     /* Split start and end into years and months */
-    ref = start.split("-"), sYear = ref[0], sMonth = ref[1];
+    ref = String(start).split("-"), sYear = ref[0], sMonth = ref[1];
     ref1 = [now.getFullYear(), now.getMonth() + 1], eYear = ref1[0], eMonth = ref1[1];
 
     /* If end year+month given, use it */
     if (end) {
-      ref2 = end.split("-"), eYear = ref2[0], eMonth = ref2[1];
+      ref2 = String(end).split("-"), eYear = ref2[0], eMonth = ref2[1];
+    }
+
+    /* Make sure months are there, otherwise set them */
+    if (!sMonth) {
+      sMonth = 1;
+    }
+    if (!eMonth) {
+      eMonth = 12;
     }
 
     /* For each year, construct the year div to hold months */
     years = [];
     for (year = j = ref3 = parseInt(sYear), ref4 = parseInt(eYear); ref3 <= ref4 ? j <= ref4 : j >= ref4; year = ref3 <= ref4 ? ++j : --j) {
       yDiv = new HTML('div', {
-        id: "calendar_year_" + year,
+        id: ("calendar_year_" + uid + "_") + year,
         data: String(year),
         "class": "calendar_year",
         onclick: "toggleYear(this);"
@@ -43,17 +52,17 @@ Calendar = (function() {
           display: (jumpTo && jumpTo === year) || (!jumpTo && year === parseInt(eYear)) ? "block" : "none"
         },
         "class": "calendar_months",
-        id: "calendar_months_" + year
+        id: ("calendar_months_" + uid + "_") + year
       });
 
       /* For each month, make a div */
-      for (month = m = 12; m >= 1; month = --m) {
+      for (month = o = 12; o >= 1; month = --o) {
 
         /* Make sure this is within the start<->end range */
         if ((year > sYear || month >= sMonth) && (year < eYear || month <= eMonth)) {
           monthDiv = new HTML('div', {
             "class": "calendar_month",
-            id: "calendar_month_" + year + "-" + month,
+            id: "calendar_month_" + uid + "_" + year + "-" + month,
             data: year + "-" + month,
             onclick: "toggleMonth(this)"
           }, calendar_months[month - 1]);
@@ -69,6 +78,7 @@ Calendar = (function() {
     /* Return a combined div */
     div = new HTML('div', {
       "class": "calendar",
+      id: uid,
       data: sYear + "-" + eYear
     }, years);
     return div;
@@ -81,25 +91,35 @@ Calendar = (function() {
 toggleYear = function(div) {
 
   /* Get the start and end year from the parent div */
-  var eYear, j, ref, ref1, ref2, results, sYear, y, year;
+  var eYear, j, ref, ref1, ref2, results, sYear, uid, y, year;
   ref = div.parentNode.getAttribute('data').split("-"), sYear = ref[0], eYear = ref[1];
 
   /* Get the year we clicked on */
   year = parseInt(div.getAttribute("data"));
+  uid = div.parentNode.getAttribute("id");
 
   /* For each year, hide if not this year, else show */
   results = [];
   for (y = j = ref1 = parseInt(sYear), ref2 = parseInt(eYear); ref1 <= ref2 ? j <= ref2 : j >= ref2; y = ref1 <= ref2 ? ++j : --j) {
     if (y === year) {
-      results.push(get('calendar_months_' + y).show(true));
+      results.push(get("calendar_months_" + uid + "_" + y).show(true));
     } else {
-      results.push(get('calendar_months_' + y).show(false));
+      results.push(get("calendar_months_" + uid + "_" + y).show(false));
     }
   }
   return results;
 };
 
-toggleMonth = function(div) {};
+toggleMonth = function(div) {
+  var m, month, ref, year;
+  m = div.getAttribute("data");
+  ref = m.split("-"), year = ref[0], month = ref[1];
+
+  /* Update the list view using the new month */
+  return listView({
+    month: m
+  });
+};
 
 
 /*
@@ -434,6 +454,51 @@ cog = function(div, size) {
 
 
 /**
+ * Pending URLs watcher:
+ * Wathes which URLs have been pending a result for a while
+ * and shows the spinner if things are taking too long.
+ */
+
+pending_url_operations = {};
+
+pendingURLStatus = function() {
+  var div, now, pending, time, url;
+  pending = 0;
+  now = new Date().getTime();
+  for (url in pending_url_operations) {
+    time = pending_url_operations[url];
+
+    /* Is something taking too long?? */
+    if ((now - time) > 1500) {
+      pending++;
+      div = get('loading');
+      if (!div) {
+        div = new HTML('div', {
+          "class": "spinner"
+        }, [
+          new HTML('img', {
+            src: "images/spinner.gif"
+          }), new HTML('br'), "Loading, please wait..."
+        ]);
+        document.body.inject(div);
+      }
+      div.style.display = "block";
+    }
+  }
+
+  /* If no pending operations, hide the spnner */
+  if (pending === 0) {
+    div = get('loading');
+    if (div) {
+      return div.style.display = "none";
+    }
+  }
+};
+
+window.setInterval(pendingURLStatus, 500);
+
+
+/**
  * HTTPRequest: Fire off a HTTP request.
  * Args:
  * - url: The URL to request (may be relative or absolute)
@@ -460,10 +525,10 @@ cog = function(div, size) {
  */
 
 HTTPRequest = (function() {
-  function HTTPRequest(url, args) {
+  function HTTPRequest(url1, args1) {
     var tmp;
-    this.url = url;
-    this.args = args;
+    this.url = url1;
+    this.args = args1;
 
     /* Set internal class data, determine request type */
     this.state = this.args.state;
@@ -474,6 +539,7 @@ HTTPRequest = (function() {
     this.callback = this.args.callback;
     this.snap = this.args.snap || pm_snap;
     this.nocreds = this.args.nocreds || false;
+    this.uid = parseInt(Math.random() * 10000000).toString(16);
 
     /* Construct request object */
     if (window.XMLHttpRequest) {
@@ -513,6 +579,9 @@ HTTPRequest = (function() {
       }
     }
 
+    /* Mark operation as pending result */
+    pending_url_operations[this.uid] = new Date().getTime();
+
     /* Use @method on URL */
     this.request.open(this.method, this.url, true);
 
@@ -531,8 +600,13 @@ HTTPRequest = (function() {
 
   HTTPRequest.prototype.onchange = function() {
 
-    /* Internal Server Error: Try to call snap */
+    /* Mark operation as done */
     var e;
+    if (this.request.readyState === 4) {
+      delete pending_url_operations[this.uid];
+    }
+
+    /* Internal Server Error: Try to call snap */
     if (this.request.readyState === 4 && this.request.status === 500) {
       if (this.snap) {
         this.snap(this.state);
@@ -614,6 +688,109 @@ HTTPRequest = (function() {
 
 
 /**
+ * This is the listview basic library
+ */
+
+
+/* Generally, popping a window state should run a listView update */
+
+window.onpopstate = function(event) {
+  return listView(null, true);
+};
+
+listView = function(hash, reParse) {
+
+  /* Get the HTML filename */
+  var args, d, etc, htmlfile, ponymail_list, ponymail_month, ponymail_query, r, ref;
+  ref = location.href.split("?"), htmlfile = ref[0], etc = ref[1];
+
+  /* Do we need to call the URL parser here? */
+  if (reParse) {
+    parseURL();
+  }
+
+  /* Any new settings passed along? */
+  if (isHash(hash)) {
+    if (hash.month) {
+      ponymail_month = hash.month;
+    }
+    if (hash.list) {
+      ponymail_list = hash.list;
+    }
+    if (hash.query) {
+      ponymail_query = hash.query;
+    }
+  }
+
+  /* First, check that we have a list to view! */
+  if (!(ponymail_list && ponymail_list.match(/.+@.+/))) {
+
+    /* Do we at least have a domain part? */
+    if (ponymail_list && ponymail_list.match(/.+?\..+/)) {
+
+      /* Check if there's a $default list in this domain */
+      d = ponymail_list;
+
+      /* Do we have this domain listed? If not, redirect to front page */
+      if (!ponymail_domains[d]) {
+        location.href = "./";
+        return;
+      }
+      if (ponymail_domains[d] && ponymail_domains[d][pm_config.default_list]) {
+
+        /* Redirect to this list then ... */
+        location.href = htmlfile + "?" + pm_config.default_list + "@" + d;
+        return;
+      }
+    } else {
+
+      /* No domain specified, redirect to front page */
+      location.href = "./";
+      return;
+    }
+  }
+
+  /* Construct arg list for URL */
+  args = "";
+  if (ponymail_list && ponymail_list.length > 0) {
+    args += ponymail_list;
+  }
+  if (ponymail_month && ponymail_month.length > 0) {
+    args += ":" + ponymail_month;
+  }
+  if (ponymail_query && ponymail_query.length > 0) {
+    args += ":" + ponymail_query;
+  }
+
+  /* Push a new history state using new args */
+  window.history.pushState({}, "", htmlfile + "?" + args);
+
+  /* Request month view from API, send to list view callback */
+  return r = new HTTPRequest("api/stats.lua?list=" + ponymail_list + "&d=" + ponymail_month, {
+    callback: renderListView
+  });
+};
+
+
+/*
+ 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)
  */
@@ -728,6 +905,87 @@ isHash = function(value) {
   return value && typeof value === 'object' && !isArray(value);
 };
 
+
+/*
+ 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.
+ */
+
+
+/* This is the basic scaffolding for all pages */
+
+listviewScaffolding = function() {
+
+  /* Start off by making the top menu */
+  var cal, calHolder, header, item, j, len, li, listDiv, logo, mainDiv, menu, ref, ul;
+  menu = new HTML('div', {
+    id: "topMenu"
+  });
+  document.body.inject(menu);
+  ul = new HTML('ul');
+  logo = new HTML('li', {
+    "class": 'logo'
+  }, new HTML('a', {
+    href: "./"
+  }, new HTML('img', {
+    src: "images/logo.png",
+    style: {
+      paddingRight: "10px",
+      height: "38px",
+      width: "auto"
+    }
+  })));
+  ul.inject(logo);
+  ref = ['Home', 'Lists', 'Third item'];
+  for (j = 0, len = ref.length; j < len; j++) {
+    item = ref[j];
+    li = new HTML('li', {}, item);
+    ul.inject(li);
+  }
+  menu.inject(ul);
+
+  /* Now, make the base div */
+  mainDiv = new HTML('div', {
+    id: "contents"
+  });
+  document.body.inject(mainDiv);
+
+  /* Make the title */
+  header = new HTML('h2', {
+    id: "header"
+  }, "Loading list data...");
+  mainDiv.inject(header);
+
+  /* Then make the calendar placeholder */
+  calHolder = new HTML('div', {
+    id: "calendar"
+  });
+  mainDiv.inject(calHolder);
+
+  /* TEST: Insert fake calendar */
+  cal = new Calendar(2010);
+  calHolder.inject(cal);
+
+  /* Finally, make the list view placeholder */
+  listDiv = new HTML('div', {
+    id: "listview",
+    "class": "sbox"
+  });
+  return mainDiv.inject(listDiv);
+};
+
 testCoffee = function() {
 
   /* Get main div from HTML */
@@ -762,7 +1020,7 @@ testCoffee = function() {
     "class": "sbox"
   });
   parent.inject(div);
-  cal = new Calendar('2010-5', '2016-9');
+  cal = new Calendar(2010, '2016-9');
   div.inject(cal);
   p = new HTML('p', {
     "class": "foo",