Changed App.Ajax and App.Auth object/method mode.

This commit is contained in:
Martin Edenhofer 2012-07-15 17:18:34 +02:00
parent bd0b29a200
commit 35e0425eae

View file

@ -54,7 +54,17 @@ Config2.set( 'a', 123)
console.log '1112222', Config2.get( 'a') console.log '1112222', Config2.get( 'a')
### ###
class App.Ajax class App.Com
_instance = undefined # Must be declared here to force the closure on the class
@ajax: (args) -> # Must be a static method
if _instance == undefined
_instance ?= new _Singleton
_instance.ajax(args)
_instance
# The actual Singleton class
class _Singleton
defaults: defaults:
contentType: 'application/json' contentType: 'application/json'
dataType: 'json' dataType: 'json'
@ -63,16 +73,27 @@ class App.Ajax
cache: false cache: false
async: true async: true
queue_list: {}
pending: false
constructor: (@args) ->
ajax: (params, defaults) -> ajax: (params, defaults) ->
if params['id']
if @queue_list[ params['id'] ]
@queue_list[ params['id'] ].abort()
@queue_list[ params['id'] ] = $.ajax($.extend({}, @defaults, defaults, params))
else
$.ajax($.extend({}, @defaults, defaults, params)) $.ajax($.extend({}, @defaults, defaults, params))
class App.Auth extends App.Ajax console.log('AJAX', params['url'] )
constructor: ->
console.log 'auth'
login: (params) -> class App.Auth
@login: (params) ->
console.log 'login(...)', params console.log 'login(...)', params
@ajax( App.Com.ajax(
id: 'login',
# params, # params,
type: 'POST', type: 'POST',
url: '/signin', url: '/signin',
@ -81,9 +102,10 @@ class App.Auth extends App.Ajax
error: params.error, error: params.error,
) )
loginCheck: -> @loginCheck: ->
console.log 'loginCheck(...)' console.log 'loginCheck(...)'
@ajax( App.Com.ajax(
id: 'login_check',
async: false, async: false,
type: 'GET', type: 'GET',
url: '/signshow', url: '/signshow',
@ -133,18 +155,17 @@ class App.Auth extends App.Ajax
# empty session # empty session
window.Session = {} window.Session = {}
) )
logout: -> @logout: ->
console.log 'logout(...)' console.log 'logout(...)'
@ajax( App.Com.ajax(
id: 'logout',
type: 'DELETE', type: 'DELETE',
url: '/signout', url: '/signout',
) )
class App.i18n extends App.Ajax class App.i18n
# @include App.Ajax
constructor: -> constructor: ->
@locale = 'de' @locale = 'de'
@ -200,7 +221,8 @@ class App.i18n extends App.Ajax
set: (locale) => set: (locale) =>
@map = {} @map = {}
@ajax( App.Com.ajax(
id: 'i18n-set-' + locale,
type: 'GET', type: 'GET',
url: '/translations/lang/' + locale, url: '/translations/lang/' + locale,
async: false, async: false,
@ -276,8 +298,7 @@ class App.Run extends Spine.Controller
new App.Navigation( el: @el.find('#navigation') ); new App.Navigation( el: @el.find('#navigation') );
# check if session already exists/try to get session data from server # check if session already exists/try to get session data from server
auth = new App.Auth App.Auth.loginCheck()
auth.loginCheck()
# start notify controller # start notify controller
new App.Notify( el: @el.find('#notify') ); new App.Notify( el: @el.find('#notify') );