From 55a0d5ce38f99226174f358279c02178eacd75d7 Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 23 Dec 2012 16:04:05 +0100 Subject: login/logout methods --- app/controllers/phones_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'app/controllers/phones_controller.rb') diff --git a/app/controllers/phones_controller.rb b/app/controllers/phones_controller.rb index d46bf86..0b765e8 100644 --- a/app/controllers/phones_controller.rb +++ b/app/controllers/phones_controller.rb @@ -14,7 +14,6 @@ class PhonesController < ApplicationController def new @phone = @phoneable.phones.build() - # Use the last phone.phone_model as the default. # @phone.phone_model_id = Phone.last.try(:phone_model).try(:id) @@ -22,6 +21,10 @@ 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') -- cgit v1.2.3 From b76b13bff13cd6bcb2d543386cae9868cd4d882f Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 27 Dec 2012 14:09:53 +0100 Subject: Fallback sip account in phone views --- app/controllers/phones_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'app/controllers/phones_controller.rb') diff --git a/app/controllers/phones_controller.rb b/app/controllers/phones_controller.rb index 0b765e8..b865cb1 100644 --- a/app/controllers/phones_controller.rb +++ b/app/controllers/phones_controller.rb @@ -13,6 +13,8 @@ class PhonesController < ApplicationController end def new + used_sip_account_ids = Phone.where('fallback_sip_account_id IS NOT NULL').collect {|r| r.fallback_sip_account } + @fallback_sip_accounts = SipAccount.where('sip_accountable_type = "Tenant" AND id NOT IN (?)', used_sip_account_ids).all @phone = @phoneable.phones.build() # Use the last phone.phone_model as the default. # @@ -34,6 +36,8 @@ class PhonesController < ApplicationController end def edit + used_sip_account_ids = Phone.where('fallback_sip_account_id IS NOT NULL AND id != ?', @phone.id).collect {|r| r.fallback_sip_account_id } + @fallback_sip_accounts = SipAccount.where('sip_accountable_type = "Tenant" AND id NOT IN (?)', used_sip_account_ids).all end def update -- cgit v1.2.3 From 3b07751150c0cd70eee4e750dd7a3670120a8675 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Fri, 28 Dec 2012 19:31:31 +0100 Subject: Fallback SIP Accounts are only shown when the hotdeskable field is checked. --- app/controllers/phones_controller.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'app/controllers/phones_controller.rb') diff --git a/app/controllers/phones_controller.rb b/app/controllers/phones_controller.rb index b865cb1..b23a589 100644 --- a/app/controllers/phones_controller.rb +++ b/app/controllers/phones_controller.rb @@ -13,9 +13,11 @@ class PhonesController < ApplicationController end def new - used_sip_account_ids = Phone.where('fallback_sip_account_id IS NOT NULL').collect {|r| r.fallback_sip_account } - @fallback_sip_accounts = SipAccount.where('sip_accountable_type = "Tenant" AND id NOT IN (?)', used_sip_account_ids).all + 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) + @phone = @phoneable.phones.build() + # Use the last phone.phone_model as the default. # @phone.phone_model_id = Phone.last.try(:phone_model).try(:id) -- cgit v1.2.3 From 2cfe480a334019619d243823c030b9315cb3ea2a Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Fri, 28 Dec 2012 20:10:36 +0100 Subject: Refactored the controller. --- app/controllers/phones_controller.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'app/controllers/phones_controller.rb') diff --git a/app/controllers/phones_controller.rb b/app/controllers/phones_controller.rb index b23a589..f1dcd3e 100644 --- a/app/controllers/phones_controller.rb +++ b/app/controllers/phones_controller.rb @@ -13,8 +13,7 @@ class PhonesController < ApplicationController end def new - 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) + set_fallback_sip_accounts @phone = @phoneable.phones.build() @@ -33,13 +32,13 @@ class PhonesController < ApplicationController 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 - used_sip_account_ids = Phone.where('fallback_sip_account_id IS NOT NULL AND id != ?', @phone.id).collect {|r| r.fallback_sip_account_id } - @fallback_sip_accounts = SipAccount.where('sip_accountable_type = "Tenant" AND id NOT IN (?)', used_sip_account_ids).all + set_fallback_sip_accounts end def update @@ -77,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 -- cgit v1.2.3