Added queueing support.

This commit is contained in:
Martin Edenhofer 2012-11-26 06:06:05 +01:00
parent cc5a4f79fb
commit f496f82669

View file

@ -19,11 +19,16 @@ class _Singleton
cache: false cache: false
async: true async: true
queue_list: {} current_request: {}
queue_list: []
queue_running: false
count: 0 count: 0
constructor: (@args) -> constructor: (@args) ->
# run queue
@_run()
# bindings # bindings
$('body').bind( 'ajaxSend', => $('body').bind( 'ajaxSend', =>
@_show_spinner() @_show_spinner()
@ -57,16 +62,28 @@ class _Singleton
) )
) )
ajax: (params, defaults) -> ajax: (params) ->
data = $.extend({}, @defaults, defaults, params) data = $.extend({}, @defaults, params )
if params['id'] if params['id']
if @queue_list[ params['id'] ] if @current_request[ params['id'] ]
@queue_list[ params['id'] ].abort() @current_request[ params['id'] ].abort()
@queue_list[ params['id'] ] = $.ajax( data ) @current_request[ params['id'] ] = $.ajax( data )
else else
$.ajax( data ) if params['queue']
@queue_list.push data
if !@queue_running
@_run()
else
$.ajax(data)
# console.log('AJAX', params['url'] ) _run: =>
if @queue_list && @queue_list[0]
@queue_running = true
request = @queue_list.shift()
request.complete = =>
@queue_running = false
@_run()
$.ajax( request )
_show_spinner: => _show_spinner: =>
@count++ @count++