From 544ea50a66da81989d0320735724bd09786be8ea Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Sun, 30 Dec 2012 11:23:09 +0100 Subject: Fixed some logic bugs. --- Gemfile.lock | 2 +- app/assets/javascripts/phones.js.coffee | 2 -- app/controllers/phones_controller.rb | 7 +++++-- app/views/phones/_form_core.html.haml | 3 +++ 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index e07b89e..f9a6596 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -84,7 +84,7 @@ GEM faye-websocket (0.4.1) eventmachine (>= 0.12.0) fssm (0.2.8.1) - haml (3.1.4) + haml (3.1.7) hike (1.2.1) hirb (0.6.1) http_accept_language (1.0.2) diff --git a/app/assets/javascripts/phones.js.coffee b/app/assets/javascripts/phones.js.coffee index ff54777..d917d09 100644 --- a/app/assets/javascripts/phones.js.coffee +++ b/app/assets/javascripts/phones.js.coffee @@ -1,5 +1,3 @@ jQuery -> - $(".fallback_sip_account_dropdown").hide() - $("#phone_hot_deskable").change -> $(".fallback_sip_account_dropdown").show("slow") diff --git a/app/controllers/phones_controller.rb b/app/controllers/phones_controller.rb index f1dcd3e..2698465 100644 --- a/app/controllers/phones_controller.rb +++ b/app/controllers/phones_controller.rb @@ -13,9 +13,9 @@ class PhonesController < ApplicationController end def new - set_fallback_sip_accounts - @phone = @phoneable.phones.build() + + set_fallback_sip_accounts # Use the last phone.phone_model as the default. # @@ -80,6 +80,9 @@ class PhonesController < ApplicationController 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) + if @phone && !@phone.fallback_sip_account_id.blank? && SipAccount.exists?(@phone.fallback_sip_account_id) + @fallback_sip_accounts << SipAccount.where(:id => @phone.fallback_sip_account_id).first + end end end diff --git a/app/views/phones/_form_core.html.haml b/app/views/phones/_form_core.html.haml index fd69690..e0c664b 100644 --- a/app/views/phones/_form_core.html.haml +++ b/app/views/phones/_form_core.html.haml @@ -5,6 +5,9 @@ = f.input :hot_deskable, :label => t('phones.form.hot_deskable.label'), :hint => conditional_hint('phones.form.hot_deskable.hint') .fallback_sip_account_dropdown = f.association :fallback_sip_account, :collection => @fallback_sip_accounts, :label => t('phones.form.fallback_sip_account_id.label'), :hint => conditional_hint('phones.form.fallback_sip_account_id.hint'), :include_blank => false + - if !@phone.hot_deskable? + :javascript + $(".fallback_sip_account_dropdown").hide() - if defined? NIGHTLY_REBOOT_OF_PHONES && NIGHTLY_REBOOT_OF_PHONES == true = f.input :nightly_reboot, :label => t('phones.form.nightly_reboot.label'), :hint => conditional_hint('phones.form.nightly_reboot.hint') -- cgit v1.2.3