diff --git a/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee b/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee index 009f97be1..044ffd0d9 100644 --- a/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee +++ b/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee @@ -32,8 +32,8 @@ class App.DashboardActivityStream extends App.Controller load: (data) => items = data.activity_stream - # load collections - App.Event.trigger 'loadAssets', data.assets + # load assets + App.Collection.loadAssets( data.assets ) @render(items) diff --git a/app/assets/javascripts/app/controllers/_dashboard/recent_viewed.js.coffee b/app/assets/javascripts/app/controllers/_dashboard/recent_viewed.js.coffee index 23496b794..cbea2a62d 100644 --- a/app/assets/javascripts/app/controllers/_dashboard/recent_viewed.js.coffee +++ b/app/assets/javascripts/app/controllers/_dashboard/recent_viewed.js.coffee @@ -16,8 +16,8 @@ class App.DashboardRecentViewed extends App.Controller success: (data, status, xhr) => @items = data.recent_viewed - # load collections - App.Event.trigger 'loadAssets', data.assets + # load assets + App.Collection.loadAssets( data.assets ) @render() ) diff --git a/app/assets/javascripts/app/controllers/_dashboard/ticket.js.coffee b/app/assets/javascripts/app/controllers/_dashboard/ticket.js.coffee index 9a37a27a4..4d8c3c186 100644 --- a/app/assets/javascripts/app/controllers/_dashboard/ticket.js.coffee +++ b/app/assets/javascripts/app/controllers/_dashboard/ticket.js.coffee @@ -38,18 +38,16 @@ class App.DashboardTicket extends App.Controller } processData: true, success: (data) => - data.ajax = true - @load(data) + @load( data, true ) ) - load: (data) => + load: (data, ajax = false) => - if data.ajax - data.ajax = false + if ajax App.Store.write( @key, data ) - # load collections - App.Event.trigger 'loadAssets', data.assets + # load assets + App.Collection.loadAssets( data.assets ) # get meta data App.Overview.refresh( data.overview, options: { clear: true } ) diff --git a/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee b/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee index c70d85c3e..ec420a724 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee @@ -103,8 +103,8 @@ class App.TicketCreate extends App.Controller # get edit form attributes @edit_form = cache.edit_form - # load collections - App.Event.trigger 'loadAssets', cache.assets + # load assets + App.Collection.loadAssets( cache.assets ) @render() else @@ -124,8 +124,8 @@ class App.TicketCreate extends App.Controller # get edit form attributes @edit_form = data.edit_form - # load collections - App.Event.trigger 'loadAssets', data.assets + # load assets + App.Collection.loadAssets( data.assets ) # split ticket if data.split && data.split.ticket_id && data.split.article_id diff --git a/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee b/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee index a2b01f6e1..b4cbafe2f 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee @@ -13,8 +13,8 @@ class App.TicketMerge extends App.ControllerModal processData: true, success: (data, status, xhr) => - # load collections - App.Event.trigger 'loadAssets', data.assets + # load assets + App.Collection.loadAssets( data.assets ) @ticket_ids_by_customer = data.ticket_ids_by_customer @ticket_ids_recent_viewed = data.ticket_ids_recent_viewed diff --git a/app/assets/javascripts/app/controllers/customer_ticket_create.js.coffee b/app/assets/javascripts/app/controllers/customer_ticket_create.js.coffee index a6e1069dd..7f5e043e3 100644 --- a/app/assets/javascripts/app/controllers/customer_ticket_create.js.coffee +++ b/app/assets/javascripts/app/controllers/customer_ticket_create.js.coffee @@ -29,8 +29,8 @@ class Index extends App.ControllerContent # get edit form attributes @edit_form = cache.edit_form - # load collections - App.Event.trigger 'loadAssets', cache.assets + # load assets + App.Collection.loadAssets( cache.assets ) @render() else @@ -47,8 +47,8 @@ class Index extends App.ControllerContent # get edit form attributes @edit_form = data.edit_form - # load collections - App.Event.trigger 'loadAssets', data.assets + # load assets + App.Collection.loadAssets( data.assets ) @render() ) diff --git a/app/assets/javascripts/app/controllers/navigation.js.coffee b/app/assets/javascripts/app/controllers/navigation.js.coffee index f29a844ab..a00088e97 100644 --- a/app/assets/javascripts/app/controllers/navigation.js.coffee +++ b/app/assets/javascripts/app/controllers/navigation.js.coffee @@ -104,8 +104,8 @@ class App.Navigation extends App.Controller processData: true, success: (data, status, xhr) => - # load collections - App.Event.trigger 'loadAssets', data.assets + # load assets + App.Collection.loadAssets( data.assets ) @result = data.result for area in @result @@ -303,8 +303,8 @@ class App.Navigation extends App.Controller items = data.recent_viewed - # load collections - App.Event.trigger 'loadAssets', data.assets + # load assets + App.Collection.loadAssets( data.assets ) # remove old views NavBarRight = @Config.get( 'NavBarRight' ) || {} diff --git a/app/assets/javascripts/app/controllers/session.js.coffee b/app/assets/javascripts/app/controllers/session.js.coffee index 30c097aa7..7f81059f5 100644 --- a/app/assets/javascripts/app/controllers/session.js.coffee +++ b/app/assets/javascripts/app/controllers/session.js.coffee @@ -27,8 +27,8 @@ class Index extends App.ControllerContent render: (data) -> - # load collections - App.Event.trigger 'loadAssets', data.assets + # load assets + App.Collection.loadAssets( data.assets ) # fill users for session in data.sessions diff --git a/app/assets/javascripts/app/controllers/ticket_history.js.coffee b/app/assets/javascripts/app/controllers/ticket_history.js.coffee index 216cfeffd..fe3110239 100644 --- a/app/assets/javascripts/app/controllers/ticket_history.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_history.js.coffee @@ -12,8 +12,8 @@ class App.TicketHistory extends App.GenericHistory url: @apiPath + '/ticket_history/' + @ticket_id, success: (data, status, xhr) => - # load collections - App.Event.trigger 'loadAssets', data.assets + # load assets + App.Collection.loadAssets( data.assets ) # render page @render(data.history) diff --git a/app/assets/javascripts/app/controllers/ticket_overview.js.coffee b/app/assets/javascripts/app/controllers/ticket_overview.js.coffee index 26f9f36e1..93a85ed2d 100644 --- a/app/assets/javascripts/app/controllers/ticket_overview.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_overview.js.coffee @@ -91,8 +91,8 @@ class Table extends App.ControllerContent data.ajax = false App.Store.write( @key, data ) - # load collections - App.Event.trigger 'loadAssets', data.assets + # load assets + App.Collection.loadAssets( data.assets ) # get meta data @overview = data.overview diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee index 99f326405..efe91206c 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee @@ -115,8 +115,8 @@ class App.TicketZoom extends App.Controller # get signature @signature = data.signature - # load collections - App.Event.trigger 'loadAssets', data.assets + # load assets + App.Collection.loadAssets( data.assets ) # get data @ticket = App.Ticket.retrieve( @ticket_id ) diff --git a/app/assets/javascripts/app/controllers/user_history.js.coffee b/app/assets/javascripts/app/controllers/user_history.js.coffee index 625b92580..6083dd746 100644 --- a/app/assets/javascripts/app/controllers/user_history.js.coffee +++ b/app/assets/javascripts/app/controllers/user_history.js.coffee @@ -12,8 +12,8 @@ class App.UserHistory extends App.GenericHistory url: @apiPath + '/users/history/' + @user_id, success: (data, status, xhr) => - # load collections - App.Event.trigger 'loadAssets', data.assets + # load assets + App.Collection.loadAssets( data.assets ) # render page @render(data.history) diff --git a/app/assets/javascripts/app/controllers/widget/link.js.coffee b/app/assets/javascripts/app/controllers/widget/link.js.coffee index 4231c9da1..7cdcb9a4f 100644 --- a/app/assets/javascripts/app/controllers/widget/link.js.coffee +++ b/app/assets/javascripts/app/controllers/widget/link.js.coffee @@ -23,8 +23,8 @@ class App.WidgetLink extends App.ControllerDrox success: (data, status, xhr) => @links = data.links - # load collections - App.Event.trigger 'loadAssets', data.assets + # load assets + App.Collection.loadAssets( data.assets ) @render() diff --git a/app/assets/javascripts/app/lib/app_post/collection.js.coffee b/app/assets/javascripts/app/lib/app_post/collection.js.coffee index 1b38112e8..b715ebb5e 100644 --- a/app/assets/javascripts/app/lib/app_post/collection.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/collection.js.coffee @@ -9,11 +9,21 @@ class App.Collection _instance ?= new _collectionSingleton _instance.load( args ) + @loadAssets: ( args ) -> + if _instance == undefined + _instance ?= new _collectionSingleton + _instance.loadAssets( args ) + @reset: ( args ) -> if _instance == undefined _instance ?= new _collectionSingleton _instance.reset( args ) + @resetCollection: ( args ) -> + if _instance == undefined + _instance ?= new _collectionSingleton + _instance.resetCollection( args ) + class _collectionSingleton extends Spine.Module @include App.LogInclude @@ -25,9 +35,7 @@ class _collectionSingleton extends Spine.Module @log 'error', 'loadAssets:trigger, got no data, cant load assets' return - for type, collections of data - @log 'debug', 'loadCollection:trigger', type, collections - @load( localStorage: data.localStorage, type: type, data: collections ) + @loadAssets( data ) # add trigger - bind new events App.Event.bind 'resetCollection', (data) => @@ -35,10 +43,7 @@ class _collectionSingleton extends Spine.Module @log 'error', 'resetCollection:trigger, got no data, cant for collections' return - # load collections - for type, collection of data - @log 'debug', 'resetCollection:trigger', type, collection - @reset( localStorage: data.localStorage, type: type, data: collection ) + @resetCollections( data ) # find collections to load @_loadObjectsFromLocalStore() @@ -55,6 +60,12 @@ class _collectionSingleton extends Spine.Module @log 'debug', 'load INIT', 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) -> if !App[ params.type ] @log 'error', 'reset', 'no such collection', params @@ -72,6 +83,11 @@ class _collectionSingleton extends Spine.Module for object in params.data @localStore( params.type, object ) + loadAssets: (assets) -> + @log 'debug', 'loadAssets', assets + for type, collections of assets + @load( localStorage: false, type: type, data: collections ) + load: (params) -> @log 'debug', 'load', params