diff options
author | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2012-12-28 20:27:04 +0100 |
---|---|---|
committer | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2012-12-28 20:27:04 +0100 |
commit | f3c3e77eaa2b82567f02601b6f66177208674181 (patch) | |
tree | 1946390f7f697e80fcdab4164ad620d507b6a1fe /app/controllers | |
parent | 3e76142566ad8f55a64a88fe5c19e7d0ec7c11c0 (diff) | |
parent | 8d20201910b1915cffa495e6474d50f9c8e8331d (diff) |
Merge branch 'develop'5.0.1
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/config_siemens_controller.rb | 18 | ||||
-rw-r--r-- | app/controllers/config_snom_controller.rb | 19 | ||||
-rw-r--r-- | app/controllers/phones_controller.rb | 13 |
3 files changed, 34 insertions, 16 deletions
diff --git a/app/controllers/config_siemens_controller.rb b/app/controllers/config_siemens_controller.rb index f398b1a..c09dfcf 100644 --- a/app/controllers/config_siemens_controller.rb +++ b/app/controllers/config_siemens_controller.rb @@ -80,6 +80,7 @@ class ConfigSiemensController < ApplicationController @phone.mac_address = mac_address @phone.hot_deskable = true @phone.phone_model = PhoneModel.where('name LIKE ?', "#{phone_type}").first + @phone.tenant = tenant if ! @phone.save render( :status => 500, @@ -128,16 +129,13 @@ class ConfigSiemensController < ApplicationController return end - phone_sip_account = PhoneSipAccount.new() - phone_sip_account.phone_id = @phone.id - phone_sip_account.sip_account_id = @sip_account.id - - if ! phone_sip_account.save + @phone.fallback_sip_account = @sip_account + if ! @phone.save render( :status => 500, :layout => false, :content_type => 'text/plain', - :text => "<!-- #{phone_sip_account.errors.messages.inspect} -->", + :text => "<!-- #{@phone.errors.messages.inspect} -->", ) return end @@ -152,13 +150,17 @@ class ConfigSiemensController < ApplicationController @sip_account = @phone.sip_accounts.where(:sip_accountable_type => @phone.phoneable_type, :sip_accountable_id => @phone.phoneable_id).first + if !@sip_account + @sip_account = @phone.fallback_sip_account + end + + tenant = @phone.tenant + if @phone.phoneable if @phone.phoneable_type == 'Tenant' - tenant = @phone.phoneable language = tenant.language.code elsif @phone.phoneable_type == 'User' language = @phone.phoneable.language.code - tenant = @phone.phoneable.current_tenant end end diff --git a/app/controllers/config_snom_controller.rb b/app/controllers/config_snom_controller.rb index 74a117d..4d12082 100644 --- a/app/controllers/config_snom_controller.rb +++ b/app/controllers/config_snom_controller.rb @@ -49,6 +49,7 @@ class ConfigSnomController < ApplicationController @phone = tenant.phones.build @phone.mac_address = @mac_address @phone.hot_deskable = true + @phone.tenant = tenant mac_address_to_model = { '00041325' => 'Snom 300', @@ -130,20 +131,16 @@ class ConfigSnomController < ApplicationController return end - phone_sip_account = PhoneSipAccount.new() - phone_sip_account.phone_id = @phone.id - phone_sip_account.sip_account_id = @sip_account.id - - if ! phone_sip_account.save + @phone.fallback_sip_account = @sip_account + if ! @phone.save render( :status => 500, :layout => false, :content_type => 'text/plain', - :text => "<!-- #{phone_sip_account.errors.messages.inspect} -->", + :text => "<!-- #{@phone.errors.messages.inspect} -->", ) return end - end elsif ! params[:phone].blank? then @phone = Phone.where({ :id => params[:phone].to_i }).first @@ -238,9 +235,15 @@ class ConfigSnomController < ApplicationController @softkeys = Array.new() @sip_accounts = Array.new() + phone_sip_accounts = Array.new() if send_sensitve - @phone.sip_accounts.each do |sip_account| + if @phone.sip_accounts && @phone.sip_accounts.count > 0 + phone_sip_accounts = @phone.sip_accounts + elsif @phone.fallback_sip_account + phone_sip_accounts.push( @phone.fallback_sip_account ) + end + phone_sip_accounts.each do |sip_account| if (sip_account.sip_accountable_type == @phone.phoneable_type) and (sip_account.sip_accountable_id == @phone.phoneable_id) snom_sip_account = { :id => sip_account.id, 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 |