Added short cut to App.Controller to access easier session object.

This commit is contained in:
Martin Edenhofer 2012-11-05 16:34:18 +01:00
parent 30a0cad4f7
commit 43b14dfad6
8 changed files with 24 additions and 23 deletions

View file

@ -1,7 +1,8 @@
class App.Controller extends Spine.Controller
constructor: ->
super
@Config = App.Config
@Config = App.Config
@Session = App.Session
# add @title methode to set title
title: (name) ->
@ -16,15 +17,15 @@ class App.Controller extends Spine.Controller
navupdate: (url) ->
App.Event.trigger 'navupdate', url
scrollTo: ( x = 0, y = 0 ) ->
scrollTo: ( x = 0, y = 0, delay = 0 ) ->
a = ->
console.log('scollTo', x, y )
window.scrollTo( x, y )
@delay( a, 0 )
@delay( a, delay )
isRole: (name) ->
roles = App.Session.get( 'roles' )
roles = @Session.get( 'roles' )
return false if !roles
for role in roles
return true if role.name is name
@ -125,10 +126,10 @@ class App.Controller extends Spine.Controller
)
authenticate: ->
console.log 'authenticate', App.Session.all()
console.log 'authenticate', @Session.all()
# return rtue if session exists
return true if App.Session.get( 'id' )
return true if @Session.get( 'id' )
# remember requested url
@Config.set( 'requested_url', window.location.hash )

View file

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

View file

@ -20,7 +20,7 @@ class App.ChatWidget extends App.Controller
else
@start()
if !_.isEmpty( App.Session.all() )
if !_.isEmpty( @Session.all() )
@start()
start: =>
@ -76,7 +76,7 @@ class App.ChatWidget extends App.Controller
action: 'broadcast'
event: 'chat:window_toggle'
recipient:
user_id: [ App.Session.get('id') ]
user_id: [ @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: [ App.Session.get('id') ]
user_id: [ @Session.get('id') ]
data:
show: false
)
@ -105,7 +105,7 @@ class App.ChatWidget extends App.Controller
'ws:send'
action: 'broadcast'
recipient:
user_id: [ App.Session.get('id') ]
user_id: [ @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 App.Session.get('login')
if message.nick is @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: App.Session.get( 'id' )
nick: App.Session.get( 'login' )
user_id: @Session.get( 'id' )
nick: @Session.get( 'login' )
@messageLog.push msg
$(e.target).find('[name=chat_message]').val('')

View file

@ -123,7 +123,7 @@ class Index extends App.Controller
@log 'paramssss', params
# set customer id
params.customer_id = App.Session.get('id')
params.customer_id = @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: "#{ App.Session.get('firstname') } #{ App.Session.get('lastname') }",
from: "#{ @Session.get('firstname') } #{ @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: App.Session.get('id'),
created_by_id: @Session.get('id'),
}
# console.log('params', params)

View file

@ -66,7 +66,7 @@ class Index extends App.Controller
@render()
render: ->
@html App.view('dashboard')(
head: 'Dashboard'
)

View file

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

View file

@ -1,6 +1,6 @@
$ = jQuery.sub()
class Index extends Spine.Controller
class Index extends App.Controller
constructor: ->
super
@ -12,7 +12,7 @@ class Index extends Spine.Controller
App.Auth.logout()
# remoce local session
App.Session.init()
@Session.init()
App.Event.trigger 'ajax:auth'
# redirect to login

View file

@ -73,8 +73,8 @@ class App.Content extends App.Controller
params.el = @el
new callback( params )
# scroll to top
# window.scrollTo(0,0)
# scroll to top / remember last screen position
# @scrollTo( 0, 0, 100 )
)
Spine.Route.setup()