Moved to own session object.

This commit is contained in:
Martin Edenhofer 2012-11-05 15:37:59 +01:00
parent dbf1d70794
commit fc7231cc35
15 changed files with 100 additions and 64 deletions

View file

@ -24,8 +24,9 @@ class App.Controller extends Spine.Controller
@delay( a, 0 ) @delay( a, 0 )
isRole: (name) -> isRole: (name) ->
return false if !window.Session.roles roles = App.Session.get( 'roles' )
for role in window.Session.roles return false if !roles
for role in roles
return true if role.name is name return true if role.name is name
return false return false
@ -124,10 +125,10 @@ class App.Controller extends Spine.Controller
) )
authenticate: -> authenticate: ->
console.log 'authenticate', window.Session console.log 'authenticate', App.Session.all()
# return rtue if session exists # return rtue if session exists
return true if window.Session['id'] return true if App.Session.get( 'id' )
# remember requested url # remember requested url
@Config.set( 'requested_url', window.location.hash ) @Config.set( 'requested_url', window.location.hash )

View file

@ -3,7 +3,7 @@ App.Config.set( 'User', {
parent: '', parent: '',
callback: -> callback: ->
item = {} item = {}
item['name'] = window.Session['login'] item['name'] = App.Session.get( 'login' )
return item return item
target: '#current_user', target: '#current_user',
role: [ 'Agent', 'Customer' ] role: [ 'Agent', 'Customer' ]

View file

@ -380,7 +380,7 @@ class Index extends App.Controller
# create article # create article
if params['body'] if params['body']
article = new App.TicketArticle article = new App.TicketArticle
params.from = window.Session['firstname'] + ' ' + window.Session['lastname'] params.from = App.Session.get( 'firstname' ) + ' ' + App.Session.get( 'lastname' )
params.ticket_id = @ticket.id params.ticket_id = @ticket.id
if !params['internal'] if !params['internal']
params['internal'] = false params['internal'] = false

View file

@ -20,7 +20,7 @@ class App.ChatWidget extends App.Controller
else else
@start() @start()
if !_.isEmpty( Session ) if !_.isEmpty( App.Session.all() )
@start() @start()
start: => start: =>
@ -76,20 +76,20 @@ class App.ChatWidget extends App.Controller
action: 'broadcast' action: 'broadcast'
event: 'chat:window_toggle' event: 'chat:window_toggle'
recipient: recipient:
user_id: [ Session['id'] ] user_id: [ App.Session.get('id') ]
data: data:
show: true show: true
) )
else else
@hide() @hide()
App.Event.trigger( App.Event.trigger(
'ws:send' 'ws:send'
action: 'broadcast' action: 'broadcast'
event: 'chat:window_toggle' event: 'chat:window_toggle'
recipient: recipient:
user_id: [ Session['id'] ] user_id: [ App.Session.get('id') ]
data: data:
show: false show: false
) )
@newMessage = false @newMessage = false
@ -105,11 +105,11 @@ class App.ChatWidget extends App.Controller
'ws:send' 'ws:send'
action: 'broadcast' action: 'broadcast'
recipient: recipient:
user_id: [ Session['id'] ] user_id: [ App.Session.get('id') ]
event: 'chat:message_new' event: 'chat:message_new'
spool: true spool: true
data: data:
show: true show: true
) )
2000 2000
@ -149,7 +149,7 @@ class App.ChatWidget extends App.Controller
render: -> render: ->
for message in @messageLog for message in @messageLog
if message.nick is Session['login'] if message.nick is App.Session.get('login')
message.nick = 'me' message.nick = 'me'
# insert data # insert data
@ -180,8 +180,8 @@ class App.ChatWidget extends App.Controller
if message if message
msg = msg =
message: message message: message
user_id: Session['id'] user_id: App.Session.get( 'id' )
nick: Session['login'] nick: App.Session.get( 'login' )
@messageLog.push msg @messageLog.push msg
$(e.target).find('[name=chat_message]').val('') $(e.target).find('[name=chat_message]').val('')

View file

