summaryrefslogtreecommitdiff
path: root/app/models/switchboard_entry.rb
blob: d1e9a0cc886b892734265d2bc351ed0e53bb0bc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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