diff --git a/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee b/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee index f01d98b91..611dc0809 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee @@ -122,6 +122,12 @@ class App.ControllerGenericIndex extends App.ControllerContent }, ], ) + App.Event.bind( + @genericObject+ ':created ' + @genericObject + ':updated ' + @genericObject + ':destroy' + => + App[ @genericObject ].fetch() + 'page' + ) App[ @genericObject ].bind 'ajaxError', (rec, msg) => @log 'error', 'ajax', msg.status @@ -139,7 +145,7 @@ class App.ControllerGenericIndex extends App.ControllerContent render: => - objects = App.Collection.all( + objects = App.Collection.all( type: @genericObject, sortBy: @defaultSortBy || 'name', ) diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee index a5c61f802..8d29b5572 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee @@ -23,7 +23,7 @@ class App.TicketZoom extends App.Controller # fetch new data if triggered App.Event.bind( - 'ticket:updated' + 'Ticket:updated' (data) => update = => if data.id.toString() is @ticket_id.toString() diff --git a/app/models/application_model.rb b/app/models/application_model.rb index ad6243939..2519cfa26 100644 --- a/app/models/application_model.rb +++ b/app/models/application_model.rb @@ -2,6 +2,7 @@ require 'cache' require 'user_info' +require 'session' class ApplicationModel < ActiveRecord::Base self.abstract_class = true @@ -206,4 +207,43 @@ class ApplicationModel < ActiveRecord::Base raise "Need name for create_or_update()" end end + + def notify_clients_after_create + + # return if we run import mode + return if Setting.get('import_mode') + + class_name = self.class.name + class_name.gsub!(/::/, '') + Session.broadcast( + :event => class_name + ':created', + :data => { :id => self.id, :updated_at => self.updated_at } + ) + end + + def notify_clients_after_update + + # return if we run import mode + return if Setting.get('import_mode') + puts "#{self.class.name.downcase} UPDATED " + self.updated_at.to_s + class_name = self.class.name + class_name.gsub!(/::/, '') + Session.broadcast( + :event => class_name + ':updated', + :data => { :id => self.id, :updated_at => self.updated_at } + ) + end + + def notify_clients_after_destroy + + # return if we run import mode + return if Setting.get('import_mode') + puts "#{self.class.name.downcase} DESTOY " + self.updated_at.to_s + class_name = self.class.name + class_name.gsub!(/::/, '') + Session.broadcast( + :event => class_name + ':destroy', + :data => { :id => self.id, :updated_at => self.updated_at } + ) + end end