@ -123,7 +123,7 @@ class Index extends App.Controller
@log 'paramssss', params @log 'paramssss', params
# set customer id # set customer id
params.customer_id = Session['id'] params.customer_id = App.Session.get('id')
# set prio # set prio
priority = App.Collection.findByAttribute( 'TicketPriority', 'name', '2 normal' ) priority = App.Collection.findByAttribute( 'TicketPriority', 'name', '2 normal' )
@ -149,13 +149,13 @@ class Index extends App.Controller
# create article # create article
params['article'] = { params['article'] = {
from: "#{Session['firstname']} #{Session['lastname']}", from: "#{ App.Session.get('firstname') } #{ App.Session.get('lastname') }",
to: (group && group.name) || '', to: (group && group.name) || '',
subject: params.subject, subject: params.subject,
body: params.body, body: params.body,
ticket_article_type_id: type.id, ticket_article_type_id: type.id,
ticket_article_sender_id: sender.id, ticket_article_sender_id: sender.id,
created_by_id: Session['id'], created_by_id: App.Session.get('id'),
} }
# console.log('params', params) # console.log('params', params)

View file

@ -79,7 +79,7 @@ class Index extends App.Controller
# store user data # store user data
for key, value of data.session for key, value of data.session
window.Session[key] = value App.Session.set( key, value )
# refresh default collections # refresh default collections
for key, value of data.default_collections for key, value of data.default_collections

View file

@ -12,9 +12,7 @@ class Index extends Spine.Controller
App.Auth.logout() App.Auth.logout()
# remoce local session # remoce local session
@log 'Session', window.Session App.Session.init()
window.Session = {}
@log 'Session', window.Session
App.Event.trigger 'ajax:auth' App.Event.trigger 'ajax:auth'
# redirect to login # redirect to login

View file

@ -27,12 +27,12 @@ class App.Navigation extends App.Controller
# rebuild ticket overview data # rebuild ticket overview data
App.Event.bind 'navupdate_ticket_overview', (data) => App.Event.bind 'navupdate_ticket_overview', (data) =>
@ticket_overview_build(data) @ticket_overview_build(data)
@render( window.Session ) @render( App.Session.all() )
# rebuild recent viewd data # rebuild recent viewd data
App.Event.bind 'update_recent_viewed', (data) => App.Event.bind 'update_recent_viewed', (data) =>
@recent_viewed_build(data) @recent_viewed_build(data)
@render( window.Session ) @render( App.Session.all() )
render: (user) -> render: (user) ->
nav_left = @getItems( navbar: @Config.get( 'NavBar' ) ) nav_left = @getItems( navbar: @Config.get( 'NavBar' ) )
@ -66,6 +66,8 @@ class App.Navigation extends App.Controller
level1 = [] level1 = []
dropdown = {} dropdown = {}
roles = App.Session.get( 'roles' )
for item in navbar for item in navbar
if typeof item.callback is 'function' if typeof item.callback is 'function'
data = item.callback() || {} data = item.callback() || {}
@ -73,10 +75,10 @@ class App.Navigation extends App.Controller
item[key] = value item[key] = value
if !item.parent if !item.parent
match = 0 match = 0
if !window.Session['roles'] if !roles
match = _.include(item.role, 'Anybody') match = _.include( item.role, 'Anybody' )
if window.Session['roles'] if roles
window.Session['roles'].forEach( (role) => roles.forEach( (role) =>
if !match if !match
match = _.include(item.role, role.name) match = _.include(item.role, role.name)
) )
@ -92,10 +94,10 @@ class App.Navigation extends App.Controller
for itemSub in navbar for itemSub in navbar
if itemSub.parent is item.parent if itemSub.parent is item.parent
match = 0 match = 0
if !window.Session['roles'] if !roles
match = _.include(itemSub.role, 'Anybody') match = _.include( itemSub.role, 'Anybody' )
if window.Session['roles'] if roles
window.Session['roles'].forEach( (role) => roles.forEach( (role) =>
if !match if !match
match = _.include(itemSub.role, role.name) match = _.include(itemSub.role, role.name)
) )

View file

