2012-03-13 17:21:32 +00:00
|
|
|
#= require_self
|
|
|
|
#= require flowerbox/result
|
|
|
|
#= require flowerbox/exception
|
|
|
|
#
|
2012-03-02 18:28:52 +00:00
|
|
|
Flowerbox =
|
|
|
|
baseUrl: '/'
|
2012-03-14 17:07:13 +00:00
|
|
|
debug: false
|
2012-03-13 17:21:32 +00:00
|
|
|
ping: ->
|
|
|
|
Flowerbox.contact('ping')
|
2012-03-15 00:32:01 +00:00
|
|
|
working: false
|
2012-03-13 17:21:32 +00:00
|
|
|
|
2012-03-02 18:28:52 +00:00
|
|
|
contact: (url, data...) ->
|
2012-03-14 17:07:13 +00:00
|
|
|
if !Flowerbox.debug
|
2012-03-15 00:32:01 +00:00
|
|
|
Flowerbox.contactQueue ||= []
|
2012-03-13 17:21:32 +00:00
|
|
|
|
2012-03-15 00:32:01 +00:00
|
|
|
Flowerbox.contactQueue.push([url, data])
|
|
|
|
Flowerbox.workOffQueue()
|
2012-03-13 17:21:32 +00:00
|
|
|
|
2012-03-15 00:32:01 +00:00
|
|
|
workOffQueue: ->
|
|
|
|
if !Flowerbox.working
|
|
|
|
Flowerbox.working = true
|
|
|
|
Flowerbox.doWorkOffQueue()
|
|
|
|
|
|
|
|
doWorkOffQueue: ->
|
|
|
|
if Flowerbox.contactQueue.length > 0
|
|
|
|
[ url, data ] = Flowerbox.contactQueue.shift()
|
|
|
|
|
|
|
|
xhr = new XMLHttpRequest()
|
|
|
|
xhr.open("POST", Flowerbox.baseUrl + url, true)
|
|
|
|
xhr.setRequestHeader("Accept", "application/json")
|
|
|
|
xhr.onreadystatechange = ->
|
|
|
|
if @readyState == @DONE
|
|
|
|
Flowerbox.doWorkOffQueue()
|
|
|
|
xhr.send(JSON.stringify(data))
|
|
|
|
else
|
|
|
|
Flowerbox.working = false
|
2012-03-13 17:21:32 +00:00
|
|
|
|
2012-03-03 16:28:03 +00:00
|
|
|
fail: ->
|
2012-03-13 17:21:32 +00:00
|
|
|
|