diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/call_forward.rb | 2 | ||||
-rw-r--r-- | app/models/softkey.rb | 19 |
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 |