@ -1,21 +1,4 @@
#= require ./lib/core/jquery-1.8.1.min.js
#= require ./lib/core/jquery-ui-1.8.23.custom.min.js
#= require ./lib/core/underscore-1.3.3.js
#not_used= require_tree ./lib/spine
#= require ./lib/spine/spine.js
#= require ./lib/spine/ajax.js
#= require ./lib/spine/route.js
#not_used= require_tree ./lib/bootstrap
#= require ./lib/bootstrap/bootstrap-dropdown.js
#= require ./lib/bootstrap/bootstrap-tooltip.js
#= require ./lib/bootstrap/bootstrap-popover.js
#= require ./lib/bootstrap/bootstrap-modal.js
#= require ./lib/bootstrap/bootstrap-tab.js
#= require ./lib/bootstrap/bootstrap-transition.js
#= require_tree ./lib/base
#= require_self #= require_self
#= require_tree ./lib/app_init #= require_tree ./lib/app_init
#= require_tree ./models #= require_tree ./models

View file

@ -4,7 +4,7 @@ class App.Config
@init: -> @init: ->
_instance ?= new _Singleton _instance ?= new _Singleton
@get: ( key, group ) -> @get: ( key ) ->
if _instance == undefined if _instance == undefined
_instance ?= new _Singleton _instance ?= new _Singleton
_instance.get( key ) _instance.get( key )

View file

@ -0,0 +1,37 @@
class App.Session
_instance = undefined
@init: ->
_instance ?= new _Singleton
_instance.clear()
@get: ( key ) ->
if _instance == undefined
_instance ?= new _Singleton
_instance.get( key )
@set: ( key, value ) ->
if _instance == undefined
_instance ?= new _Singleton
_instance.set( key, value )
@all: ->
if _instance == undefined
_instance ?= new _Singleton
_instance.all()
class _Singleton
constructor: ->
@clear()
clear: ->
@data = {}
get: ( key ) ->
return @data[key]
set: ( key, value ) ->
@data[key] = value
all: ->
@data

View file

@ -39,7 +39,7 @@ class App.Auth
App.Config.set( key, value ) App.Config.set( key, value )
# empty session # empty session
window.Session = {} App.Session.init()
# update websocked auth info # update websocked auth info
App.WebSocket.auth() App.WebSocket.auth()
@ -59,7 +59,7 @@ class App.Auth
# store user data # store user data
for key, value of data.session for key, value of data.session
window.Session[key] = value App.Session.set( key, value )
# update websocked auth info # update websocked auth info
App.WebSocket.auth() App.WebSocket.auth()
@ -75,7 +75,7 @@ class App.Auth
console.log 'loginCheck:error'#, error, statusText, xhr.statusCode console.log 'loginCheck:error'#, error, statusText, xhr.statusCode
# empty session # empty session
window.Session = {} App.Session.init()
# clear store # clear store
App.Store.clear('all') App.Store.clear('all')

View file

@ -62,10 +62,9 @@ class _Singleton extends App.Controller
return if !@supported return if !@supported
# logon websocket # logon websocket
data = { data =
action: 'login', action: 'login'
session: window.Session session: App.Session.all()
}
@send(data) @send(data)
spool: => spool: =>

View file

@ -5,6 +5,23 @@
// the compiled file. // the compiled file.
// //
//= require init.js //= require ./app/lib/core/jquery-1.8.1.min.js
//= require app //= require ./app/lib/core/jquery-ui-1.8.23.custom.min.js
//not_used#= require_tree . //= require ./app/lib/core/underscore-1.3.3.js
//not_used= require_tree ./app/lib/spine
//= require ./app/lib/spine/spine.js
//= require ./app/lib/spine/ajax.js
//= require ./app/lib/spine/route.js
//not_used= require_tree ./app/lib/bootstrap
//= require ./app/lib/bootstrap/bootstrap-dropdown.js
//= require ./app/lib/bootstrap/bootstrap-tooltip.js
//= require ./app/lib/bootstrap/bootstrap-popover.js
//= require ./app/lib/bootstrap/bootstrap-modal.js
//= require ./app/lib/bootstrap/bootstrap-tab.js
//= require ./app/lib/bootstrap/bootstrap-transition.js
//= require_tree ./app/lib/base
//= require ./app/index.js.coffee

View file

@ -1 +0,0 @@
var Session = {};