diff options
Diffstat (limited to 'app/controllers/phones_controller.rb')
-rw-r--r-- | app/controllers/phones_controller.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/app/controllers/phones_controller.rb b/app/controllers/phones_controller.rb index d46bf86..f1dcd3e 100644 --- a/app/controllers/phones_controller.rb +++ b/app/controllers/phones_controller.rb @@ -13,6 +13,8 @@ class PhonesController < ApplicationController end def new + set_fallback_sip_accounts + @phone = @phoneable.phones.build() # Use the last phone.phone_model as the default. @@ -22,15 +24,21 @@ class PhonesController < ApplicationController def create @phone = @phoneable.phones.build(params[:phone]) + if !@tenant + @tenant = @user.current_tenant + end + @phone.tenant = @tenant if @phone.save m = method( :"#{@phoneable.class.name.underscore}_phone_path" ) redirect_to m.( @phoneable, @phone ), :notice => t('phones.controller.successfuly_created') else + set_fallback_sip_accounts render :new end end def edit + set_fallback_sip_accounts end def update @@ -68,5 +76,10 @@ class PhonesController < ApplicationController add_breadcrumb @phone, method( :"#{@phone.phoneable.class.name.underscore}_phone_path" ).(@phone.phoneable, @phone) end end + + def set_fallback_sip_accounts + used_sip_account_ids = Phone.where(:fallback_sip_account_id => SipAccount.pluck(:id)).pluck(:fallback_sip_account_id) + @fallback_sip_accounts = SipAccount.where(:sip_accountable_type => 'Tenant').where(:hotdeskable => true) - SipAccount.where(:id => used_sip_account_ids) + end end |