summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorspag <spag@golwen.net>2013-02-08 10:41:18 +0100
committerspag <spag@golwen.net>2013-02-08 10:41:18 +0100
commit9e723519982c3b442aa90f3728bfddd4025d4a69 (patch)
tree928c98fab134d0f3106119c6a094e3606a6727af
parentcd909970e8443ca86ad0be09b26cf5fb616ea303 (diff)
softkey-call_forward relation polymorphic
-rw-r--r--app/controllers/config_siemens_controller.rb12
-rw-r--r--app/controllers/config_snom_controller.rb44
-rw-r--r--app/models/call_forward.rb2
-rw-r--r--app/models/softkey.rb19
-rw-r--r--app/views/gs_nodes/sync.xml.haml2
-rw-r--r--app/views/softkeys/show.html.haml4
-rw-r--r--db/migrate/20130208065700_add_softkeyable_to_softkey.rb16
-rw-r--r--lib/tasks/gs_cluster.rake8
8 files changed, 75 insertions, 32 deletions
diff --git a/app/controllers/config_siemens_controller.rb b/app/controllers/config_siemens_controller.rb
index b7fa107..bbeba46 100644
--- a/app/controllers/config_siemens_controller.rb
+++ b/app/controllers/config_siemens_controller.rb
@@ -610,15 +610,21 @@ class ConfigSiemensController < ApplicationController
@new_settings << ['stimulus-led-control-uri', key_idx, '' ]
@new_settings << ['stimulus-DTMF-sequence', key_idx, '' ]
when 'call_forwarding'
+ if sk.softkeyable.class == CallForward then
@new_settings << ['function-key-def', key_idx, '63']
- @new_settings << ['stimulus-led-control-uri', key_idx, "f-cftg-#{sk.call_forward_id}" ]
+ @new_settings << ['stimulus-led-control-uri', key_idx, "f-cftg-#{sk.softkeyable.id}" ]
@new_settings << ['send-url-address', key_idx, request.host]
@new_settings << ['send-url-protocol', key_idx, 3]
@new_settings << ['send-url-port', key_idx, '80']
@new_settings << ['send-url-path', key_idx, "/config_siemens/#{@phone.id}/#{@sip_account.id}/call_forwarding.xml"]
- @new_settings << ['send-url-query', key_idx, "id=#{sk.call_forward_id}&function=toggle"]
+ @new_settings << ['send-url-query', key_idx, "id=#{sk.softkeyable.id}&function=toggle"]
@new_settings << ['send-url-method', key_idx, '0']
@new_settings << ['blf-popup', key_idx, 'false']
+ else
+ @new_settings << ['function-key-def', key_idx, '0']
+ @new_settings << ['stimulus-led-control-uri', key_idx, '' ]
+ @new_settings << ['stimulus-DTMF-sequence', key_idx, '' ]
+ end
when 'call_forwarding_always'
phone_number = PhoneNumber.where(:number => sk.number, :phone_numberable_type => 'SipAccount').first
if phone_number
@@ -887,7 +893,7 @@ class ConfigSiemensController < ApplicationController
if @call_forwarding_id
call_forwarding = @sip_account.call_forwards.where(:id => @call_forwarding_id).first
- if !call_forwarding and @sip_account.softkeys.where(:call_forward_id => @call_forwarding_id).count > 0
+ if !call_forwarding and @sip_account.softkeys.where(:softkeyable_id => @call_forwarding_id, :softkeyable_type => 'CallForward').count > 0
call_forwarding = CallForward.where(:id => @call_forwarding_id).first
end
diff --git a/app/controllers/config_snom_controller.rb b/app/controllers/config_snom_controller.rb
index 33b63da..58cced2 100644
--- a/app/controllers/config_snom_controller.rb
+++ b/app/controllers/config_snom_controller.rb
@@ -282,23 +282,47 @@ class ConfigSnomController < ApplicationController
@softkeys.push({:context => sip_account_index, :label => softkey.label, :data => "speed f-li-#{softkey.number}"})
when 'conference'
@softkeys.push({:context => sip_account_index, :label => softkey.label, :data => "blf <sip:#{softkey.number}@#{sip_account.host}>|f-ta-"})
- when 'call_forwarding'
+ when 'call_parking'
@softkeys.push({
:context => sip_account_index,
- :function => softkey.function,
+ :function => softkey.softkey_function.name,
:label => softkey.label,
:softkey => softkey,
:general_type => t("softkeys.functions.#{softkey.softkey_function.name}"),
:subscription => {
- :to => "f-cftg-#{softkey.call_forward_id}@#{sip_account.host}",
+ :to => "park+#{@softkeys.softkeyable_id}@#{sip_account.host}",
:for => "#{sip_account.auth_name}@#{sip_account.host}"
},
:actions => [{
- :type => :url,
- :target => "#{request.protocol}#{request.host_with_port}/config_snom/#{@phone.id}/#{snom_sip_account[:id]}/call_forwarding.xml?id=#{softkey.call_forward_id}&function=toggle",
+ :type => :dial,
+ :target => "f-tpark-#{@softkeys.softkeyable_id}",
+ :when => 'on press',
+ :states => 'connected,holding',
+ },{
+ :type => :dial,
+ :target => "f-park-#{@softkeys.softkeyable_id}",
:when => 'on press',
}],
})
+ when 'call_forwarding'
+ if softkey.softkeyable.class == CallForward then
+ @softkeys.push({
+ :context => sip_account_index,
+ :function => softkey.softkey_function.name,
+ :label => softkey.label,
+ :softkey => softkey,
+ :general_type => t("softkeys.functions.#{softkey.softkey_function.name}"),
+ :subscription => {
+ :to => "f-cftg-#{softkey.softkeyable_id}@#{sip_account.host}",
+ :for => "#{sip_account.auth_name}@#{sip_account.host}"
+ },
+ :actions => [{
+ :type => :url,
+ :target => "#{request.protocol}#{request.host_with_port}/config_snom/#{@phone.id}/#{snom_sip_account[:id]}/call_forwarding.xml?id=#{softkey.softkeyable_id}&function=toggle",
+ :when => 'on press',
+ }],
+ })
+ end
when 'call_forwarding_always'
phone_number = PhoneNumber.where(:number => softkey.number, :phone_numberable_type => 'SipAccount').first
if phone_number
@@ -310,7 +334,7 @@ class ConfigSnomController < ApplicationController
@softkeys.push({
:context => sip_account_index,
- :function => softkey.function,
+ :function => softkey.softkey_function.name,
:label => softkey.label,
:softkey => softkey,
:general_type => t("softkeys.functions.#{softkey.softkey_function.name}"),
@@ -335,7 +359,7 @@ class ConfigSnomController < ApplicationController
@softkeys.push({
:context => sip_account_index,
- :function => softkey.function,
+ :function => softkey.softkey_function.name,
:label => softkey.label,
:softkey => softkey,
:general_type => t("softkeys.functions.#{softkey.softkey_function.name}"),
@@ -375,7 +399,7 @@ class ConfigSnomController < ApplicationController
if hunt_group_member
@softkeys.push({
:context => sip_account_index,
- :function => softkey.function,
+ :function => softkey.softkey_function.name,
:label => softkey.label,
:softkey => softkey,
:general_type => t("softkeys.functions.#{softkey.softkey_function.name}"),
@@ -405,7 +429,7 @@ class ConfigSnomController < ApplicationController
if acd_agent
@softkeys.push({
:context => sip_account_index,
- :function => softkey.function,
+ :function => softkey.softkey_function.name,
:label => softkey.label,
:softkey => softkey,
:general_type => t("softkeys.functions.#{softkey.softkey_function.name}"),
@@ -924,7 +948,7 @@ AAAA'
if @call_forwarding_id
call_forwarding = @sip_account.call_forwards.where(:id => @call_forwarding_id).first
- if !call_forwarding and @sip_account.softkeys.where(:call_forward_id => @call_forwarding_id).count > 0
+ if !call_forwarding and @sip_account.softkeys.where(:softkeyable_id => @call_forwarding_id, :softkeyable_type => 'CallForward').count > 0
call_forwarding = CallForward.where(:id => @call_forwarding_id).first
end
diff --git a/app/models/call_forward.rb b/app/models/call_forward.rb
index 8a8d1df..c668993 100644
--- a/app/models/call_forward.rb
+++ b/app/models/call_forward.rb
@@ -145,7 +145,7 @@ class CallForward < ActiveRecord::Base
softkey_function_deactivated = SoftkeyFunction.find_by_name('deactivated')
self.softkeys.each do |softkey|
if softkey.softkey_function_id != softkey_function_deactivated.id
- softkey.update_attributes(:call_forward_id => nil, :softkey_function_id => softkey_function_deactivated.id)
+ softkey.update_attributes(:softkeyable_id => nil, :softkeyable_type => nil, :softkey_function_id => softkey_function_deactivated.id)
end
end
end
diff --git a/app/models/softkey.rb b/app/models/softkey.rb
index a709036..f038acd 100644
--- a/app/models/softkey.rb
+++ b/app/models/softkey.rb
@@ -1,13 +1,11 @@
class Softkey < ActiveRecord::Base
- attr_accessible :softkey_function_id, :number, :label, :call_forward_id, :uuid
+ attr_accessible :softkey_function_id, :number, :label, :uuid, :softkeyable_type, :softkeyable_id
belongs_to :sip_account
belongs_to :softkey_function
- belongs_to :call_forward
+ belongs_to :softkeyable, :polymorphic => true
- # Any CallForward BLF must have a valid softkey_call_forward_id.
- #
- validates_presence_of :call_forward_id, :if => Proc.new{ |softkey| self.softkey_function_id != nil &&
+ validates_presence_of :softkeyable_id, :if => Proc.new{ |softkey| self.softkey_function_id != nil &&
self.softkey_function_id == SoftkeyFunction.find_by_name('call_forwarding').try(:id) }
# These functions need a number to act.
@@ -21,7 +19,6 @@ class Softkey < ActiveRecord::Base
acts_as_list :scope => :sip_account
before_validation :clean_up_and_leave_only_values_which_make_sense_for_the_current_softkey_function_id
- after_validation :save_function_name_in_function, :if => Proc.new{ |softkey| self.call_forward_id.blank? }
after_save :resync_phone
after_destroy :resync_phone
@@ -52,7 +49,7 @@ class Softkey < ActiveRecord::Base
def to_s
if (['call_forwarding'].include?(self.softkey_function.name))
- "#{self.call_forward}"
+ "#{self.softkeyable}"
else
if ['log_out', 'log_in'].include?(self.softkey_function.name)
I18n.t("softkeys.functions.#{self.softkey_function.name}")
@@ -78,18 +75,14 @@ class Softkey < ActiveRecord::Base
end
private
-
- def save_function_name_in_function
- self.function = self.softkey_function.name
- end
-
# Make sure that no number is set when there is no need for one.
# And make sure that there is no CallForward connected when not needed.
#
def clean_up_and_leave_only_values_which_make_sense_for_the_current_softkey_function_id
if self.softkey_function_id != nil
if ['blf','speed_dial','dtmf','conference'].include?(self.softkey_function.name)
- self.call_forward_id = nil
+ self.softkeyable_id = nil
+ self.softkeyable_type = nil
end
if ['call_forwarding'].include?(self.softkey_function.name)
self.number = nil
diff --git a/app/views/gs_nodes/sync.xml.haml b/app/views/gs_nodes/sync.xml.haml
index 0f097f8..a2fa71a 100644
--- a/app/views/gs_nodes/sync.xml.haml
+++ b/app/views/gs_nodes/sync.xml.haml
@@ -60,7 +60,7 @@
- if !@softkeys.blank?
%softkeys
- @softkeys.each do |softkey|
- %softkey{ :uuid => softkey.uuid, :function => softkey.softkey_function.try(:name), :number => softkey.number, :label => softkey.label, :position => softkey.position, :created_at => softkey.created_at, :updated_at => softkey.updated_at, :sip_account_uuid => softkey.sip_account.try(:uuid), :call_forward_uuid => softkey.call_forward.try(:uuid) }
+ %softkey{ :uuid => softkey.uuid, :function => softkey.softkey_function.try(:name), :number => softkey.number, :label => softkey.label, :position => softkey.position, :created_at => softkey.created_at, :updated_at => softkey.updated_at, :sip_account_uuid => softkey.sip_account.try(:uuid), :softkeyable_uuid => softkey.softkeyable.try(:uuid), :softkeyable_type => softkey.softkeyable_type) }
- if !@ringtones.blank?
%ringtones
diff --git a/app/views/softkeys/show.html.haml b/app/views/softkeys/show.html.haml
index d0db111..7c068ae 100644
--- a/app/views/softkeys/show.html.haml
+++ b/app/views/softkeys/show.html.haml
@@ -1,7 +1,7 @@
- content_for :title, t("softkeys.show.page_title")
%p
- %strong= t('softkeys.show.function') + ":"
+ %strong= t("softkeys.functions.#{@softkey.softkey_function}") + ":"
=@softkey.to_s
-= render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @softkey.sip_account, :child => @softkey } \ No newline at end of file
+= render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @softkey.sip_account, :child => @softkey }
diff --git a/db/migrate/20130208065700_add_softkeyable_to_softkey.rb b/db/migrate/20130208065700_add_softkeyable_to_softkey.rb
new file mode 100644
index 0000000..deae9a0
--- /dev/null
+++ b/db/migrate/20130208065700_add_softkeyable_to_softkey.rb
@@ -0,0 +1,16 @@
+class AddSoftkeyableToSoftkey < ActiveRecord::Migration
+ def up
+ add_column :softkeys, :softkeyable_type, :string
+ add_column :softkeys, :softkeyable_id, :integer
+ Softkey.where('call_forward_id > 0').each do |softkey|
+ softkey.update_attributes( :softkeyable_type => 'CallForward', :softkeyable_id => softkey.call_forward_id )
+ end
+ remove_column :softkeys, :call_forward_id
+ end
+
+ def down
+ remove_column :softkeys, :softkeyable_type
+ remove_column :softkeys, :softkeyable_id
+ add_column :softkeys, :call_forward_id, :integer
+ end
+end
diff --git a/lib/tasks/gs_cluster.rake b/lib/tasks/gs_cluster.rake
index 7b49ebb..c248c32 100644
--- a/lib/tasks/gs_cluster.rake
+++ b/lib/tasks/gs_cluster.rake
@@ -201,10 +201,14 @@ namespace :gs_cluster do
remote_objects(remote_site, local_node_id, last_sync, Softkey).each do |remote_object|
attributes = make_hash(remote_object.attributes)
attributes[:sip_account_id] = SipAccount.where(:uuid => attributes[:sip_account_uuid]).first.try(:id)
- attributes[:call_forward_id] = CallForward.where(:uuid => attributes[:call_forward_uuid]).first.try(:id)
+
+ if ! attributes[:softkeyable_uuid].blank?
+ attributes[:softkeyable_id] = attributes[:softkeyable_type].constantize.where(:uuid => attributes[:softkeyable_uuid]).first.try(:id)
+ end
+
attributes[:softkey_function_id] = SoftkeyFunction.where(:name => attributes[:function]).first.try(:id)
attributes.delete(:sip_account_uuid)
- attributes.delete(:call_forward_uuid)
+ attributes.delete(:softkeyable_uuid)
attributes.delete(:softkey_function)
process_object(Softkey, Softkey, Softkey.where(:uuid => attributes[:uuid]).first, attributes)
end