Improved way how to load/reset collections.

This commit is contained in:
Martin Edenhofer 2013-10-20 14:24:18 +02:00
parent 2032847179
commit f99c72907c
4 changed files with 14 additions and 13 deletions

View file

@ -84,9 +84,10 @@ class App.Auth
App.Session.set( key, value )
# refresh default collections
for key, value of data.default_collections
App[key].refresh( value, options: { clear: true } )
if data.collections
App.Event.trigger 'resetCollection', data.collections
# trigger auth ok with new session data
App.Event.trigger( 'auth', data.session )
# init of i18n

View file

@ -31,13 +31,14 @@ class _collectionSingleton extends Spine.Module
# add trigger - bind new events
App.Event.bind 'resetCollection', (data) =>
if !data
@log 'error', 'resetCollection:trigger, got no data, cant for collections'
return
# load collections
if data.collections
for type of data.collections
@log 'debug', 'resetCollection:trigger', type, data.collections[type]
@reset( localStorage: data.localStorage, type: type, data: data.collections[type] )
for type, collection of data
@log 'debug', 'resetCollection:trigger', type, collection
@reset( localStorage: data.localStorage, type: type, data: collection )
# find collections to load
@_loadObjectsFromLocalStore()

View file

@ -31,7 +31,7 @@ class SessionsController < ApplicationController
user.activity_stream_log( 'session started', user.id, true )
# auto population of default collections
default_collection = SessionHelper::default_collections(user)
collections = SessionHelper::default_collections(user)
# set session user_id
user = User.find_fulldata(user.id)
@ -50,9 +50,9 @@ class SessionsController < ApplicationController
# return new session data
render :json => {
:session => user,
:default_collections => default_collection,
:logon_session => logon_session_key,
:session => user,
:collections => collections,
:logon_session => logon_session_key,
},
:status => :created
end

View file

@ -56,8 +56,7 @@ module Sessions::Backend::Collections
# send update to browser
data = {}
data['collections'] = {}
data['collections'][key] = push_collections
data[key] = push_collections
client.send({
:event => 'resetCollection',
:data => data,