From 6374c0b3e38dfc74eb1b4a5a1fcc5229eacdcaf2 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Fri, 8 Mar 2013 12:09:17 +0100 Subject: Added SwitchboardEntry scaffold. switchboard has_many switchboard_entries --- app/models/sip_account.rb | 2 ++ app/models/switchboard.rb | 2 ++ app/models/switchboard_entry.rb | 30 ++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 app/models/switchboard_entry.rb (limited to 'app/models') diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index cdb609d..74a2562 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -41,6 +41,8 @@ class SipAccount < ActiveRecord::Base has_many :call_legs, :class_name => 'Call' has_many :b_call_legs, :class_name => 'Call', :foreign_key => 'b_sip_account_id' + has_many :switchboard_entries, :dependent => :destroy + # Delegations: # delegate :host, :to => :sip_domain, :allow_nil => true diff --git a/app/models/switchboard.rb b/app/models/switchboard.rb index cb0c70f..74e2767 100644 --- a/app/models/switchboard.rb +++ b/app/models/switchboard.rb @@ -7,6 +7,8 @@ class Switchboard < ActiveRecord::Base :uniqueness => {:scope => :user_id} belongs_to :user, :touch => true + has_many :switchboard_entries, :dependent => :destroy + has_many :sip_accounts, :through => :switchboard_entries def to_s self.name.to_s diff --git a/app/models/switchboard_entry.rb b/app/models/switchboard_entry.rb new file mode 100644 index 0000000..d1e9a0c --- /dev/null +++ b/app/models/switchboard_entry.rb @@ -0,0 +1,30 @@ +class SwitchboardEntry < ActiveRecord::Base + # https://github.com/rails/strong_parameters + include ActiveModel::ForbiddenAttributesProtection + + belongs_to :switchboard, :touch => true + belongs_to :sip_account, :touch => true + + validates :switchboard, + :presence => true + + validates :sip_account, + :presence => true + + validates :name, + :uniqueness => {:scope => :switchboard_id}, + :allow_blank => true, + :allow_nil => true + + acts_as_list :scope => [ :switchboard_id ] + + default_scope order(:position) + + def to_s + if self.name.blank? && !self.sip_account.to_s.blank? + self.sip_account.to_s + else + self.name.to_s + end + end +end -- cgit v1.2.3