Improved AJAX bindung.

This commit is contained in:
Martin Edenhofer 2012-07-16 09:05:38 +02:00
parent 35d7a46ab6
commit a557df0106

View file

@ -24,21 +24,26 @@ class _Singleton
constructor: (@args) -> constructor: (@args) ->
# bindings
$('body').bind( 'ajaxSend', =>
@_show_spinner()
).bind( 'ajaxComplete', =>
@_hide_spinner()
)
ajax: (params, defaults) -> ajax: (params, defaults) ->
data = $.extend({}, @defaults, defaults, params) data = $.extend({}, @defaults, defaults, params)
@count++
@_show_spinner()
# console.log( 'START', @count )
if params['id'] if params['id']
if @queue_list[ params['id'] ] if @queue_list[ params['id'] ]
@queue_list[ params['id'] ].abort() @queue_list[ params['id'] ].abort()
@queue_list[ params['id'] ] = $.ajax( data ).always( @_hide_spinner ) @queue_list[ params['id'] ] = $.ajax( data )
else else
$.ajax( data ).always( @_hide_spinner ) $.ajax( data )
console.log('AJAX', params['url'] ) console.log('AJAX', params['url'] )
_show_spinner: => _show_spinner: =>
@count++
$('.spinner').show() $('.spinner').show()
_hide_spinner: => _hide_spinner: =>