summaryrefslogtreecommitdiff
path: root/app/controllers/call_forwards_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/call_forwards_controller.rb')
-rw-r--r--app/controllers/call_forwards_controller.rb104
1 files changed, 94 insertions, 10 deletions
diff --git a/app/controllers/call_forwards_controller.rb b/app/controllers/call_forwards_controller.rb
index b30ee9e..1721aa3 100644
--- a/app/controllers/call_forwards_controller.rb
+++ b/app/controllers/call_forwards_controller.rb
@@ -30,6 +30,7 @@ class CallForwardsController < ApplicationController
@call_forward.active = true
@call_forwarding_destinations = call_forwarding_destination_types()
@call_forward.destination = GsParameter.get('CALLFORWARD_DESTINATION_DEFAULT').to_s if defined?(GsParameter.get('CALLFORWARD_DESTINATION_DEFAULT'))
+ @destination_phone_number = @call_forward.destination
@available_call_forward_cases = []
CallForwardCase.all.each do |available_call_forward_case|
@@ -45,6 +46,8 @@ class CallForwardsController < ApplicationController
@call_forward.call_forward_case_id = CallForwardCase.find_by_value('noanswer').id
@call_forward.timeout = 45
end
+
+ @available_greetings = available_greetings()
end
def create
@@ -62,6 +65,8 @@ class CallForwardsController < ApplicationController
def edit
@available_call_forward_cases = CallForwardCase.all
@call_forwarding_destinations = call_forwarding_destination_types()
+ @available_greetings = available_greetings()
+ @destination_phone_number = @call_forward.destination if @call_forward.call_forwarding_destination == ':PhoneNumber'
end
def update
@@ -82,7 +87,6 @@ class CallForwardsController < ApplicationController
end
private
- private
def set_and_authorize_parent
@parent = @phone_number || @sip_account || @automatic_call_distributor || @hunt_group
authorize! :read, @parent
@@ -92,6 +96,14 @@ class CallForwardsController < ApplicationController
if @parent
if @parent.class == PhoneNumber && @parent.phone_numberable_type == 'SipAccount'
@sip_account = @parent.phone_numberable
+ elsif @parent.class == PhoneNumber && @parent.phone_numberable_type == 'HuntGroup'
+ add_breadcrumb t("hunt_groups.index.page_title"), tenant_hunt_groups_path(@parent.phone_numberable.tenant)
+ add_breadcrumb @parent.phone_numberable, tenant_hunt_group_path(@parent.phone_numberable.tenant, @parent.phone_numberable)
+ add_breadcrumb t("phone_numbers.index.page_title"), hunt_group_phone_numbers_path(@parent.phone_numberable)
+ add_breadcrumb @parent, hunt_group_phone_number_path(@parent.phone_numberable, @parent)
+ elsif @parent.class == HuntGroup
+ add_breadcrumb t("hunt_groups.index.page_title"), tenant_hunt_groups_path(@parent.tenant)
+ add_breadcrumb @parent, tenant_hunt_group_path(@parent.tenant, @parent)
end
if @sip_account
@@ -127,29 +139,101 @@ class CallForwardsController < ApplicationController
end
def call_forwarding_destination_types
-
+ destinations_hash = {}
phone_number_destination = CallForwardingDestination.new()
phone_number_destination.id = ':PhoneNumber'
phone_number_destination.label = 'Phone Number'
- voice_mail_destination = CallForwardingDestination.new()
- voice_mail_destination.id = ':Voicemail'
- voice_mail_destination.label = 'Voice Mail'
call_forwarding_destinations = [
phone_number_destination,
- voice_mail_destination,
]
+ if @parent.class == SipAccount || @parent.class == User || @parent.class == Tenant
+ @parent.voicemail_accounts.each do |voicemail_account|
+ call_forwards_destination = CallForwardingDestination.new()
+ call_forwards_destination.id = "#{voicemail_account.id}:VoicemailAccount"
+ call_forwards_destination.label = "VoicemailAccount: #{voicemail_account.to_s}"
+ if !destinations_hash[call_forwards_destination.id]
+ destinations_hash[call_forwards_destination.id] = true
+ call_forwarding_destinations << call_forwards_destination
+ end
+ end
+ end
+
+ if @parent.class == SipAccount
+ sip_account = @parent
+ group_ids = Group.target_group_ids_by_permission(:forward_to, sip_account.groups)
+
+ if sip_account.sip_accountable.class == User || sip_account.sip_accountable.class == Tenant
+ group_ids = group_ids + Group.target_group_ids_by_permission(:forward_to, sip_account.sip_accountable.groups)
+ sip_account.sip_accountable.voicemail_accounts.each do |voicemail_account|
+ call_forwards_destination = CallForwardingDestination.new()
+ call_forwards_destination.id = "#{voicemail_account.id}:VoicemailAccount"
+ call_forwards_destination.label = "VoicemailAccount: #{voicemail_account.to_s}"
+ if !destinations_hash[call_forwards_destination.id]
+ destinations_hash[call_forwards_destination.id] = true
+ call_forwarding_destinations << call_forwards_destination
+ end
+ end
+ end
+
+ GroupMembership.where(:group_id => group_ids, :item_type => 'VoicemailAccount').each do |group_member|
+ call_forwards_destination = CallForwardingDestination.new()
+ call_forwards_destination.id = "#{group_member.item.id}:VoicemailAccount"
+ call_forwards_destination.label = "VoicemailAccount: #{group_member.item.to_s}"
+ if !destinations_hash[call_forwards_destination.id]
+ destinations_hash[call_forwards_destination.id] = true
+ call_forwarding_destinations << call_forwards_destination
+ end
+ end
+ end
+
+ if @parent.class == PhoneNumber
+ if @parent.phone_numberable.class == SipAccount
+ sip_account = @parent.phone_numberable
+ if sip_account.sip_accountable.class == User || sip_account.sip_accountable.class == Tenant
+ sip_account.sip_accountable.voicemail_accounts.each do |voicemail_account|
+ call_forwards_destination = CallForwardingDestination.new()
+ call_forwards_destination.id = "#{voicemail_account.id}:VoicemailAccount"
+ call_forwards_destination.label = "VoicemailAccount: #{voicemail_account.to_s}"
+ if !destinations_hash[call_forwards_destination.id]
+ destinations_hash[call_forwards_destination.id] = true
+ call_forwarding_destinations << call_forwards_destination
+ end
+ end
+ end
+ end
+ end
+
if GuiFunction.display?('huntgroup_in_destination_field_in_call_forward_form', current_user)
HuntGroup.all.each do |hunt_group|
- hunt_group_destination = CallForwardingDestination.new()
- hunt_group_destination.id = "#{hunt_group.id}:HuntGroup"
- hunt_group_destination.label = "HuntGroup: #{hunt_group.to_s}"
- call_forwarding_destinations.push(hunt_group_destination)
+ call_forwards_destination = CallForwardingDestination.new()
+ call_forwards_destination.id = "#{hunt_group.id}:HuntGroup"
+ call_forwards_destination.label = "HuntGroup: #{hunt_group.to_s}"
+ if !destinations_hash[call_forwards_destination.id]
+ destinations_hash[call_forwards_destination.id] = true
+ call_forwarding_destinations << call_forwards_destination
+ end
end
end
return call_forwarding_destinations
end
+ def available_greetings
+ if @parent.class == PhoneNumber
+ owner = @parent.phone_numberable
+ else
+ owner = @parent
+ end
+
+ if owner.class == SipAccount
+ owner = owner.sip_accountable
+ elsif owner.class == FaxAccount
+ owner = owner.fax_accountable
+ end
+
+ return GenericFile.where(:category => 'greeting', :owner_type => owner.class.to_s, :owner_id => owner.id).map {|x| [x.to_s, x.name] }
+ end
+
end