summaryrefslogtreecommitdiff
path: root/app/models/call_forward.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/call_forward.rb')
-rw-r--r--app/models/call_forward.rb32
1 files changed, 16 insertions, 16 deletions
diff --git a/app/models/call_forward.rb b/app/models/call_forward.rb
index 195ac36..a4bfbb5 100644
--- a/app/models/call_forward.rb
+++ b/app/models/call_forward.rb
@@ -2,7 +2,7 @@ class CallForward < ActiveRecord::Base
attr_accessor :to_voicemail, :hunt_group_id
- attr_accessible :phone_number_id, :call_forward_case_id, :timeout,
+ attr_accessible :call_forward_case_id, :timeout,
:destination, :source, :depth, :active, :to_voicemail,
:hunt_group_id,
:call_forwardable_type, :call_forwardable_id,
@@ -56,7 +56,8 @@ class CallForward < ActiveRecord::Base
end
}
- before_save :split_and_format_destination_numbers
+ before_validation :resolve_prerouting
+
after_save :set_presence
after_save :deactivate_concurring_entries, :if => Proc.new { |cf| cf.active == true }
before_destroy :deactivate_connected_softkeys
@@ -71,7 +72,7 @@ class CallForward < ActiveRecord::Base
else
destinationable_type = " #{self.destinationable_type}"
end
- if self.destinationable
+ if Module.constants.include?(destinationable_type.to_sym) && self.destinationable
destination = "#{self.destinationable}#{destinationable_type}"
else
destination = "#{self.destination}#{destinationable_type}"
@@ -102,19 +103,6 @@ class CallForward < ActiveRecord::Base
end
private
- def split_and_format_destination_numbers
- if !self.destination.blank?
- destinations = self.destination.gsub(/[^+0-9\,]/,'').gsub(/[\,]+/,',').split(/\,/).delete_if{|x| x.blank?}
- self.destination = nil
- if destinations.count > 0
- destinations.each do |single_destination|
- self.destination = self.destination.to_s + ", #{PhoneNumber.parse_and_format(single_destination)}"
- end
- end
- self.destination = self.destination.to_s.gsub(/[^+0-9\,]/,'').gsub(/[\,]+/,',').split(/\,/).sort.delete_if{|x| x.blank?}.join(', ')
- end
- end
-
def set_presence
state = 'terminated'
@@ -149,6 +137,18 @@ class CallForward < ActiveRecord::Base
end
end
+ def resolve_prerouting
+ if self.destinationable_type == 'PhoneNumber' && GsParameter.get('CALLFORWARD_DESTINATION_RESOLVE') != false
+ if self.call_forwardable.class == PhoneNumber
+ prerouting = PhoneNumber.resolve_prerouting(self.destination, self.call_forwardable.phone_numberable)
+ else
+ prerouting = PhoneNumber.resolve_prerouting(self.destination, self.call_forwardable)
+ end
+ if prerouting && !prerouting['destination_number'].blank? && prerouting['type'] == 'phonenumber'
+ self.destination = prerouting['destination_number']
+ end
+ end
+ end
def send_presence_event(state, call_forwarding_service = nil)
dialplan_function = "cftg-#{self.id}"