diff --git a/app/assets/javascripts/app/models/_application_model.js.coffee b/app/assets/javascripts/app/models/_application_model.js.coffee index 1f705e942..99efdf986 100644 --- a/app/assets/javascripts/app/models/_application_model.js.coffee +++ b/app/assets/javascripts/app/models/_application_model.js.coffee @@ -291,7 +291,7 @@ class App.Model extends Spine.Model # subscribe and render data after local change @bind( - 'refresh change' + 'change' (items) => # check if result is array or singel item @@ -301,7 +301,26 @@ class App.Model extends Spine.Model for item in items for key, callback of App[ @className ].SUBSCRIPTION_ITEM[ item.id ] item = App[ @className ]._fillUp( item ) - callback(item) + callback(item, 'change') + ) + + @changeTable = {} + @bind( + 'refresh' + (items) => + + # check if result is array or singel item + if !_.isArray(items) + items = [items] + + for item in items + for key, callback of App[ @className ].SUBSCRIPTION_ITEM[ item.id ] + + # only trigger callbacks if object has changed + if !@changeTable[key] || @changeTable[key] isnt item.updated_at + @changeTable[key] = item.updated_at + item = App[ @className ]._fillUp( item ) + callback(item, 'refresh') ) # subscribe and render data after server change