summaryrefslogtreecommitdiff
path: root/app/models/softkey.rb
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-02-12 13:53:28 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-02-12 13:53:28 +0100
commitc9066760fd1f5f2f892ce2be5cf2a83bb5210246 (patch)
tree82ecdd528e803ccd1b469dc13482e06cf8ea0b8e /app/models/softkey.rb
parent0b97717b2171820dea41de8df705f8f0e4b71464 (diff)
parentfb66a5e5a4c5d5f9eac4a5e8de6a286482cb55d5 (diff)
Release a new beta.5.1-beta4
Diffstat (limited to 'app/models/softkey.rb')
-rw-r--r--app/models/softkey.rb32
1 files changed, 15 insertions, 17 deletions
diff --git a/app/models/softkey.rb b/app/models/softkey.rb
index a709036..83c88ab 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,21 +75,22 @@ 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
- end
- if ['call_forwarding'].include?(self.softkey_function.name)
+ if self.softkey_function_id != nil
+ case self.softkey_function.name
+ when 'blf'
+ self.softkeyable = PhoneNumber.where(:number => self.number, :phone_numberable_type => 'SipAccount').first.try(:phone_numberable)
+ when 'conference'
+ self.softkeyable = PhoneNumber.where(:number => self.number, :phone_numberable_type => 'Conference').first.try(:phone_numberable)
+ when 'call_forwarding'
+ self.softkeyable = CallForward.where(:id => self.softkeyable_id).first
self.number = nil
+ else
+ self.softkeyable_id = nil
+ self.softkeyable_type = nil
end
end
end