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/05 08:50:04 UTC

[2/3] incubator-ponymail git commit: add a SingleListView mode, make it default for now

add a SingleListView mode, make it default for now

this shows email as single entities, not threaded.
extends the BasicListView.


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

Branch: refs/heads/coffee-and-cake
Commit: c7f5104e8b212bddbbd82da5eab2be8c9a30fb80
Parents: 5b5382b
Author: Daniel Gruno <hu...@apache.org>
Authored: Mon Sep 5 10:49:42 2016 +0200
Committer: Daniel Gruno <hu...@apache.org>
Committed: Mon Sep 5 10:49:42 2016 +0200

----------------------------------------------------------------------
 site/js/coffee/listview.coffee              |   2 +-
 site/js/coffee/listview_single_email.coffee | 122 +++++++++++++++++++++++
 2 files changed, 123 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/c7f5104e/site/js/coffee/listview.coffee
----------------------------------------------------------------------
diff --git a/site/js/coffee/listview.coffee b/site/js/coffee/listview.coffee
index cbc1e65..f052e50 100644
--- a/site/js/coffee/listview.coffee
+++ b/site/js/coffee/listview.coffee
@@ -133,5 +133,5 @@ renderListView = (json, state) ->
         cal = new Calendar(json.firstYear, json.lastYear, ponymail_month)
         get('calendar').empty().inject(cal)
         
-    lv = new BasicListView(json)
+    lv = new SingleListView(json)
     
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/c7f5104e/site/js/coffee/listview_single_email.coffee
----------------------------------------------------------------------
diff --git a/site/js/coffee/listview_single_email.coffee b/site/js/coffee/listview_single_email.coffee
new file mode 100644
index 0000000..8b8ed2f
--- /dev/null
+++ b/site/js/coffee/listview_single_email.coffee
@@ -0,0 +1,122 @@
+###
+ 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.
+###
+
+###*
+# Single email list view - extends BasicListView
+###
+class SingleListView extends BasicListView
+    ### json: from stats.lua, rpp = results per page, pos = starting position (from 0) ###
+    constructor: (@json, @rpp = 15, @pos = 0) ->
+        
+        ### Set the header first ###
+        hd = get('header')
+        if @json.list
+            if ponymail_month.length > 0
+                [y, m] = ponymail_month.split("-", 2)
+                date = calendar_months[parseInt(m)-1] + ", #{y}"
+                hd.empty().inject([
+                    "#{@json.list} (#{date}):",
+                    new HTML('a', { href: "api/mbox.lua?list=#{ponymail_list}&date=#{ponymail_month}", title: "Download as mbox archive"},
+                        new HTML('img', { src: 'images/floppy.svg', style: {marginLeft: "10px", width:"20px", height: "20px", verticalAlign: 'middle'}} )
+                    )
+                    ])
+                
+            else    
+                hd.empty().inject("#{@json.list}, past 30 days:")
+            
+        ### Get and clear the list view ###
+        @lv = get('listview')
+        @lv = @lv.empty()
+        
+        ### Set some internal vars ###
+        @listsize = 0
+        
+        ### If we got results, use scroll() to display from result 0 on ###
+        if isArray(@json.emails) and @json.emails.length > 0
+            
+            ### Set some internal vars ###
+            @listsize = @json.emails.length
+        
+            ### Reverse thread struct, but only if we're not using an
+            # already reversed cache ###
+            if not @json.cached
+                @json.emails.reverse()
+            @scroll(@rpp, @pos)
+        else
+            ### No results, just say...that ###
+            @lv.inject("No emails found matching this criterion.")
+        
+        
+        # set current list view to this class
+        ponymail_current_listview = this
+        return this
+    
+    renderItems: () ->
+        ### For each email result,...###
+        lvitems = new HTML('div', { class: "listview_table" })
+        for original in @json.emails[@pos...(@pos+@rpp)]
+            ### Be sure we actually have an email here ###
+            if original
+                ### Call listViewItem to compile a list view HTML element ###
+                item = @listViewItem(original, null)
+                
+                ### Inject new item into the list view ###
+                lvitems.inject(item)
+        @lv.inject(lvitems)
+        
+    listViewItem: (original, thread) ->
+        ### Be sure we actually have an email here ###
+        if original
+            now = new Date().getTime()/1000
+            
+            ### Render the email in the LV ###
+            
+            ### First set some data points for later ###
+            uid = parseInt(Math.random() * 999999999999).toString(16)
+            
+            
+            ### Gravatar ###
+            avatar = new HTML('img', { class: "gravatar", src: "https://secure.gravatar.com/avatar/#{original.gravatar}.png?s=24&r=g&d=mm"})
+            
+            ### Sender, without the <fo...@bar> part - just the name ###
+            sender = new HTML('div', {style: {fontWeight: "bold"}}, original.from.replace(/\s*<.+>/, "").replace(/"/g, ''))
+            
+            ### readStyle: bold if new email, normal if read before ###
+            readStyle = "bold"
+            if hasRead(original.id)
+                readStyle = "normal"
+                
+            ### Subject, PLUS a bit of the body with a break before ###
+            subject = new HTML('div', {}, [
+                new HTML('a', { style: {fontWeight: readStyle}, href: "thread.html/#{original.id}", onclick: "readEmail(this.parentNode.parentNode.parentNode); return false;"}, original.subject),
+            ])
+            
+            
+            ### Add date; yellow if <= 1day, grey otherwise ###
+            date_style = "listview_grey"
+            if (now-86400*4) < original.epoch
+                date_style = "listview_yellow"
+            date = new HTML('div', {class:"listview_right #{date_style}"}, new Date(original.epoch*1000).ISOBare())
+            
+            
+            ### Finally, pull it all together in a div and add that to the listview ###
+            item = new HTML('div', {id: uid, data: original.id, class: "listview_item"},
+                            new HTML('div', {class:"listview_summary"}, [avatar, sender, subject, date])
+                            )
+            return item
+        
+                
\ No newline at end of file