Browse Source

Improved way how to load/reset collections.

Martin Edenhofer 11 years ago
parent
commit
f99c72907c

+ 3 - 2
app/assets/javascripts/app/lib/app_post/auth.js.coffee

@@ -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

+ 6 - 5
app/assets/javascripts/app/lib/app_post/collection.js.coffee

@@ -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()

+ 4 - 4
app/controllers/sessions_controller.rb

@@ -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

+ 1 - 2
lib/sessions/backend/collections.rb

@@ -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,