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 17:51:14 UTC

[4/4] incubator-ponymail git commit: test out the calendar

test out the calendar


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

Branch: refs/heads/coffee-and-cake
Commit: 621eed5c5f8037e1fa309934decac3ffa6b999b5
Parents: 595b295
Author: Daniel Gruno <hu...@apache.org>
Authored: Fri Sep 2 19:50:54 2016 +0200
Committer: Daniel Gruno <hu...@apache.org>
Committed: Fri Sep 2 19:50:54 2016 +0200

----------------------------------------------------------------------
 site/js/coffee/test.coffee |  12 ++++-
 site/js/ponymail-coffee.js | 117 ++++++++++++++++++++++++++++++++++++++--
 2 files changed, 122 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/621eed5c/site/js/coffee/test.coffee
----------------------------------------------------------------------
diff --git a/site/js/coffee/test.coffee b/site/js/coffee/test.coffee
index ecf94a4..492dfed 100644
--- a/site/js/coffee/test.coffee
+++ b/site/js/coffee/test.coffee
@@ -30,11 +30,19 @@ testCoffee = () ->
         ul.inject(li)
     menu.inject(ul)
     
+    # Make a div
+    div = new HTML('div', { class: "sbox"})
+    parent.inject(div)
+    
+    # Make a calendar test
+    cal = new Calendar('2010-5', '2016-9')
+    div.inject(cal)
+    
     # Make a paragraph with some text in it
-    p = new HTML('p', { class: "sbox", style: { textAlign: 'center'}}, "Text goes here")
+    p = new HTML('p', { class: "foo", style: { textAlign: 'center'}}, "Text goes here")
     
     # Inject paragraph into div
-    parent.inject(p)
+    div.inject(p)
     
     # Add some plain text and a break
     p.inject([". Here's a textNode added afterwards", new HTML('br')])

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/621eed5c/site/js/ponymail-coffee.js
----------------------------------------------------------------------
diff --git a/site/js/ponymail-coffee.js b/site/js/ponymail-coffee.js
index 7906288..3f4a7df 100644
--- a/site/js/ponymail-coffee.js
+++ b/site/js/ponymail-coffee.js
@@ -1,4 +1,106 @@
 // 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;
+
+calendar_months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
+
+
+/**
+ * Calendar: Make a HTML calendar with years and months
+ * that expands/contracts. For the left side view.
+ * Usage: cal = new Calendar('2001-2', '2016-9', 2010)
+ * Would make a calendar going from 2001 to 2016 with 2010 expanded.
+ */
+
+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;
+    now = new Date();
+
+    /* Split start and end into years and months */
+    ref = 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];
+    }
+
+    /* 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,
+        data: String(year),
+        "class": "calendar_year",
+        onclick: "toggleYear(this);"
+      }, String(year));
+
+      /* Construct the placeholder for months */
+
+      /* Hide unless active year */
+      monthsDiv = new HTML('div', {
+        style: {
+          display: (jumpTo && jumpTo === year) || (!jumpTo && year === parseInt(eYear)) ? "block" : "none"
+        },
+        "class": "calendar_months",
+        id: "calendar_months_" + year
+      });
+
+      /* For each month, make a div */
+      for (month = m = 12; m >= 1; month = --m) {
+
+        /* 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}",
+            data: year + "-" + month,
+            onclick: "toggleMonth(this)"
+          }, calendar_months[month - 1]);
+          monthsDiv.inject(monthDiv);
+        }
+      }
+
+      /* unshift year into the div list (thus reverse order) */
+      years.unshift(monthsDiv);
+      years.unshift(yDiv);
+    }
+
+    /* Return a combined div */
+    div = new HTML('div', {
+      "class": "calendar",
+      data: sYear + "-" + eYear
+    }, years);
+    return div;
+  }
+
+  return Calendar;
+
+})();
+
+toggleYear = function(div) {
+
+  /* Get the start and end year from the parent div */
+  var eYear, j, ref, ref1, ref2, results, sYear, 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"));
+
+  /* For each year, hide if not this year, else show */
+  results = [];
+  for (y = j = ref1 = sYear, ref2 = eYear; ref1 <= ref2 ? j <= ref2 : j >= ref2; y = ref1 <= ref2 ? ++j : --j) {
+    if (y === year) {
+      results.push(get('calendar_months_' + y).show(true));
+    } else {
+      results.push(get('calendar_months_' + y).show(false));
+    }
+  }
+  return results;
+};
+
+toggleMonth = function(div) {};
+
 
 /*
  Licensed to the Apache Software Foundation (ASF) under one or more
@@ -16,7 +118,6 @@
  See the License for the specific language governing permissions and
  limitations under the License.
  */
-var HTML, HTTPRequest, cog, dbRead, dbWrite, e, genColors, get, hsl2rgb, isArray, isHash, pm_storage_available, pm_storage_globvar, set, testCoffee, testToggle, txt;
 
 hsl2rgb = function(h, s, l) {
   var fract, min, sh, sv, switcher, v, vsf;
@@ -201,7 +302,7 @@ HTML = (function() {
             } else {
 
               /* Plain element, add normally */
-              this.element.inject(k);
+              this.element.inject(child);
             }
           }
         } else {
@@ -630,7 +731,7 @@ isHash = function(value) {
 testCoffee = function() {
 
   /* Get main div from HTML */
-  var hider, item, j, len, li, logo, menu, p, parent, ref, ul;
+  var cal, div, hider, item, j, len, li, logo, menu, p, parent, ref, ul;
   parent = get('testdiv');
   menu = new HTML('div', {
     id: "topMenu"
@@ -657,13 +758,19 @@ testCoffee = function() {
     ul.inject(li);
   }
   menu.inject(ul);
+  div = new HTML('div', {
+    "class": "sbox"
+  });
+  parent.inject(div);
+  cal = new Calendar('2010-5', '2016-9');
+  div.inject(cal);
   p = new HTML('p', {
-    "class": "sbox",
+    "class": "foo",
     style: {
       textAlign: 'center'
     }
   }, "Text goes here");
-  parent.inject(p);
+  div.inject(p);
   p.inject([". Here's a textNode added afterwards", new HTML('br')]);
   hider = new HTML('b', {
     onclick: 'testToggle(this);'