Improved loading assets.

This commit is contained in:
Martin Edenhofer 2014-04-02 15:15:14 +02:00
parent e01873b590
commit 8f744e2856
14 changed files with 58 additions and 44 deletions

View file

@ -32,8 +32,8 @@ class App.DashboardActivityStream extends App.Controller
load: (data) => load: (data) =>
items = data.activity_stream items = data.activity_stream
# load collections # load assets
App.Event.trigger 'loadAssets', data.assets App.Collection.loadAssets( data.assets )
@render(items) @render(items)

View file

@ -16,8 +16,8 @@ class App.DashboardRecentViewed extends App.Controller
success: (data, status, xhr) => success: (data, status, xhr) =>
@items = data.recent_viewed @items = data.recent_viewed
# load collections # load assets
App.Event.trigger 'loadAssets', data.assets App.Collection.loadAssets( data.assets )
@render() @render()
) )

View file

@ -38,18 +38,16 @@ class App.DashboardTicket extends App.Controller
} }
processData: true, processData: true,
success: (data) => success: (data) =>
data.ajax = true @load( data, true )
@load(data)
) )
load: (data) => load: (data, ajax = false) =>
if data.ajax if ajax
data.ajax = false
App.Store.write( @key, data ) App.Store.write( @key, data )
# load collections # load assets
App.Event.trigger 'loadAssets', data.assets App.Collection.loadAssets( data.assets )
# get meta data # get meta data
App.Overview.refresh( data.overview, options: { clear: true } ) App.Overview.refresh( data.overview, options: { clear: true } )

View file

@ -103,8 +103,8 @@ class App.TicketCreate extends App.Controller
# get edit form attributes # get edit form attributes
@edit_form = cache.edit_form @edit_form = cache.edit_form
# load collections # load assets
App.Event.trigger 'loadAssets', cache.assets App.Collection.loadAssets( cache.assets )
@render() @render()
else else
@ -124,8 +124,8 @@ class App.TicketCreate extends App.Controller
# get edit form attributes # get edit form attributes
@edit_form = data.edit_form @edit_form = data.edit_form
# load collections # load assets
App.Event.trigger 'loadAssets', data.assets App.Collection.loadAssets( data.assets )
# split ticket # split ticket
if data.split && data.split.ticket_id && data.split.article_id if data.split && data.split.ticket_id && data.split.article_id

View file

@ -13,8 +13,8 @@ class App.TicketMerge extends App.ControllerModal
processData: true, processData: true,
success: (data, status, xhr) => success: (data, status, xhr) =>
# load collections # load assets
App.Event.trigger 'loadAssets', data.assets App.Collection.loadAssets( data.assets )
@ticket_ids_by_customer = data.ticket_ids_by_customer @ticket_ids_by_customer = data.ticket_ids_by_customer
@ticket_ids_recent_viewed = data.ticket_ids_recent_viewed @ticket_ids_recent_viewed = data.ticket_ids_recent_viewed

View file

@ -29,8 +29,8 @@ class Index extends App.ControllerContent
# get edit form attributes # get edit form attributes
@edit_form = cache.edit_form @edit_form = cache.edit_form
# load collections # load assets
App.Event.trigger 'loadAssets', cache.assets App.Collection.loadAssets( cache.assets )
@render() @render()
else else
@ -47,8 +47,8 @@ class Index extends App.ControllerContent
# get edit form attributes # get edit form attributes
@edit_form = data.edit_form @edit_form = data.edit_form
# load collections # load assets
App.Event.trigger 'loadAssets', data.assets App.Collection.loadAssets( data.assets )
@render() @render()
) )

View file

@ -104,8 +104,8 @@ class App.Navigation extends App.Controller
processData: true, processData: true,
success: (data, status, xhr) => success: (data, status, xhr) =>
# load collections # load assets
App.Event.trigger 'loadAssets', data.assets App.Collection.loadAssets( data.assets )
@result = data.result @result = data.result
for area in @result for area in @result
@ -303,8 +303,8 @@ class App.Navigation extends App.Controller
items = data.recent_viewed items = data.recent_viewed
# load collections # load assets
App.Event.trigger 'loadAssets', data.assets App.Collection.loadAssets( data.assets )
# remove old views # remove old views
NavBarRight = @Config.get( 'NavBarRight' ) || {} NavBarRight = @Config.get( 'NavBarRight' ) || {}

View file

@ -27,8 +27,8 @@ class Index extends App.ControllerContent
render: (data) -> render: (data) ->
# load collections # load assets
App.Event.trigger 'loadAssets', data.assets App.Collection.loadAssets( data.assets )
# fill users # fill users
for session in data.sessions for session in data.sessions

View file

