Moved to own session object.
This commit is contained in:
parent
dbf1d70794
commit
fc7231cc35
15 changed files with 100 additions and 64 deletions
|
@ -24,8 +24,9 @@ class App.Controller extends Spine.Controller
|
|||
@delay( a, 0 )
|
||||
|
||||
isRole: (name) ->
|
||||
return false if !window.Session.roles
|
||||
for role in window.Session.roles
|
||||
roles = App.Session.get( 'roles' )
|
||||
return false if !roles
|
||||
for role in roles
|
||||
return true if role.name is name
|
||||
return false
|
||||
|
||||
|
@ -124,10 +125,10 @@ class App.Controller extends Spine.Controller
|
|||
)
|
||||
|
||||
authenticate: ->
|
||||
console.log 'authenticate', window.Session
|
||||
console.log 'authenticate', App.Session.all()
|
||||
|
||||
# return rtue if session exists
|
||||
return true if window.Session['id']
|
||||
return true if App.Session.get( 'id' )
|
||||
|
||||
# remember requested url
|
||||
@Config.set( 'requested_url', window.location.hash )
|
||||
|
|
|
@ -3,7 +3,7 @@ App.Config.set( 'User', {
|
|||
parent: '',
|
||||
callback: ->
|
||||
item = {}
|
||||
item['name'] = window.Session['login']
|
||||
item['name'] = App.Session.get( 'login' )
|
||||
return item
|
||||
target: '#current_user',
|
||||
role: [ 'Agent', 'Customer' ]
|
||||
|
|
|
@ -380,7 +380,7 @@ class Index extends App.Controller
|
|||
# create article
|
||||
if params['body']
|
||||
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
|
||||
if !params['internal']
|
||||
params['internal'] = false
|
||||
|
|
|
@ -20,7 +20,7 @@ class App.ChatWidget extends App.Controller
|
|||
else
|
||||
@start()
|
||||
|
||||
if !_.isEmpty( Session )
|
||||
if !_.isEmpty( App.Session.all() )
|
||||
@start()
|
||||
|
||||
start: =>
|
||||
|
@ -76,7 +76,7 @@ class App.ChatWidget extends App.Controller
|
|||
action: 'broadcast'
|
||||
event: 'chat:window_toggle'
|
||||
recipient:
|
||||
user_id: [ Session['id'] ]
|
||||
user_id: [ App.Session.get('id') ]
|
||||
data:
|
||||
show: true
|
||||
)
|
||||
|
@ -87,7 +87,7 @@ class App.ChatWidget extends App.Controller
|
|||
action: 'broadcast'
|
||||
event: 'chat:window_toggle'
|
||||
recipient:
|
||||
user_id: [ Session['id'] ]
|
||||
user_id: [ App.Session.get('id') ]
|
||||
data:
|
||||
show: false
|
||||
)
|
||||
|
@ -105,7 +105,7 @@ class App.ChatWidget extends App.Controller
|
|||
'ws:send'
|
||||
action: 'broadcast'
|
||||
recipient:
|
||||
user_id: [ Session['id'] ]
|
||||
user_id: [ App.Session.get('id') ]
|
||||
event: 'chat:message_new'
|
||||
spool: true
|
||||
data:
|
||||
|
@ -149,7 +149,7 @@ class App.ChatWidget extends App.Controller
|
|||
render: ->
|
||||
|
||||
for message in @messageLog
|
||||
if message.nick is Session['login']
|
||||
if message.nick is App.Session.get('login')
|
||||
message.nick = 'me'
|
||||
|
||||
# insert data
|
||||
|
@ -180,8 +180,8 @@ class App.ChatWidget extends App.Controller
|
|||
if message
|
||||
msg =
|
||||
message: message
|
||||
user_id: Session['id']
|
||||
nick: Session['login']
|
||||
user_id: App.Session.get( 'id' )
|
||||
nick: App.Session.get( 'login' )
|
||||
@messageLog.push msg
|
||||
|
||||
$(e.target).find('[name=chat_message]').val('')
|
||||
|
|
|
@ -123,7 +123,7 @@ class Index extends App.Controller
|
|||
@log 'paramssss', params
|
||||
|
||||
# set customer id
|
||||
params.customer_id = Session['id']
|
||||
params.customer_id = App.Session.get('id')
|
||||
|
||||
# set prio
|
||||
priority = App.Collection.findByAttribute( 'TicketPriority', 'name', '2 normal' )
|
||||
|
@ -149,13 +149,13 @@ class Index extends App.Controller
|
|||
|
||||
# create article
|
||||
params['article'] = {
|
||||
from: "#{Session['firstname']} #{Session['lastname']}",
|
||||
from: "#{ App.Session.get('firstname') } #{ App.Session.get('lastname') }",
|
||||
to: (group && group.name) || '',
|
||||
subject: params.subject,
|
||||
body: params.body,
|
||||
ticket_article_type_id: type.id,
|
||||
ticket_article_sender_id: sender.id,
|
||||
created_by_id: Session['id'],
|
||||
created_by_id: App.Session.get('id'),
|
||||
}
|
||||
# console.log('params', params)
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ class Index extends App.Controller
|
|||
|
||||
# store user data
|
||||
for key, value of data.session
|
||||
window.Session[key] = value
|
||||
App.Session.set( key, value )
|
||||
|
||||
# refresh default collections
|
||||
for key, value of data.default_collections
|
||||
|
|
|
@ -12,9 +12,7 @@ class Index extends Spine.Controller
|
|||
App.Auth.logout()
|
||||
|
||||
# remoce local session
|
||||
@log 'Session', window.Session
|
||||
window.Session = {}
|
||||
@log 'Session', window.Session
|
||||
App.Session.init()
|
||||
App.Event.trigger 'ajax:auth'
|
||||
|
||||
# redirect to login
|
||||
|
|
|
@ -27,12 +27,12 @@ class App.Navigation extends App.Controller
|
|||
# rebuild ticket overview data
|
||||
App.Event.bind 'navupdate_ticket_overview', (data) =>
|
||||
@ticket_overview_build(data)
|
||||
@render( window.Session )
|
||||
@render( App.Session.all() )
|
||||
|
||||
# rebuild recent viewd data
|
||||
App.Event.bind 'update_recent_viewed', (data) =>
|
||||
@recent_viewed_build(data)
|
||||
@render( window.Session )
|
||||
@render( App.Session.all() )
|
||||
|
||||
render: (user) ->
|
||||
nav_left = @getItems( navbar: @Config.get( 'NavBar' ) )
|
||||
|
@ -66,6 +66,8 @@ class App.Navigation extends App.Controller
|
|||
level1 = []
|
||||
dropdown = {}
|
||||
|
||||
roles = App.Session.get( 'roles' )
|
||||
|
||||
for item in navbar
|
||||
if typeof item.callback is 'function'
|
||||
data = item.callback() || {}
|
||||
|
@ -73,10 +75,10 @@ class App.Navigation extends App.Controller
|
|||
item[key] = value
|
||||
if !item.parent
|
||||
match = 0
|
||||
if !window.Session['roles']
|
||||
if !roles
|
||||
match = _.include( item.role, 'Anybody' )
|
||||
if window.Session['roles']
|
||||
window.Session['roles'].forEach( (role) =>
|
||||
if roles
|
||||
roles.forEach( (role) =>
|
||||
if !match
|
||||
match = _.include(item.role, role.name)
|
||||
)
|
||||
|
@ -92,10 +94,10 @@ class App.Navigation extends App.Controller
|
|||
for itemSub in navbar
|
||||
if itemSub.parent is item.parent
|
||||
match = 0
|
||||
if !window.Session['roles']
|
||||
if !roles
|
||||
match = _.include( itemSub.role, 'Anybody' )
|
||||
if window.Session['roles']
|
||||
window.Session['roles'].forEach( (role) =>
|
||||
if roles
|
||||
roles.forEach( (role) =>
|
||||
if !match
|
||||
match = _.include(itemSub.role, role.name)
|
||||
)
|
||||
|
|
|
@ -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_tree ./lib/app_init
|
||||
#= require_tree ./models
|
||||
|
|
|
@ -4,7 +4,7 @@ class App.Config
|
|||
@init: ->
|
||||
_instance ?= new _Singleton
|
||||
|
||||
@get: ( key, group ) ->
|
||||
@get: ( key ) ->
|
||||
if _instance == undefined
|
||||
_instance ?= new _Singleton
|
||||
_instance.get( key )
|
||||
|
|
37
app/assets/javascripts/app/lib/app_init/session.js.coffee
Normal file
37
app/assets/javascripts/app/lib/app_init/session.js.coffee
Normal 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
|
|
@ -39,7 +39,7 @@ class App.Auth
|
|||
App.Config.set( key, value )
|
||||
|
||||
# empty session
|
||||
window.Session = {}
|
||||
App.Session.init()
|
||||
|
||||
# update websocked auth info
|
||||
App.WebSocket.auth()
|
||||
|
@ -59,7 +59,7 @@ class App.Auth
|
|||
|
||||
# store user data
|
||||
for key, value of data.session
|
||||
window.Session[key] = value
|
||||
App.Session.set( key, value )
|
||||
|
||||
# update websocked auth info
|
||||
App.WebSocket.auth()
|
||||
|
@ -75,7 +75,7 @@ class App.Auth
|
|||
console.log 'loginCheck:error'#, error, statusText, xhr.statusCode
|
||||
|
||||
# empty session
|
||||
window.Session = {}
|
||||
App.Session.init()
|
||||
|
||||
# clear store
|
||||
App.Store.clear('all')
|
||||
|
|
|
@ -62,10 +62,9 @@ class _Singleton extends App.Controller
|
|||
return if !@supported
|
||||
|
||||
# logon websocket
|
||||
data = {
|
||||
action: 'login',
|
||||
session: window.Session
|
||||
}
|
||||
data =
|
||||
action: 'login'
|
||||
session: App.Session.all()
|
||||
@send(data)
|
||||
|
||||
spool: =>
|
||||
|
|
|
@ -5,6 +5,23 @@
|
|||
// the compiled file.
|
||||
//
|
||||
|
||||
//= require init.js
|
||||
//= require app
|
||||
//not_used#= require_tree .
|
||||
//= require ./app/lib/core/jquery-1.8.1.min.js
|
||||
//= require ./app/lib/core/jquery-ui-1.8.23.custom.min.js
|
||||
//= 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
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
var Session = {};
|
Loading…
Reference in a new issue