summaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/acd_agents_controller.rb32
-rw-r--r--app/controllers/application_controller.rb4
-rw-r--r--app/controllers/call_routes_controller.rb22
-rw-r--r--app/controllers/calls_controller.rb6
-rw-r--r--app/controllers/conference_invitees_controller.rb7
-rw-r--r--app/controllers/config_polycom_controller.rb4
-rw-r--r--app/controllers/config_siemens_controller.rb2
-rw-r--r--app/controllers/config_snom_controller.rb29
-rw-r--r--app/controllers/gemeinschaft_setups_controller.rb5
-rw-r--r--app/controllers/gs_nodes_controller.rb2
-rw-r--r--app/controllers/ringtones_controller.rb35
-rw-r--r--app/controllers/sip_accounts_controller.rb7
-rw-r--r--app/controllers/softkeys_controller.rb19
-rw-r--r--app/controllers/switchboard_entries_controller.rb74
-rw-r--r--app/controllers/switchboards_controller.rb66
-rw-r--r--app/controllers/trigger_controller.rb73
16 files changed, 338 insertions, 49 deletions
diff --git a/app/controllers/acd_agents_controller.rb b/app/controllers/acd_agents_controller.rb
index 4c08f68..e2aabdf 100644
--- a/app/controllers/acd_agents_controller.rb
+++ b/app/controllers/acd_agents_controller.rb
@@ -1,7 +1,7 @@
class AcdAgentsController < ApplicationController
- load_and_authorize_resource :automatic_call_distributor
- load_and_authorize_resource :acd_agent, :through => [:automatic_call_distributor]
-
+ load_and_authorize_resource :automatic_call_distributor, :except => [:toggle]
+ load_and_authorize_resource :acd_agent, :through => [:automatic_call_distributor], :except => [:toggle]
+ load_and_authorize_resource :acd_agent, :only => [:toggle]
before_filter :spread_breadcrumbs
def index
@@ -62,16 +62,24 @@ class AcdAgentsController < ApplicationController
redirect_to automatic_call_distributor_acd_agents_path(@automatic_call_distributor), :notice => t('acd_agents.controller.successfuly_destroyed')
end
+ def toggle
+ @acd_agent.toggle_status
+ redirect_to request.referer
+ end
+
+ private
def spread_breadcrumbs
- if @automatic_call_distributor.automatic_call_distributorable.class == User
- add_breadcrumb t("#{@automatic_call_distributor.automatic_call_distributorable.class.name.underscore.pluralize}.index.page_title"), method( :"tenant_#{@automatic_call_distributor.automatic_call_distributorable.class.name.underscore.pluralize}_path" ).(@automatic_call_distributor.tenant)
- add_breadcrumb @automatic_call_distributor.automatic_call_distributorable, method( :"tenant_#{@automatic_call_distributor.automatic_call_distributorable.class.name.underscore}_path" ).(@automatic_call_distributor.tenant, @automatic_call_distributor.automatic_call_distributorable)
- end
- add_breadcrumb t("automatic_call_distributors.index.page_title"), method( :"#{@automatic_call_distributor.automatic_call_distributorable.class.name.underscore}_automatic_call_distributors_path" ).(@automatic_call_distributor.automatic_call_distributorable)
- add_breadcrumb @automatic_call_distributor, method( :"#{@automatic_call_distributor.automatic_call_distributorable.class.name.underscore}_automatic_call_distributor_path" ).(@automatic_call_distributor.automatic_call_distributorable, @automatic_call_distributor)
- add_breadcrumb t("acd_agents.index.page_title"), automatic_call_distributor_acd_agents_path(@automatic_call_distributor)
- if @acd_agent && !@acd_agent.new_record?
- add_breadcrumb @acd_agent, automatic_call_distributor_acd_agent_path(@automatic_call_distributor, @acd_agent)
+ if @automatic_call_distributor
+ if @automatic_call_distributor.automatic_call_distributorable.class == User
+ add_breadcrumb t("#{@automatic_call_distributor.automatic_call_distributorable.class.name.underscore.pluralize}.index.page_title"), method( :"tenant_#{@automatic_call_distributor.automatic_call_distributorable.class.name.underscore.pluralize}_path" ).(@automatic_call_distributor.tenant)
+ add_breadcrumb @automatic_call_distributor.automatic_call_distributorable, method( :"tenant_#{@automatic_call_distributor.automatic_call_distributorable.class.name.underscore}_path" ).(@automatic_call_distributor.tenant, @automatic_call_distributor.automatic_call_distributorable)
+ end
+ add_breadcrumb t("automatic_call_distributors.index.page_title"), method( :"#{@automatic_call_distributor.automatic_call_distributorable.class.name.underscore}_automatic_call_distributors_path" ).(@automatic_call_distributor.automatic_call_distributorable)
+ add_breadcrumb @automatic_call_distributor, method( :"#{@automatic_call_distributor.automatic_call_distributorable.class.name.underscore}_automatic_call_distributor_path" ).(@automatic_call_distributor.automatic_call_distributorable, @automatic_call_distributor)
+ add_breadcrumb t("acd_agents.index.page_title"), automatic_call_distributor_acd_agents_path(@automatic_call_distributor)
+ if @acd_agent && !@acd_agent.new_record?
+ add_breadcrumb @acd_agent, automatic_call_distributor_acd_agent_path(@automatic_call_distributor, @acd_agent)
+ end
end
end
end
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index d1d918e..12bea54 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -110,6 +110,10 @@ class ApplicationController < ActionController::Base
redirect_to log_in_path, :alert => 'Access denied! You need to login first.'
end
end
+
+ def request_remote_ip
+ request.env['HTTP_X_FORWARDED_FOR'] || request.remote_ip
+ end
private
diff --git a/app/controllers/call_routes_controller.rb b/app/controllers/call_routes_controller.rb
index 2dcd648..e5cf56a 100644
--- a/app/controllers/call_routes_controller.rb
+++ b/app/controllers/call_routes_controller.rb
@@ -87,6 +87,28 @@ class CallRoutesController < ApplicationController
end
end
+ def test
+ if !params[:sip_account_id].blank?
+ account = SipAccount.where(:id => params[:sip_account_id]).first
+ elsif !params[:hunt_group_id].blank?
+ account = HuntGroup.where(:id => params[:hunt_group_id]).first
+ end
+
+ if account
+ destination_number = params[:destination_number]
+ routing_table = params[:routing_table]
+ @route_test = CallRoute.test_route(routing_table, {
+ 'caller.destination_number' => destination_number,
+ 'caller.auth_account_type' => account.class.name,
+ 'caller.auth_account_id' => account.id,
+ 'caller.auth_account_uuid' => account.try(:uuid),
+ 'caller.account_type' => account.class.name,
+ 'caller.account_id' => account.id,
+ 'caller.account_uuid' => account.try(:uuid),
+ })
+ end
+ end
+
private
def call_route_parameter_params
params.require(:call_route).permit(:routing_table, :name, :endpoint_type, :endpoint_id, :position)
diff --git a/app/controllers/calls_controller.rb b/app/controllers/calls_controller.rb
index 9d85a10..ae0093c 100644
--- a/app/controllers/calls_controller.rb
+++ b/app/controllers/calls_controller.rb
@@ -17,11 +17,11 @@ class CallsController < ApplicationController
if !params[:url].blank?
protocol, separator, phone_number = params[:url].partition(':')
if ! phone_number.blank?
- @call = @parent.calls.new()
+ @call = @parent.call_legs.new()
@call.destination = phone_number
end
elsif !params[:number].blank?
- @call = @parent.calls.new()
+ @call = @parent.call_legs.new()
@call.destination = params[:number]
end
end
@@ -31,7 +31,7 @@ class CallsController < ApplicationController
end
def create
- @call = @sip_account.calls.create(params[:call])
+ @call = @sip_account.call_legs.build(params[:call])
if @call && @call.call
m = method( :"#{@parent.class.name.underscore}_calls_url" )
diff --git a/app/controllers/conference_invitees_controller.rb b/app/controllers/conference_invitees_controller.rb
index e891ebc..cbe4790 100644
--- a/app/controllers/conference_invitees_controller.rb
+++ b/app/controllers/conference_invitees_controller.rb
@@ -35,10 +35,7 @@ class ConferenceInviteesController < ApplicationController
end
if @conference_invitee.save
- # m = method( :"#{@parent_in_route.class.name.underscore}_path" )
- # redirect_to m.( @parent_in_route ), :notice => t('conference_invitees.controller.successfuly_created', :resource => @conference_invitees)
- m = method( :"#{@conference_invitee.conference.conferenceable_type.underscore}_conference_path")
- redirect_to m.( @conference_invitee.conference.conferenceable, @conference_invitee.conference), :notice => t('conference_invitees.controller.successfuly_created', :resource => @conference_invitees)
+ redirect_to conference_conference_invitees_url(@conference), :notice => t('conference_invitees.controller.successfuly_created')
else
render :new
end
@@ -50,7 +47,7 @@ class ConferenceInviteesController < ApplicationController
def update
if @conference_invitee.update_attributes(params[:conference_invitee])
- redirect_to @conference_invitee, :notice => t('conference_invitees.controller.successfuly_updated')
+ redirect_to conference_conference_invitees_url(@conference), :notice => t('conference_invitees.controller.successfuly_updated')
else
render :edit
end
diff --git a/app/controllers/config_polycom_controller.rb b/app/controllers/config_polycom_controller.rb
index fd730e3..ca314c2 100644
--- a/app/controllers/config_polycom_controller.rb
+++ b/app/controllers/config_polycom_controller.rb
@@ -67,8 +67,8 @@ class ConfigPolycomController < ApplicationController
if ! request.env['HTTP_USER_AGENT'].index('polycom')
Rails.logger.info "---> User-Agent indicates not a Polycom phone (#{request.env['HTTP_USER_AGENT'].inspect})"
else
- Rails.logger.info "---> Phone #{@mac_address.inspect}, IP address #{request.remote_ip.inspect}"
- @phone.update_attributes({ :ip_address => request.remote_ip })
+ Rails.logger.info "---> Phone #{@mac_address.inspect}, IP address #{request_remote_ip.inspect}"
+ @phone.update_attributes({ :ip_address => request_remote_ip })
end
xml_applications_url = "#{request.protocol}#{request.host_with_port}/config_polycom/#{@phone.id}/0"
diff --git a/app/controllers/config_siemens_controller.rb b/app/controllers/config_siemens_controller.rb
index 1966d49..7d5eb3f 100644
--- a/app/controllers/config_siemens_controller.rb
+++ b/app/controllers/config_siemens_controller.rb
@@ -146,7 +146,7 @@ class ConfigSiemensController < ApplicationController
country = 'US'
language = 'en'
if ! @phone.nil?
- @phone.update_attributes(:ip_address => request.remote_ip)
+ @phone.update_attributes(:ip_address => request_remote_ip)
@sip_account = @phone.sip_accounts.where(:sip_accountable_type => @phone.phoneable_type,
:sip_accountable_id => @phone.phoneable_id).first
diff --git a/app/controllers/config_snom_controller.rb b/app/controllers/config_snom_controller.rb
index eb94038..8db1d57 100644
--- a/app/controllers/config_snom_controller.rb
+++ b/app/controllers/config_snom_controller.rb
@@ -233,8 +233,8 @@ class ConfigSnomController < ApplicationController
if ! request.env['HTTP_USER_AGENT'].index('snom')
Rails.logger.info "---> User-Agent indicates not a Snom phone (#{request.env['HTTP_USER_AGENT'].inspect})"
else
- Rails.logger.info "---> Phone #{@mac_address.inspect}, IP address #{request.remote_ip.inspect}"
- @phone.update_attributes({ :ip_address => request.remote_ip })
+ Rails.logger.info "---> Phone #{@mac_address.inspect}, IP address #{request_remote_ip.inspect}"
+ @phone.update_attributes({ :ip_address => request_remote_ip })
end
@softkeys = Array.new()
@@ -281,7 +281,30 @@ class ConfigSnomController < ApplicationController
when 'log_in'
@softkeys.push({:context => sip_account_index, :label => softkey.label, :data => "speed f-li-#{softkey.number}"})
when 'conference'
- @softkeys.push({:context => sip_account_index, :label => softkey.label, :data => "blf <sip:#{softkey.number}@#{sip_account.host}>|f-ta-"})
+ conference = softkey.softkeyable
+ if conference.class == Conference
+ @softkeys.push({
+ :context => sip_account_index,
+ :function => softkey.softkey_function.name,
+ :label => softkey.label,
+ :softkey => softkey,
+ :general_type => t("softkeys.functions.#{softkey.softkey_function.name}"),
+ :subscription => {
+ :to => "sip:conference#{conference.id}@#{sip_account.host}",
+ :for => "sip:conference#{conference.id}@#{sip_account.host}",
+ },
+ :actions => [{
+ :type => :dial,
+ :target => "f-ta-#{softkey.number}",
+ :when => 'on press',
+ :states => 'connected,holding',
+ },{
+ :type => :dial,
+ :target => softkey.number,
+ :when => 'on press',
+ }],
+ })
+ end
when 'parking_stall'
parking_stall = softkey.softkeyable
if parking_stall.class == ParkingStall
diff --git a/app/controllers/gemeinschaft_setups_controller.rb b/app/controllers/gemeinschaft_setups_controller.rb
index a62df99..4949fa7 100644
--- a/app/controllers/gemeinschaft_setups_controller.rb
+++ b/app/controllers/gemeinschaft_setups_controller.rb
@@ -62,6 +62,11 @@ class GemeinschaftSetupsController < ApplicationController
GsParameter.where(:name => 'ringtone_url').first.update_attributes(:value => "http://#{@gemeinschaft_setup.sip_domain.host}")
GsParameter.where(:name => 'user_image_url').first.update_attributes(:value => "http://#{@gemeinschaft_setup.sip_domain.host}/uploads/user/image")
+ # Set ringback_tone
+ if @gemeinschaft_setup.country.country_code.to_s == '49'
+ GsParameter.where(:entity => 'dialplan', :section => 'variables', :name => 'ringback').first.update_attributes(:value => '%(1000,4000,425.0)')
+ end
+
# Restart FreeSWITCH
if Rails.env.production?
require 'freeswitch_event'
diff --git a/app/controllers/gs_nodes_controller.rb b/app/controllers/gs_nodes_controller.rb
index 17c9e8b..6a5e0a6 100644
--- a/app/controllers/gs_nodes_controller.rb
+++ b/app/controllers/gs_nodes_controller.rb
@@ -48,7 +48,7 @@ class GsNodesController < ApplicationController
end
def sync
- if !GsNode.where(:ip_address => request.remote_ip).first
+ if !GsNode.where(:ip_address => request_remote_ip).first
render(
:status => 404,
:layout => false,
diff --git a/app/controllers/ringtones_controller.rb b/app/controllers/ringtones_controller.rb
index e5a4f64..96e9c6d 100644
--- a/app/controllers/ringtones_controller.rb
+++ b/app/controllers/ringtones_controller.rb
@@ -49,19 +49,42 @@ class RingtonesController < ApplicationController
end
def spread_breadcrumbs
- if @parent.class == PhoneNumber && @parent.phone_numberable.class == SipAccount
- @sip_account = @parent.phone_numberable
+ if @parent.class == SipAccount
if @sip_account.sip_accountable.class == User
add_breadcrumb t("#{@sip_account.sip_accountable.class.name.underscore.pluralize}.index.page_title"), method( :"tenant_#{@sip_account.sip_accountable.class.name.underscore.pluralize}_path" ).(@sip_account.tenant)
add_breadcrumb @sip_account.sip_accountable, method( :"tenant_#{@sip_account.sip_accountable.class.name.underscore}_path" ).(@sip_account.tenant, @sip_account.sip_accountable)
end
add_breadcrumb t("sip_accounts.index.page_title"), method( :"#{@sip_account.sip_accountable.class.name.underscore}_sip_accounts_path" ).(@sip_account.sip_accountable)
add_breadcrumb @sip_account, method( :"#{@sip_account.sip_accountable.class.name.underscore}_sip_account_path" ).(@sip_account.sip_accountable, @sip_account)
- add_breadcrumb t("phone_numbers.index.page_title"), sip_account_phone_numbers_path(@sip_account)
- add_breadcrumb @phone_number, sip_account_phone_number_path(@sip_account, @phone_number)
- add_breadcrumb t("ringtones.index.page_title"), phone_number_ringtones_path(@phone_number)
+ add_breadcrumb t("ringtones.index.page_title"), sip_account_ringtones_path(@sip_account)
if @ringtone && !@ringtone.new_record?
- add_breadcrumb @ringtone, phone_number_ringtone_path(@phone_number, @ringtone)
+ add_breadcrumb @ringtone
+ end
+ elsif @parent.class == PhoneNumber
+ if @parent.phone_numberable.class == SipAccount
+ @sip_account = @parent.phone_numberable
+ if @sip_account.sip_accountable.class == User
+ add_breadcrumb t("#{@sip_account.sip_accountable.class.name.underscore.pluralize}.index.page_title"), method( :"tenant_#{@sip_account.sip_accountable.class.name.underscore.pluralize}_path" ).(@sip_account.tenant)
+ add_breadcrumb @sip_account.sip_accountable, method( :"tenant_#{@sip_account.sip_accountable.class.name.underscore}_path" ).(@sip_account.tenant, @sip_account.sip_accountable)
+ end
+ add_breadcrumb t("sip_accounts.index.page_title"), method( :"#{@sip_account.sip_accountable.class.name.underscore}_sip_accounts_path" ).(@sip_account.sip_accountable)
+ add_breadcrumb @sip_account, method( :"#{@sip_account.sip_accountable.class.name.underscore}_sip_account_path" ).(@sip_account.sip_accountable, @sip_account)
+ add_breadcrumb t("phone_numbers.index.page_title"), sip_account_phone_numbers_path(@sip_account)
+ add_breadcrumb @phone_number, sip_account_phone_number_path(@sip_account, @phone_number)
+ add_breadcrumb t("ringtones.index.page_title"), phone_number_ringtones_path(@phone_number)
+ if @ringtone && !@ringtone.new_record?
+ add_breadcrumb @ringtone
+ end
+ elsif @parent.phone_numberable.class == HuntGroup
+ @hunt_group = @parent.phone_numberable
+ add_breadcrumb t("hunt_groups.index.page_title"), method( :"#{@hunt_group.tenant.class.name.underscore}_hunt_groups_path" ).(@hunt_group.tenant)
+ add_breadcrumb @hunt_group, method( :"#{@hunt_group.tenant.class.name.underscore}_hunt_group_path" ).(@hunt_group.tenant, @hunt_group)
+ add_breadcrumb t("phone_numbers.index.page_title"), hunt_group_phone_numbers_path(@hunt_group)
+ add_breadcrumb @phone_number, hunt_group_phone_number_path(@hunt_group, @phone_number)
+ add_breadcrumb t("ringtones.index.page_title"), phone_number_ringtones_path(@phone_number)
+ if @ringtone && !@ringtone.new_record?
+ add_breadcrumb @ringtone
+ end
end
end
end
diff --git a/app/controllers/sip_accounts_controller.rb b/app/controllers/sip_accounts_controller.rb
index b34172d..0d34109 100644
--- a/app/controllers/sip_accounts_controller.rb
+++ b/app/controllers/sip_accounts_controller.rb
@@ -10,7 +10,10 @@ class SipAccountsController < ApplicationController
end
def show
- @register_tel_protocol = "#{request.protocol}#{request.host_with_port}/sip_accounts/#{@sip_account.try(:id)}/calls/new?url=%s"
+ @register_protocols = {
+ :tel => "#{request.protocol}#{request.host_with_port}/sip_accounts/#{@sip_account.try(:id)}/calls/new?url=%s",
+ :callto => "#{request.protocol}#{request.host_with_port}/sip_accounts/#{@sip_account.try(:id)}/calls/new?url=%s",
+ }
end
def new
@@ -72,7 +75,7 @@ class SipAccountsController < ApplicationController
def destroy
@sip_account.destroy
m = method( :"#{@parent.class.name.underscore}_sip_accounts_url" )
- redirect_to :root, :notice => t('sip_accounts.controller.successfuly_destroyed')
+ redirect_to m.(@parent), :notice => t('sip_accounts.controller.successfuly_destroyed')
end
private
diff --git a/app/controllers/softkeys_controller.rb b/app/controllers/softkeys_controller.rb
index 9179d8c..adb0e10 100644
--- a/app/controllers/softkeys_controller.rb
+++ b/app/controllers/softkeys_controller.rb
@@ -2,7 +2,7 @@ class SoftkeysController < ApplicationController
load_and_authorize_resource :sip_account, :except => [:sort]
load_and_authorize_resource :softkey, :through => [:sip_account], :except => [:sort]
- before_filter :set_available_softkey_functions, :only => [ :new, :edit, :update ]
+ before_filter :set_available_softkey_functions, :only => [ :new, :edit, :update, :create ]
before_filter :spread_breadcrumbs, :except => [:sort]
def index
@@ -13,8 +13,6 @@ class SoftkeysController < ApplicationController
def new
@softkey = @sip_account.softkeys.build
-
- delete_call_forward_softkey_if_no_callforward_is_available
end
def create
@@ -27,14 +25,12 @@ class SoftkeysController < ApplicationController
end
def edit
- delete_call_forward_softkey_if_no_callforward_is_available
end
def update
if @softkey.update_attributes(params[:softkey])
redirect_to sip_account_softkey_path(@softkey.sip_account, @softkey), :notice => t('softkeys.controller.successfuly_updated')
else
- delete_call_forward_softkey_if_no_callforward_is_available
render :edit
end
end
@@ -56,10 +52,13 @@ class SoftkeysController < ApplicationController
private
def set_available_softkey_functions
+ @possible_call_forwards = @softkey.possible_call_forwards
@softkey_functions = []
SoftkeyFunction.accessible_by(current_ability, :read).each do |softkey_function|
if GuiFunction.display?("softkey_function_#{softkey_function.name.downcase}_field_in_softkey_form", current_user)
- @softkey_functions << softkey_function
+ if softkey_function.name != 'call_forwarding' or @possible_call_forwards.count > 0
+ @softkey_functions << softkey_function
+ end
end
end
end
@@ -77,12 +76,4 @@ class SoftkeysController < ApplicationController
add_breadcrumb t('softkeys.index.page_title'), sip_account_softkeys_path(@sip_account)
end
end
-
- def delete_call_forward_softkey_if_no_callforward_is_available
- # Don't display the call_forward option if there aren't any call_forwards to choose from.
- #
- if @softkey.sip_account.phone_numbers.map{|phone_number| phone_number.call_forwards}.flatten.count == 0
- @softkey_functions.delete_if { |softkey_function| softkey_function == SoftkeyFunction.find_by_name('call_forwarding') }
- end
- end
end
diff --git a/app/controllers/switchboard_entries_controller.rb b/app/controllers/switchboard_entries_controller.rb
new file mode 100644
index 0000000..ef6c72e
--- /dev/null
+++ b/app/controllers/switchboard_entries_controller.rb
@@ -0,0 +1,74 @@
+class SwitchboardEntriesController < ApplicationController
+ load_and_authorize_resource :switchboard
+ authorize_resource :switchboard_entry, :through => :switchboard, :except => [:sort]
+
+ def index
+ @switchboard_entries = @switchboard.switchboard_entries
+ spread_breadcrumbs
+ end
+
+ def show
+ @switchboard_entry = @switchboard.switchboard_entries.find(params[:id])
+ spread_breadcrumbs
+ end
+
+ def new
+ @switchboard_entry = @switchboard.switchboard_entries.build
+ @sip_accounts = SipAccount.all - @switchboard.sip_accounts
+ spread_breadcrumbs
+ end
+
+ def create
+ @switchboard_entry = @switchboard.switchboard_entries.build(switchboard_entry_params)
+ spread_breadcrumbs
+ if @switchboard_entry.save
+ redirect_to switchboard_switchboard_entries_path(@switchboard), :notice => t('switchboard_entries.controller.successfuly_created')
+ else
+ render :new
+ end
+ end
+
+ def edit
+ @switchboard_entry = @switchboard.switchboard_entries.find(params[:id])
+ @sip_accounts = SipAccount.all - @switchboard.sip_accounts + [@switchboard_entry.sip_account]
+ spread_breadcrumbs
+ end
+
+ def update
+ @switchboard_entry = @switchboard.switchboard_entries.find(params[:id])
+ if @switchboard_entry.update_attributes(switchboard_entry_params)
+ redirect_to [@switchboard, @switchboard_entry], :notice => t('switchboard_entries.controller.successfuly_updated')
+ else
+ render :edit
+ end
+ end
+
+ def destroy
+ @switchboard_entry = @switchboard.switchboard_entries.find(params[:id])
+ @switchboard_entry.destroy
+ redirect_to switchboard_switchboard_entries_path(@switchboard), :notice => t('switchboard_entries.controller.successfuly_destroyed')
+ end
+
+ def sort
+ params[:switchboard_entry].reverse.each do |id|
+ @switchboard.switchboard_entries.find(id).move_to_top
+ end
+ render nothing: true
+ end
+
+ private
+ def switchboard_entry_params
+ params.require(:switchboard_entry).permit(:name, :sip_account_id)
+ end
+
+ def spread_breadcrumbs
+ add_breadcrumb t("users.index.page_title"), tenant_users_path(@switchboard.user.current_tenant)
+ add_breadcrumb @switchboard.user, tenant_user_path(@switchboard.user.current_tenant, @switchboard.user)
+ add_breadcrumb t("switchboards.index.page_title"), user_switchboards_path(@switchboard.user)
+ add_breadcrumb @switchboard, user_switchboard_path(@switchboard.user, @switchboard)
+ add_breadcrumb t("switchboard_entries.index.page_title"), switchboard_switchboard_entries_path(@switchboard)
+ if @switchboard_entry && !@switchboard_entry.new_record?
+ add_breadcrumb @switchboard_entry, switchboard_switchboard_entries_path(@switchboard, @switchboard_entry)
+ end
+ end
+end
diff --git a/app/controllers/switchboards_controller.rb b/app/controllers/switchboards_controller.rb
new file mode 100644
index 0000000..98008c1
--- /dev/null
+++ b/app/controllers/switchboards_controller.rb
@@ -0,0 +1,66 @@
+class SwitchboardsController < ApplicationController
+ load_and_authorize_resource :user
+ authorize_resource :switchboard, :through => :user
+
+ def index
+ @switchboards = @user.switchboards
+ spread_breadcrumbs
+ end
+
+ def show
+ @switchboard = @user.switchboards.find(params[:id])
+ @switchboard_entries = @switchboard.switchboard_entries
+ spread_breadcrumbs
+ end
+
+ def new
+ @switchboard = @user.switchboards.build
+ spread_breadcrumbs
+ end
+
+ def create
+ @switchboard = @user.switchboards.build(switchboard_params)
+ spread_breadcrumbs
+ if @switchboard.save
+ redirect_to user_switchboards_path(@user), :notice => t('switchboards.controller.successfuly_created')
+ else
+ render :new
+ end
+ end
+
+ def edit
+ @switchboard = @user.switchboards.find(params[:id])
+ spread_breadcrumbs
+ end
+
+ def update
+ @switchboard = @user.switchboards.find(params[:id])
+ spread_breadcrumbs
+ if @switchboard.update_attributes(switchboard_params)
+ redirect_to [@user, @switchboard], :notice => t('switchboards.controller.successfuly_updated')
+ else
+ render :edit
+ end
+ end
+
+ def destroy
+ @switchboard = @user.switchboards.find(params[:id])
+ @switchboard.destroy
+ spread_breadcrumbs
+ redirect_to user_switchboards_path(@user), :notice => t('switchboards.controller.successfuly_destroyed')
+ end
+
+ private
+ def switchboard_params
+ params.require(:switchboard).permit(:name)
+ end
+
+ def spread_breadcrumbs
+ add_breadcrumb t("users.index.page_title"), tenant_users_path(@user.current_tenant)
+ add_breadcrumb @user, tenant_user_path(@user.current_tenant, @user)
+ add_breadcrumb t("switchboards.index.page_title"), user_switchboards_path(@user)
+ if @switchboard && !@switchboard.new_record?
+ add_breadcrumb @switchboard, user_switchboard_path(@user, @switchboard)
+ end
+ end
+end
diff --git a/app/controllers/trigger_controller.rb b/app/controllers/trigger_controller.rb
index 5e836c4..6b58d6a 100644
--- a/app/controllers/trigger_controller.rb
+++ b/app/controllers/trigger_controller.rb
@@ -16,6 +16,11 @@ class TriggerController < ApplicationController
next
end
+ # Indicate a new voicemail in the navigation bar.
+ #
+ PrivatePub.publish_to("/users/#{user.id}/messages/new", "$('#new_voicemail_or_fax_indicator').hide('fast').show('slow');")
+ PrivatePub.publish_to("/users/#{user.id}/messages/new", "document.title = '* ' + document.title.replace( '* ' , '');")
+
if user.email.blank?
next
end
@@ -59,6 +64,64 @@ class TriggerController < ApplicationController
end
end
+ def fax_has_been_sent
+ fax_document = FaxDocument.find(params[:id])
+
+ if fax_document
+ # push the partial to the webbrowser
+ #
+ new_html = ActionController::Base.helpers.escape_javascript(render_to_string("fax_documents/_fax_document", :layout => false, :locals => {:fax_document => fax_document}))
+ PrivatePub.publish_to("/fax_documents/#{fax_document.id}", "$('#" + fax_document.id.to_s + ".fax_document').replaceWith('#{new_html}');")
+
+ render(
+ :status => 200,
+ :layout => false,
+ :content_type => 'text/plain',
+ :text => "<!-- OK -->",
+ )
+ else
+ render(
+ :status => 501,
+ :layout => false,
+ :content_type => 'text/plain',
+ :text => "<!-- ERRORS: #{errors.join(', ')} -->",
+ )
+ end
+ end
+
+ def sip_account_update
+ sip_account = SipAccount.find(params[:id])
+
+ if sip_account.updated_at < Time.now
+
+ # Push an update to sip_account.switchboard_entries
+ #
+ sip_account.switchboard_entries.each do |switchboard_entry|
+ escaped_switchboard_entry_partial = ActionController::Base.helpers.escape_javascript(render_to_string("switchboard_entries/_switchboard_entry", :layout => false, :locals => {:switchboard_entry => switchboard_entry}))
+ PrivatePub.publish_to("/switchboards/#{switchboard_entry.switchboard.id}", "$('#switchboard_entry_id_" + switchboard_entry.id.to_s + "').replaceWith('#{escaped_switchboard_entry_partial}');")
+ end
+
+ # Push an update to the needed switchboards
+ #
+ Switchboard.where(:user_id => sip_account.sip_accountable.id).each do |switchboard|
+ if sip_account.call_legs.where(:sip_account_id => switchboard.user.sip_account_ids).any? ||
+ sip_account.b_call_legs.where(:sip_account_id => switchboard.user.sip_account_ids).any?
+ escaped_switchboard_partial = ActionController::Base.helpers.escape_javascript(render_to_string("switchboards/_current_user_dashboard", :layout => false, :locals => {:current_user => switchboard.user}))
+ PrivatePub.publish_to("/switchboards/#{switchboard.id}", "$('.dashboard').replaceWith('#{escaped_switchboard_partial}');")
+ end
+ end
+
+ sip_account.touch
+ end
+
+ render(
+ :status => 200,
+ :layout => false,
+ :content_type => 'text/plain',
+ :text => "<!-- OK -->",
+ )
+ end
+
def fax
if !params[:fax_account_id].blank?
fax_account = FaxAccount.where(:id => params[:fax_account_id].to_i).first
@@ -87,6 +150,8 @@ class TriggerController < ApplicationController
if fax_document.save
Notifications.new_fax(fax_document).deliver
+ @last_fax_document = fax_document
+
begin
File.delete(pdf_file)
rescue => e
@@ -106,6 +171,14 @@ class TriggerController < ApplicationController
end
if errors.count == 0
+ # Indicate a new fax in the navigation bar.
+ #
+ if @last_fax_document.fax_account.fax_accountable.class == User
+ user = @last_fax_document.fax_account.fax_accountable
+ PrivatePub.publish_to("/users/#{user.id}/messages/new", "$('#new_voicemail_or_fax_indicator').hide('fast').show('slow');")
+ PrivatePub.publish_to("/users/#{user.id}/messages/new", "document.title = '* ' + document.title.replace( '* ' , '');")
+ end
+
render(
:status => 200,
:layout => false,