diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/application.js | 1 | ||||
-rw-r--r-- | app/assets/javascripts/phones.js.coffee | 5 | ||||
-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 | ||||
-rw-r--r-- | app/models/phone.rb | 31 | ||||
-rw-r--r-- | app/views/layouts/application.html.haml | 7 | ||||
-rw-r--r-- | app/views/phones/_form_core.html.haml | 10 | ||||
-rw-r--r-- | app/views/phones/new.html.haml | 6 | ||||
-rw-r--r-- | app/views/phones/show.html.haml | 11 |
10 files changed, 76 insertions, 45 deletions
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 2e0b0d8..1762043 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -10,4 +10,5 @@ //= require vendor/modernizr-2.0.6.min.js //= require vendor/jquery.condom.js //= require vendor/jquery.survival-kit +//= require phones //= require softkeys diff --git a/app/assets/javascripts/phones.js.coffee b/app/assets/javascripts/phones.js.coffee new file mode 100644 index 0000000..ff54777 --- /dev/null +++ b/app/assets/javascripts/phones.js.coffee @@ -0,0 +1,5 @@ +jQuery -> + $(".fallback_sip_account_dropdown").hide() + + $("#phone_hot_deskable").change -> + $(".fallback_sip_account_dropdown").show("slow") 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 diff --git a/app/models/phone.rb b/app/models/phone.rb index 89371eb..1f3c497 100644 --- a/app/models/phone.rb +++ b/app/models/phone.rb @@ -4,7 +4,7 @@ class Phone < ActiveRecord::Base attr_accessible :mac_address, :ip_address, :http_user, :http_password, :phone_model_id, :hot_deskable, :nightly_reboot, - :provisioning_key, :provisioning_key_active + :provisioning_key, :provisioning_key_active, :fallback_sip_account_id, :tenant # Associations # @@ -14,6 +14,9 @@ class Phone < ActiveRecord::Base has_many :phone_sip_accounts, :dependent => :destroy, :uniq => true, :order => :position has_many :sip_accounts, :through => :phone_sip_accounts + belongs_to :tenant + belongs_to :fallback_sip_account, :class_name => "SipAccount" + # Validations # before_validation :sanitize_mac_address @@ -29,6 +32,8 @@ class Phone < ActiveRecord::Base validates_presence_of :phone_model validates_presence_of :phoneable + + validates_uniqueness_of :fallback_sip_account_id, :allow_nil => true before_save :save_last_ip_address before_save :destroy_phones_sip_accounts_if_phoneable_changed @@ -138,6 +143,8 @@ class Phone < ActiveRecord::Base end end + PhoneSipAccount.where(:phone_id => self.id).destroy_all + self.phoneable = user sip_accounts.each do |sip_account| if ! self.sip_accounts.where(:id => sip_account.id).first @@ -163,37 +170,21 @@ class Phone < ActiveRecord::Base # OPTIMIZE i18n translations def user_logout - if ! self.hot_deskable or self.phoneable_type == 'Tenant' + if ! self.hot_deskable errors.add(:hot_deskable, "Phone not hot-deskable") return false end sip_account = self.sip_accounts.where(:sip_accountable_type => self.phoneable_type).first - tenant_sip_account = self.sip_accounts.where(:sip_accountable_type => 'Tenant').first - if tenant_sip_account - tenant = tenant_sip_account.sip_accountable - end - - sip_account_ids = Array.new() - self.sip_accounts.where(:sip_accountable_type => 'User', :hotdeskable => true).each do |sip_account| - sip_account_ids.push(sip_account.id) - end - - if tenant - self.phoneable = tenant - @not_destroy_phones_sip_accounts = true + if self.tenant + self.phoneable = self.tenant if ! self.save errors.add(:phoneable, "Could not change owner") return false end end - if ! PhoneSipAccount.destroy_all(:sip_account_id => sip_account_ids) - errors.add(:sip_accounts, "Could not delete sip_accounts") - return false - end - sleep(0.5) if ! self.resync(true, sip_account) diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index f2aff0a..2c7faec 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -20,7 +20,6 @@ %body #container = render :partial => "shared/header" - = render :partial => "shared/system_message" = render :partial => "shared/flash", :locals => { :flash => flash} #content{:role => 'main'} @@ -33,14 +32,16 @@ %footer#main %ul + %li + %a{:href => "http://amooma.de/gemeinschaft/gs5"} Gemeinschaft #{GEMEINSCHAFT_VERSION} - if GuiFunction.display?('amooma_commercial_support_link_in_footer', current_user) %li - %a{:href => "http://www.amooma.de"} Kommerzieller Support und Consulting + %a{:href => "http://amooma.de"} Kommerzieller Support und Consulting - if GuiFunction.display?('gemeinschaft_mailinglist_link_in_footer', current_user) %li %a{:href => "https://groups.google.com/group/gs5-users/"} Kostenlose Mailingliste .amooma-logo %span brought to you by - %a{ :target => '_blank', :href => "http://www.amooma.de/" } Amooma + %a{ :target => '_blank', :href => "http://amooma.de/" } Amooma diff --git a/app/views/phones/_form_core.html.haml b/app/views/phones/_form_core.html.haml index 51ceff5..fd69690 100644 --- a/app/views/phones/_form_core.html.haml +++ b/app/views/phones/_form_core.html.haml @@ -1,7 +1,11 @@ .inputs - = f.input :mac_address, :label => t('phones.form.mac_address.label'), :hint => conditional_hint('phones.form.mac_address.hint') - = f.association :phone_model, :label => t('phones.form.phone_model_id.label'), :hint => conditional_hint('phones.form.phone_model_id.hint') - = f.input :hot_deskable, :label => t('phones.form.hot_deskable.label'), :hint => conditional_hint('phones.form.hot_deskable.hint') + = f.input :mac_address, :label => t('phones.form.mac_address.label'), :hint => conditional_hint('phones.form.mac_address.hint'), :autofocus => true + = f.association :phone_model, :label => t('phones.form.phone_model_id.label'), :hint => conditional_hint('phones.form.phone_model_id.hint'), :include_blank => false + - if @fallback_sip_accounts.any? + = 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 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') - if defined? PROVISIONING_KEY_LENGTH && PROVISIONING_KEY_LENGTH > 0 diff --git a/app/views/phones/new.html.haml b/app/views/phones/new.html.haml index 61923cc..ae0a539 100644 --- a/app/views/phones/new.html.haml +++ b/app/views/phones/new.html.haml @@ -1,3 +1,9 @@ - title t("phones.new.page_title") +- if !@fallback_sip_accounts.any? && can?(:create, current_user.current_tenant.sip_accounts.build) + %p + = t("phones.new.you_need_to_have_at_least_one_available_fallback_sip_account_for_hotdesking") + = link_to t("sip_accounts.index.actions.create_for", :resource => current_user.current_tenant), new_tenant_sip_account_path(current_user.current_tenant) + = render "form" + diff --git a/app/views/phones/show.html.haml b/app/views/phones/show.html.haml index 2664ffa..090323e 100644 --- a/app/views/phones/show.html.haml +++ b/app/views/phones/show.html.haml @@ -6,9 +6,14 @@ %p %strong= t('phones.show.phone_model_id') + ":" = @phone.phone_model -%p - %strong= t('phones.show.hot_deskable') + ":" - = @phone.hot_deskable +- if @phone.hot_deskable == true + %p + %strong= t('phones.show.hot_deskable') + ":" + = @phone.hot_deskable + %p + %strong= t('phones.show.fallback_sip_account_id') + ":" + = @phone.fallback_sip_account + - if defined? NIGHTLY_REBOOT_OF_PHONES && NIGHTLY_REBOOT_OF_PHONES == true %p %strong= t('phones.show.nightly_reboot') + ":" |