summaryrefslogtreecommitdiff
path: root/app/models
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 /app/models
parentcd909970e8443ca86ad0be09b26cf5fb616ea303 (diff)
softkey-call_forward relation polymorphic
Diffstat (limited to 'app/models')
-rw-r--r--app/models/call_forward.rb2
-rw-r--r--app/models/softkey.rb19
2 files changed, 7 insertions, 14 deletions
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