@ -12,8 +12,8 @@ class App.TicketHistory extends App.GenericHistory
url: @apiPath + '/ticket_history/' + @ticket_id, url: @apiPath + '/ticket_history/' + @ticket_id,
success: (data, status, xhr) => success: (data, status, xhr) =>
# load collections # load assets
App.Event.trigger 'loadAssets', data.assets App.Collection.loadAssets( data.assets )
# render page # render page
@render(data.history) @render(data.history)

View file

@ -91,8 +91,8 @@ class Table extends App.ControllerContent
data.ajax = false data.ajax = false
App.Store.write( @key, data ) App.Store.write( @key, data )
# load collections # load assets
App.Event.trigger 'loadAssets', data.assets App.Collection.loadAssets( data.assets )
# get meta data # get meta data
@overview = data.overview @overview = data.overview

View file

@ -115,8 +115,8 @@ class App.TicketZoom extends App.Controller
# get signature # get signature
@signature = data.signature @signature = data.signature
# load collections # load assets
App.Event.trigger 'loadAssets', data.assets App.Collection.loadAssets( data.assets )
# get data # get data
@ticket = App.Ticket.retrieve( @ticket_id ) @ticket = App.Ticket.retrieve( @ticket_id )

View file

@ -12,8 +12,8 @@ class App.UserHistory extends App.GenericHistory
url: @apiPath + '/users/history/' + @user_id, url: @apiPath + '/users/history/' + @user_id,
success: (data, status, xhr) => success: (data, status, xhr) =>
# load collections # load assets
App.Event.trigger 'loadAssets', data.assets App.Collection.loadAssets( data.assets )
# render page # render page
@render(data.history) @render(data.history)

View file

@ -23,8 +23,8 @@ class App.WidgetLink extends App.ControllerDrox
success: (data, status, xhr) => success: (data, status, xhr) =>
@links = data.links @links = data.links
# load collections # load assets
App.Event.trigger 'loadAssets', data.assets App.Collection.loadAssets( data.assets )
@render() @render()

View file

@ -9,11 +9,21 @@ class App.Collection
_instance ?= new _collectionSingleton _instance ?= new _collectionSingleton
_instance.load( args ) _instance.load( args )
@loadAssets: ( args ) ->
if _instance == undefined
_instance ?= new _collectionSingleton
_instance.loadAssets( args )
@reset: ( args ) -> @reset: ( args ) ->
if _instance == undefined if _instance == undefined
_instance ?= new _collectionSingleton _instance ?= new _collectionSingleton
_instance.reset( args ) _instance.reset( args )
@resetCollection: ( args ) ->
if _instance == undefined
_instance ?= new _collectionSingleton
_instance.resetCollection( args )
class _collectionSingleton extends Spine.Module class _collectionSingleton extends Spine.Module
@include App.LogInclude @include App.LogInclude
@ -25,9 +35,7 @@ class _collectionSingleton extends Spine.Module
@log 'error', 'loadAssets:trigger, got no data, cant load assets' @log 'error', 'loadAssets:trigger, got no data, cant load assets'
return return
for type, collections of data @loadAssets( data )
@log 'debug', 'loadCollection:trigger', type, collections
@load( localStorage: data.localStorage, type: type, data: collections )
# add trigger - bind new events # add trigger - bind new events
App.Event.bind 'resetCollection', (data) => App.Event.bind 'resetCollection', (data) =>
@ -35,10 +43,7 @@ class _collectionSingleton extends Spine.Module
@log 'error', 'resetCollection:trigger, got no data, cant for collections' @log 'error', 'resetCollection:trigger, got no data, cant for collections'
return return
# load collections @resetCollections( data )
for type, collection of data
@log 'debug', 'resetCollection:trigger', type, collection
@reset( localStorage: data.localStorage, type: type, data: collection )
# find collections to load # find collections to load
@_loadObjectsFromLocalStore() @_loadObjectsFromLocalStore()
@ -55,6 +60,12 @@ class _collectionSingleton extends Spine.Module
@log 'debug', 'load INIT', data @log 'debug', 'load INIT', data
@load( data ) @load( data )
resetCollections: (data) ->
# load assets
for type, collection of data
@log 'debug', 'resetCollection:trigger', type, collection
@reset( localStorage: data.localStorage, type: type, data: collection )
reset: (params) -> reset: (params) ->
if !App[ params.type ] if !App[ params.type ]
@log 'error', 'reset', 'no such collection', params @log 'error', 'reset', 'no such collection', params
@ -72,6 +83,11 @@ class _collectionSingleton extends Spine.Module
for object in params.data for object in params.data
@localStore( params.type, object ) @localStore( params.type, object )
loadAssets: (assets) ->
@log 'debug', 'loadAssets', assets
for type, collections of assets
@load( localStorage: false, type: type, data: collections )
load: (params) -> load: (params) ->
@log 'debug', 'load', params @log 'debug', 'load', params