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/04 16:24:18 UTC
[2/6] incubator-ponymail git commit: Move list view item generation
to own func, add scrolling
Move list view item generation to own func, add scrolling
Simplifying extending this class by moving the list view
item generation to its own function (which can then be modified
separately). Also enabling the mouse scroll feature and adding
buttons to next/prev page of emails.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/commit/1d76d320
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/tree/1d76d320
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/diff/1d76d320
Branch: refs/heads/coffee-and-cake
Commit: 1d76d320cf415d4831c199d32b2d5744f4c836b3
Parents: 0dcb7b5
Author: Daniel Gruno <hu...@apache.org>
Authored: Sun Sep 4 17:45:01 2016 +0200
Committer: Daniel Gruno <hu...@apache.org>
Committed: Sun Sep 4 17:45:01 2016 +0200
----------------------------------------------------------------------
site/js/coffee/listview_basic.coffee | 183 ++++++++++++++++++++++--------
1 file changed, 133 insertions(+), 50 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/1d76d320/site/js/coffee/listview_basic.coffee
----------------------------------------------------------------------
diff --git a/site/js/coffee/listview_basic.coffee b/site/js/coffee/listview_basic.coffee
index c61dc2b..7f956bd 100644
--- a/site/js/coffee/listview_basic.coffee
+++ b/site/js/coffee/listview_basic.coffee
@@ -52,77 +52,84 @@ class BasicListView
else
### No results, just say...that ###
@lv.inject("No emails found matching this criterion.")
-
+
+ ### Set some internal vars ###
+ @listsize = @json.thread_struct.length
+
+ # set current list view to this class
+ ponymail_current_listview = this
+ return this
### scroll: scroll to a position and show N emails/threads ###
scroll: (rpp, pos) ->
@lastScroll = new Date().getTime()
- now = new Date().getTime()/1000
### Clear the list view ###
@lv = @lv.empty()
+ topButtons = null
- ### Make some pre-defined html object templates ###
- peopleimg = new HTML('img', {src: 'images/avatar.png', style: { verticalAlign: 'middle', width: "12px", height: "12px"}})
- envelopeimg = new HTML('img', {src: 'images/envelope.png', style: { verticalAlign: 'middle', width: "16px", height: "12px"}})
+ @rpp = rpp
+ @pos = pos
+ ### First, build the prev/next buttons if needed ###
+ if pos > 0 or (pos+rpp) < @json.thread_struct.length
+ topButtons = new HTML('div', { style: {float: "left", width: "100%"}})
+ ## Prev button
+ if pos > 0
+ pno = Math.min(rpp, pos)
+ pp = Math.max(0, pos-rpp)
+ pbutton = new HTML('input', {
+ type: 'button'
+ value: 'Previous ' + pno + " message" + (if pno == 1 then '' else 's')
+ onclick: "ponymail_current_listview.scroll(#{rpp}, #{pp});"
+ class: "listview_button_green"
+ style: { float: "left" }
+ })
+ topButtons.inject(pbutton)
+ ### Next button ###
+ if (pos+rpp) < @json.thread_struct.length
+ nno = Math.min(rpp, @json.thread_struct.length - pos - rpp)
+ np = pos+rpp
+ nbutton = new HTML('input', {
+ type: 'button'
+ value: 'Next ' + nno + " message" + (if nno == 1 then '' else 's')
+ onclick: "ponymail_current_listview.scroll(#{rpp}, #{np});"
+ class: "listview_button_green"
+ style: { float: "right" }
+ })
+ topButtons.inject(nbutton)
+ @lv.inject(topButtons)
+
### For each email result,...###
for item in @json.thread_struct[pos...(pos+rpp)]
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 ###
-
- ### 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, ''))
+ ### Call listViewItem to compile a list view HTML element ###
+ item = @listViewItem(original, item)
- ### readStyle: bold if new email, normal if read before ###
- readStyle = "bold"
- if hasRead(item.tid)
- 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/#{item.tid}", onclick: "readEmail(this.parentNode.parentNode); return false;"}, original.subject),
- new HTML('br'),
- new HTML('span', { style: { color: "#999", fontSize: "0.7rem"}}, item.body)
- ])
-
- ### show number of replies and participants ###
- stats = new HTML('div', {class:"listview_right"}, [
- peopleimg.cloneNode(),
- " #{people} ",
- envelopeimg.cloneNode(),
- " #{noeml}"
- ])
-
- ### Add date; yellow if <= 1day, grey otherwise ###
- date_style = "listview_grey"
- if (now-86400*4) < item.epoch
- date_style = "listview_yellow"
- date = new HTML('div', {class:"listview_right #{date_style}"}, new Date(item.epoch*1000).ISOBare())
-
-
- ### Finally, pull it all together in a div and add that to the listview ###
- item = new HTML('div', {id: uid, data: item.tid, class: "listview_item"}, [avatar, sender, subject, date, stats])
+ ### Inject new item into the list view ###
@lv.inject(item)
+ ### If we made buttons, clone them at the bottom ###
+ if topButtons
+ @lv.inject(topButtons.cloneNode(true))
+
now = new Date().getTime()
diff = now - @lastScroll
if @json.cached
@lv.inject("Fetched from cache (no updates detected), rendered in " + parseInt(diff) + "ms.")
else
@lv.inject("Fetched in " + parseInt(@json.took/1000) + "ms, rendered in " + parseInt(diff) + "ms.")
+
+ tmpthis = this
+ ### Finally, enable scrolling ###
+ @lv.addEventListener("mousewheel", (e) ->
+ tmpthis.swipe(e)
+ , false);
+ @lv.addEventListener("DOMMouseScroll", (e) ->
+ tmpthis.swipe(e)
+ , false);
+
### findEmail: find an email given an ID ###
findEmail: (id) ->
for email in @json.emails
@@ -161,4 +168,80 @@ class BasicListView
for k,v of np
n++
return n
-
\ No newline at end of file
+
+ listViewItem: (original, thread) ->
+ ### Be sure we actually have an email here ###
+ if original and thread
+ now = new Date().getTime()/1000
+
+ ### Gather stats ###
+ people = @countPeople(thread)
+ noeml = @countEmail(thread)
+
+ ### 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(thread.tid)
+ 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/#{thread.tid}", onclick: "readEmail(this.parentNode.parentNode); return false;"}, original.subject),
+ new HTML('br'),
+ new HTML('span', {class: "listview_item_body"}, thread.body)
+ ])
+
+ ### show number of replies and participants ###
+ peopleimg = new HTML('img', {src: 'images/avatar.png', style: { verticalAlign: 'middle', width: "12px", height: "12px"}})
+ envelopeimg = new HTML('img', {src: 'images/envelope.png', style: { verticalAlign: 'middle', width: "16px", height: "12px"}})
+ stats = new HTML('div', {class:"listview_right"}, [
+ peopleimg,
+ " #{people} ",
+ envelopeimg,
+ " #{noeml}"
+ ])
+
+ ### Add date; yellow if <= 1day, grey otherwise ###
+ date_style = "listview_grey"
+ if (now-86400*4) < thread.epoch
+ date_style = "listview_yellow"
+ date = new HTML('div', {class:"listview_right #{date_style}"}, new Date(thread.epoch*1000).ISOBare())
+
+
+ ### Finally, pull it all together in a div and add that to the listview ###
+ item = new HTML('div', {id: uid, data: thread.tid, class: "listview_item"}, [avatar, sender, subject, date, stats])
+ return item
+
+ ### swipe: go to next or previous page of emails, depending on mouse wheel direction ###
+ swipe: (e) ->
+ direction = if ((e.wheelDelta || -e.detail) < 0) then 'down' else 'up'
+ style = document.body.currentStyle || window.getComputedStyle(document.body, "")
+
+ ### Use the footer to determine whether scrollbar is present or not ###
+ obj = get('footer').getBoundingClientRect()
+ scrollBar = window.innerHeight < obj.bottom
+
+ ### Abort swiping if an email is open or scrollbar is present ###
+ if ponymail_email_open or scrollBar
+ return
+
+ if direction == 'down'
+ ### Next page? ###
+ if @listsize > (@pos+@rpp+1)
+ @scroll(@rpp, @pos+@rpp)
+ else if direction == 'up'
+ ### Previous page? ###
+ if @pos > 0
+ @scroll(@rpp, Math.max(0,@pos-@rpp))
+
\ No newline at end of file