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 19:17:40 UTC
[2/7] incubator-ponymail git commit: add a spinner if things are
taking too long
add a spinner if things are taking too long
Project: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/commit/26a70978
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/tree/26a70978
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/diff/26a70978
Branch: refs/heads/coffee-and-cake
Commit: 26a709780672866742b12817453114b49a6c0731
Parents: c855509
Author: Daniel Gruno <hu...@apache.org>
Authored: Fri Sep 2 21:00:59 2016 +0200
Committer: Daniel Gruno <hu...@apache.org>
Committed: Fri Sep 2 21:00:59 2016 +0200
----------------------------------------------------------------------
site/js/coffee/http_utils.coffee | 49 +++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/26a70978/site/js/coffee/http_utils.coffee
----------------------------------------------------------------------
diff --git a/site/js/coffee/http_utils.coffee b/site/js/coffee/http_utils.coffee
index 3194a25..20daeaa 100644
--- a/site/js/coffee/http_utils.coffee
+++ b/site/js/coffee/http_utils.coffee
@@ -19,6 +19,44 @@
# This is http_utils.coffee: HTTP Request library #
####################################################
+
+###*
+# Pending URLs watcher:
+# Wathes which URLs have been pending a result for a while
+# and shows the spinner if things are taking too long.
+###
+pending_url_operations = {}
+
+pendingURLStatus = () ->
+ pending = 0
+ now = new Date().getTime()
+ for url, time of pending_url_operations
+ ### Is something taking too long?? ###
+ if (now - time) > 1500
+ pending++
+ div = get('loading')
+ if not div
+ div = new HTML('div', {
+ class: "spinner"
+ },
+ [
+ new HTML('img', {src: "images/spinner.gif"}),
+ new HTML('br'),
+ "Loading, please wait..."
+ ]
+ )
+ document.body.inject(div)
+ div.style.display = "block"
+
+ ### If no pending operations, hide the spnner ###
+ if pending == 0
+ div = get('loading')
+ if div
+ div.style.display = "none"
+
+window.setInterval(pendingURLStatus, 500)
+
+
###*
# HTTPRequest: Fire off a HTTP request.
# Args:
@@ -45,6 +83,7 @@
# })
###
+
class HTTPRequest
constructor: (@url, @args) ->
### Set internal class data, determine request type ###
@@ -56,6 +95,7 @@ class HTTPRequest
@callback = @args.callback
@snap = @args.snap || pm_snap
@nocreds = @args.nocreds || false
+ @uid = parseInt(Math.random()*10000000).toString(16)
### Construct request object ###
if window.XMLHttpRequest
@@ -87,6 +127,9 @@ class HTTPRequest
else
@url += "?" + tmp
+ ### Mark operation as pending result ###
+ pending_url_operations[@uid] = new Date().getTime()
+
### Use @method on URL ###
@request.open(@method, @url, true)
@@ -101,10 +144,16 @@ class HTTPRequest
### HTTPRequest state change calback ###
onchange: () ->
+
+ ### Mark operation as done ###
+ if @request.readyState == 4
+ delete pending_url_operations[@uid]
+
### Internal Server Error: Try to call snap ###
if @request.readyState == 4 and @request.status == 500
if @snap
@snap(@state)
+
### 200 OK, everything is okay, try to parse JSON response ###
if @request.readyState == 4 and @request.status == 200
if @callback