diff options
author | Peter Kozak <spag@golwen.net> | 2013-03-18 01:54:56 -0400 |
---|---|---|
committer | Peter Kozak <spag@golwen.net> | 2013-03-18 01:54:56 -0400 |
commit | b22b802c80649fb9ee1925cc9ab5a2a959fc89ab (patch) | |
tree | 74cd845bd6363b56a06a81c6cfb2cc107f9e2c67 /app/controllers | |
parent | 208c0bbb9b7b744febbf288f56a3926561cd001b (diff) | |
parent | d007b83d1d6b51caea93b5f08f449db88a930a16 (diff) |
Merge branch 'develop' of github.com:amooma/GS5 into develop
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/trigger_controller.rb | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/app/controllers/trigger_controller.rb b/app/controllers/trigger_controller.rb index a858e33..6b58d6a 100644 --- a/app/controllers/trigger_controller.rb +++ b/app/controllers/trigger_controller.rb @@ -92,19 +92,26 @@ class TriggerController < ApplicationController def sip_account_update sip_account = SipAccount.find(params[:id]) - # TO-DO: Only update the neccessary entries. - # - SwitchboardEntry.all.each do |switchboard_entry| - new_html = ActionController::Base.helpers.escape_javascript(render_to_string("switchboard_entries/_switchboard_entry", :layout => false, :locals => {:switchboard_entry => switchboard_entry})) - PrivatePub.publish_to("/switchboards/#{switchboard_entry.switchboard.id}", "$('#switchboard_entry_id_" + switchboard_entry.id.to_s + "').replaceWith('#{new_html}');") - end + if sip_account.updated_at < Time.now - Switchboard.all.each do |switchboard| - if sip_account.call_legs.where(:sip_account_id => switchboard.user.sip_account_ids).any? || - sip_account.b_call_legs.where(:sip_account_id => switchboard.user.sip_account_ids).any? - new_html = ActionController::Base.helpers.escape_javascript(render_to_string("switchboards/_current_user_dashboard", :layout => false, :locals => {:current_user => switchboard.user})) - PrivatePub.publish_to("/switchboards/#{switchboard.id}", "$('.dashboard').replaceWith('#{new_html}');") + # Push an update to sip_account.switchboard_entries + # + sip_account.switchboard_entries.each do |switchboard_entry| + escaped_switchboard_entry_partial = ActionController::Base.helpers.escape_javascript(render_to_string("switchboard_entries/_switchboard_entry", :layout => false, :locals => {:switchboard_entry => switchboard_entry})) + PrivatePub.publish_to("/switchboards/#{switchboard_entry.switchboard.id}", "$('#switchboard_entry_id_" + switchboard_entry.id.to_s + "').replaceWith('#{escaped_switchboard_entry_partial}');") end + + # Push an update to the needed switchboards + # + Switchboard.where(:user_id => sip_account.sip_accountable.id).each do |switchboard| + if sip_account.call_legs.where(:sip_account_id => switchboard.user.sip_account_ids).any? || + sip_account.b_call_legs.where(:sip_account_id => switchboard.user.sip_account_ids).any? + escaped_switchboard_partial = ActionController::Base.helpers.escape_javascript(render_to_string("switchboards/_current_user_dashboard", :layout => false, :locals => {:current_user => switchboard.user})) + PrivatePub.publish_to("/switchboards/#{switchboard.id}", "$('.dashboard').replaceWith('#{escaped_switchboard_partial}');") + end + end + + sip_account.touch end render( |