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 ++++++++---- config/locales/views/phones/de.yml | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) 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 diff --git a/config/locales/views/phones/de.yml b/config/locales/views/phones/de.yml index e8221a9..dafe279 100644 --- a/config/locales/views/phones/de.yml +++ b/config/locales/views/phones/de.yml @@ -42,7 +42,7 @@ de: new: page_title: 'Neues Telefon' actions: - you_need_to_have_at_least_one_available_fallback_sip_account_for_hotdesking: 'Sie benötigen mindestens einen nicht benutzen SIP-Account, damit die Option für Hotdesking in diesem Formular angezeigt wird. ' + you_need_to_have_at_least_one_available_fallback_sip_account_for_hotdesking: 'Sie benötigen mindestens einen nicht benutzen und hotdeskfähigen SIP-Account, damit die Option für Hotdesking in diesem Formular angezeigt wird. ' edit: page_title: 'Telefondaten bearbeiten' form: -- cgit v1.2.3