summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/softkeys_controller.rb3
-rw-r--r--app/models/sip_account.rb10
-rw-r--r--app/models/softkey.rb22
-rw-r--r--app/views/softkeys/_form_core.html.haml3
4 files changed, 27 insertions, 11 deletions
diff --git a/app/controllers/softkeys_controller.rb b/app/controllers/softkeys_controller.rb
index 9179d8c..6727de1 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
@@ -35,6 +35,7 @@ class SoftkeysController < ApplicationController
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
diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb
index cdb609d..1ff3c9a 100644
--- a/app/models/sip_account.rb
+++ b/app/models/sip_account.rb
@@ -160,12 +160,16 @@ class SipAccount < ActiveRecord::Base
);
end
-
- def target_sip_accounts_by_permission(permission)
+ def target_group_ids_by_permission(permission)
target_groups = Group.union(self.groups.collect{|g| g.permission_targets(permission)})
target_groups = target_groups + Group.union(self.sip_accountable.groups.collect{|g| g.permission_targets(permission)})
+
+ return target_groups
+ end
+
+ def target_sip_accounts_by_permission(permission)
sip_accounts = []
- GroupMembership.where(:group_id => target_groups).each do |group_membership|
+ GroupMembership.where(:group_id => target_group_ids_by_permission(permission)).each do |group_membership|
if group_membership.item.class == User || group_membership.item.class == Tenant
sip_accounts = sip_accounts + group_membership.item.sip_accounts
elsif group_membership.item.class == SipAccount
diff --git a/app/models/softkey.rb b/app/models/softkey.rb
index 6063017..7f77a25 100644
--- a/app/models/softkey.rb
+++ b/app/models/softkey.rb
@@ -1,17 +1,17 @@
class Softkey < ActiveRecord::Base
- attr_accessible :softkey_function_id, :number, :label, :uuid, :softkeyable_type, :softkeyable_id
+ attr_accessible :softkey_function_id, :number, :label, :uuid, :softkeyable_type, :softkeyable_id, :call_forward, :blf
belongs_to :sip_account
belongs_to :softkey_function
belongs_to :softkeyable, :polymorphic => true
- 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.
#
validates_presence_of :number, :if => Proc.new{ |softkey| self.softkey_function_id != nil &&
- ['blf','speed_dial','dtmf','conference'].include?(softkey.softkey_function.name) }
+ ['blf', 'speed_dial','dtmf','conference'].include?(softkey.softkey_function.name) }
+
+ validates_presence_of :softkeyable_id, :if => Proc.new{ |softkey| self.softkey_function_id != nil &&
+ ['call_forwarding'].include?(softkey.softkey_function.name) }
validates_presence_of :uuid
validates_uniqueness_of :uuid
@@ -43,7 +43,16 @@ class Softkey < ActiveRecord::Base
end
def possible_blf_sip_accounts
- self.sip_account.target_sip_accounts_by_permission('presence')
+ self.sip_account.target_sip_accounts_by_permission(:presence)
+ end
+
+ def possible_pickup_groups
+ Group.where(:id => self.sip_account.target_group_ids_by_permission(:presence))
+ end
+
+ def possible_blf
+ blf = possible_pickup_groups.collect{ |g| ["#{g.class.name}: #{g.to_s}", "#{g.id}:#{g.class.name}"] }
+ blf + possible_blf_sip_accounts.collect{ |g| ["#{g.class.name}: #{g.to_s}", "#{g.id}:#{g.class.name}"] }
end
def to_s
@@ -73,6 +82,7 @@ class Softkey < ActiveRecord::Base
return self.position.to_i < Softkey.where(:sip_account_id => self.sip_account_id ).order(:position).last.position.to_i
end
+
private
# 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.
diff --git a/app/views/softkeys/_form_core.html.haml b/app/views/softkeys/_form_core.html.haml
index f447aa6..0e251f3 100644
--- a/app/views/softkeys/_form_core.html.haml
+++ b/app/views/softkeys/_form_core.html.haml
@@ -4,10 +4,11 @@
hold_function_name = "#{I18n.t('softkeys.functions.hold')}"
deactivated_function_name = "#{I18n.t('softkeys.functions.deactivated')}"
+
.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
- call_forwards = @softkey.possible_call_forwards
- if call_forwards && call_forwards.count > 0
- = f.association :softkeyable, :collection => call_forwards, :label => t('softkeys.form.call_forward.label'), :hint => conditional_hint('softkeys.form.call_forward.hint'), :include_blank => false
+ = f.input :softkeyable_id, :collection => 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')