From 2f2276dc424196ace5d1859dfa3d3999926effce Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 5 Mar 2013 01:45:31 -0500 Subject: bypassing softkeys controller --- app/controllers/softkeys_controller.rb | 8 ++----- app/models/softkey.rb | 37 ++++++++++++++------------------- app/views/softkeys/_form_core.html.haml | 4 ++-- 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/app/controllers/softkeys_controller.rb b/app/controllers/softkeys_controller.rb index c9e8c20..9179d8c 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_call_forwards_and_softkey_functions, :only => [ :new, :edit, :update ] + before_filter :set_available_softkey_functions, :only => [ :new, :edit, :update ] before_filter :spread_breadcrumbs, :except => [:sort] def index @@ -54,12 +54,8 @@ class SoftkeysController < ApplicationController render nothing: true end - private - - def set_available_call_forwards_and_softkey_functions - @available_call_forwards = @softkey.possible_blf_call_forwards - + def set_available_softkey_functions @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) diff --git a/app/models/softkey.rb b/app/models/softkey.rb index 8049456..470605c 100644 --- a/app/models/softkey.rb +++ b/app/models/softkey.rb @@ -22,29 +22,24 @@ class Softkey < ActiveRecord::Base after_save :resync_phone after_destroy :resync_phone - def possible_blf_call_forwards - if self.sip_account.phone_numbers.count == 0 - nil - else - if self.sip_account.callforward_rules_act_per_sip_account == true - # We pick one phone_number and display the rules of it. - # - phone_number = self.sip_account.phone_numbers.order(:number).first - call_forwards = self.sip_account.call_forwards.where(:call_forwardable_id => phone_number.id, :call_forwardable_type => 'PhoneNumber') - else - call_forwards = self.sip_account.call_forwards - end - - phone_numbers_ids = self.sip_account.phone_number_ids - phone_numbers = PhoneNumber.where(:id => phone_numbers_ids).pluck(:number) + def possible_call_forwards + call_forwards = self.sip_account.call_forwards + self.sip_account.phone_numbers.each do |phone_number| + call_forwards = call_forwards + phone_number.call_forwards + end - hunt_group_ids = PhoneNumber.where(:phone_numberable_type => 'HuntGroupMember', :number => phone_numbers). - map{ |phone_number| phone_number.phone_numberable.hunt_group.id }. - uniq - call_forwards + CallForward.where(:destinationable_type => 'HuntGroup', :destinationable_id => hunt_group_ids, :call_forwardable_type => 'PhoneNumber'). - where('call_forwardable_id NOT IN (?)', phone_numbers_ids) - end + phone_numbers_ids = self.sip_account.phone_number_ids + phone_numbers = PhoneNumber.where(:id => phone_numbers_ids).pluck(:number) + + hunt_group_ids = PhoneNumber.where(:phone_numberable_type => 'HuntGroupMember', :number => phone_numbers). + map{ |phone_number| phone_number.phone_numberable.hunt_group.id }. + uniq + + call_forwards = call_forwards + CallForward.where(:destinationable_type => 'HuntGroup', :destinationable_id => hunt_group_ids, :call_forwardable_type => 'PhoneNumber'). + where('call_forwardable_id NOT IN (?)', phone_numbers_ids) + + return call_forwards end def to_s diff --git a/app/views/softkeys/_form_core.html.haml b/app/views/softkeys/_form_core.html.haml index 2863d5c..7c1dd4a 100644 --- a/app/views/softkeys/_form_core.html.haml +++ b/app/views/softkeys/_form_core.html.haml @@ -6,7 +6,7 @@ .inputs = f.input :softkey_function_id, :as => :select, :collection => @softkey_functions.map {|x| [I18n.t("softkeys.functions.#{x}"), x.id] }, :label => t('softkeys.form.function.label'), :hint => conditional_hint('softkeys.form.function.hint'), :include_blank => false - - if @available_call_forwards && @available_call_forwards.count > 0 - = f.association :softkeyable, :collection => @available_call_forwards, :label => t('softkeys.form.call_forward.label'), :hint => conditional_hint('softkeys.form.call_forward.hint'), :include_blank => false + - if @softkey.possible_call_forwards && @softkey.possible_call_forwards.count > 0 + = f.association :softkeyable, :collection => @softkey.possible_call_forwards, :label => t('softkeys.form.call_forward.label'), :hint => conditional_hint('softkeys.form.call_forward.hint'), :include_blank => false = f.input :number, :label => t('softkeys.form.number.label'), :hint => conditional_hint('softkeys.form.number.hint') = f.input :label, :label => t('softkeys.form.label.label'), :hint => conditional_hint('softkeys.form.label.hint') -- cgit v1.2.3