From cea2cc3c1cc1e48fc4600c698d52dfda2bde4505 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Wed, 3 Apr 2013 22:08:19 +0200 Subject: Massive changes to the switchboard. --- app/models/switchboard.rb | 3 ++- app/models/switchboard_entry.rb | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/switchboard.rb b/app/models/switchboard.rb index 360de70..53f69a4 100644 --- a/app/models/switchboard.rb +++ b/app/models/switchboard.rb @@ -8,7 +8,7 @@ class Switchboard < ActiveRecord::Base validates :reload_interval, :numericality => { :only_integer => true, - :greater_than => 250, + :greater_than => 249, :allow_nil => true } @@ -21,6 +21,7 @@ class Switchboard < ActiveRecord::Base belongs_to :user, :touch => true has_many :switchboard_entries, :dependent => :destroy has_many :sip_accounts, :through => :switchboard_entries + has_many :phone_numbers, :through => :sip_accounts before_validation :convert_0_to_nil diff --git a/app/models/switchboard_entry.rb b/app/models/switchboard_entry.rb index faeba8c..44de7fd 100644 --- a/app/models/switchboard_entry.rb +++ b/app/models/switchboard_entry.rb @@ -30,4 +30,37 @@ class SwitchboardEntry < ActiveRecord::Base self.name.to_s end end + + def avatar_src + if self.sip_account.sip_accountable.class == User + if self.sip_account.sip_accountable.image? + self.sip_account.sip_accountable.image_url(:profile) + else + if self.sip_account.sip_accountable.male? + '/assets/icons/user-male-16x.png' + else + '/assets/icons/user-female-16x.png' + end + end + else + nil + end + end + + def callstate + if self.sip_account.call_legs.where(callstate: 'ACTIVE').any? || self.sip_account.b_call_legs.where(b_callstate: 'ACTIVE').any? + 'ACTIVE' + else + if self.sip_account.call_legs.where(callstate: 'EARLY').any? + 'EARLY' + else + if self.sip_account.call_legs.where(callstate: 'RINGING').any? + 'RINGING' + else + nil + end + end + end + end + end -- cgit v1.2.3