ponymail-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From humbed...@apache.org
Subject [10/12] incubator-ponymail git commit: start work on a basic listview class
Date Sat, 03 Sep 2016 07:45:58 GMT
start work on a basic listview class

this is meant to be extended/cloned by other listview
styles later on.


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

Branch: refs/heads/coffee-and-cake
Commit: 40736a6cb033a14c3a187824944fb646cadcc4d7
Parents: 496d7b4
Author: Daniel Gruno <humbedooh@apache.org>
Authored: Sat Sep 3 09:44:48 2016 +0200
Committer: Daniel Gruno <humbedooh@apache.org>
Committed: Sat Sep 3 09:44:48 2016 +0200

----------------------------------------------------------------------
 site/js/coffee/listview_basic.coffee | 93 +++++++++++++++++++++++++++++++
 1 file changed, 93 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/40736a6c/site/js/coffee/listview_basic.coffee
----------------------------------------------------------------------
diff --git a/site/js/coffee/listview_basic.coffee b/site/js/coffee/listview_basic.coffee
new file mode 100644
index 0000000..005ccdc
--- /dev/null
+++ b/site/js/coffee/listview_basic.coffee
@@ -0,0 +1,93 @@
+###
+ 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.
+###
+
+###*
+# Basic listview class, to be extended by other designs
+###
+class BasicListView
+    ### json: from stats.lua, rpp = results per page, pos = starting position (from 0) ###
+    constructor: (@json, @rpp = 15, @pos = 0) ->
+        
+        ### Get and clear the list view ###
+        @lv = get('listview')
+        @lv = @lv.empty()
+        
+        ### If we got results, use scroll() to display from result 0 on ###
+        if isArray(@json.thread_struct) and @json.thread_struct.length > 0
+            @scroll(@rpp, @pos)
+        else
+            ### No results, just say...that ###
+            @lv.inject("No emails found matching this criterion.")
+            
+            
+    ### scroll: scroll to a position and show N emails/threads ###
+    scroll: (rpp, pos) ->
+        ### Clear the list view ###
+        @lv = @lv.empty()
+        
+        ### For each email result,...###
+        for item in @json.thread_struct
+            original = @findEmail(item.tid)
+            
+            ### Be sure we actually have an email here ###
+            if original
+                people = @countPeople(item)
+                noeml = @countEmail(item)
+                
+                ### Render the email in the LV ###
+                item = new HTML('div', {class: "listview_item"}, "#{original.subject} - #{people}
and #{noeml} replies.")
+                @lv.inject(item)
+    
+    ### findEmail: find an email given an ID ###
+    findEmail: (id) ->
+        for email in @json.emails
+            if email.id == id
+                return email
+        return null
+    
+    ### countEmail: func for counting how many emails are in a thread ###
+    countEmail: (thread) ->
+        n = 0
+        if thread.children
+            for item in (if isArray(thread.children) then thread.children else [])
+                n++
+                if isArray(item.children) and item.children.length > 0
+                    n += @countEmail(item.children)
+        return n
+    
+    ### countPeople: func for counting how many people are in a thread ###
+    countPeople: (thread, p) ->
+        np = p || {}
+        n = 0
+        if thread.tid
+            eml = @findEmail(thread.tid)
+            if eml
+                np[eml.from] = true
+                for item in (if isArray(thread.children) then thread.children else [])
+                    t = item.tid
+                    email = @findEmail(t)
+                    if email
+                        np[email.from] = true
+                    if isArray(item.children) and item.children.length > 0
+                        np = @countPeople(item.children, np)
+        if p
+            return np
+        else
+            for k,v of np
+                n++
+            return n
+        
\ No newline at end of file


Mime
View raw message