ponymail-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From humbed...@apache.org
Subject [2/4] incubator-ponymail git commit: Add a calendar object
Date Fri, 02 Sep 2016 17:51:12 GMT
Add a calendar object


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

Branch: refs/heads/coffee-and-cake
Commit: 1a19fb9d9e82f80313d1fe35e58c66b902b5eebd
Parents: cb60afc
Author: Daniel Gruno <humbedooh@apache.org>
Authored: Fri Sep 2 19:49:01 2016 +0200
Committer: Daniel Gruno <humbedooh@apache.org>
Committed: Fri Sep 2 19:49:01 2016 +0200

----------------------------------------------------------------------
 site/css/ponymail2.css         | 39 +++++++++++++++-
 site/js/coffee/calendar.coffee | 93 +++++++++++++++++++++++++++++++++++++
 2 files changed, 131 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/1a19fb9d/site/css/ponymail2.css
----------------------------------------------------------------------
diff --git a/site/css/ponymail2.css b/site/css/ponymail2.css
index 7fb365c..846f4b2 100644
--- a/site/css/ponymail2.css
+++ b/site/css/ponymail2.css
@@ -75,4 +75,41 @@ body, html {
     border-radius: 2px;
     font-family: sans-serif;
     font-size:  9pt;
-}
\ No newline at end of file
+}
+
+
+
+/* Calendars */
+
+.calendar_year {
+    background: #77D32C;
+    border-radius: 4px;
+    color: #000;
+    width: 110px;
+    text-align: center;
+    border: 1px solid #666;
+}
+
+.calendar_year:hover {
+    background: #80E52D;
+    cursor: pointer;
+}
+
+
+.calendar_month {
+    background: #8CB9CE;
+    border-radius: 4px;
+    color: #000;
+    margin-left: 5px;
+    width: 100px;
+    text-align: center;
+    border: 1px solid #666;
+}
+
+
+.calendar_month:hover {
+    background: #99BCDB;
+    cursor: pointer;
+}
+
+

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/1a19fb9d/site/js/coffee/calendar.coffee
----------------------------------------------------------------------
diff --git a/site/js/coffee/calendar.coffee b/site/js/coffee/calendar.coffee
new file mode 100644
index 0000000..00c09fa
--- /dev/null
+++ b/site/js/coffee/calendar.coffee
@@ -0,0 +1,93 @@
+calendar_months = [
+    'January',
+    'February',
+    'March',
+    'April',
+    'May',
+    'June',
+    'July',
+    'August',
+    'September',
+    'October',
+    'November',
+    'December'
+    ]
+
+class Calendar
+    constructor: (start, end, jumpTo) ->
+        now = new Date()
+        
+        ### Split start and end into years and months ###
+        [sYear, sMonth] = start.split("-")
+        
+        [eYear, eMonth] = [now.getFullYear(), now.getMonth()+1]
+        
+        ### If end year+month given, use it ###
+        if end
+            [eYear, eMonth] = end.split("-")
+        
+        ### For each year, construct the year div to hold months ###
+        years = []
+        for year in [parseInt(sYear)..parseInt(eYear)]
+            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: if (jumpTo and jumpTo == year) or
+                        (not jumpTo and year == parseInt(eYear))
+                    then "block"
+                    else "none",
+                }
+                class: "calendar_months"
+                id: "calendar_months_" + year
+            })
+            
+            ### For each month, make a div ###
+            for month in [12..1]
+                ### Make sure this is within the start<->end range ###
+                if (year > sYear or month >= sMonth) and (year < eYear or 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
+    
+toggleYear = (div) ->
+    
+    ### Get the start and end year from the parent div ###
+    [sYear, eYear] = div.parentNode.getAttribute('data').split("-")
+    
+    ### Get the year we clicked on ###
+    year = parseInt(div.getAttribute("data"))
+        
+    ### For each year, hide if not this year, else show ###
+    for y in [sYear..eYear]
+        if y == year
+            get('calendar_months_' + y).show(true)
+        else
+            get('calendar_months_' + y).show(false)
+            
+toggleMonth = (div) ->
+    #### TODO later... ###
+    
\ No newline at end of file


Mime
View raw message