From 64653a9149eca977c16233abb0a472730b94a464 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 26 Mar 2013 16:55:08 +0100 Subject: Store reload interval in the Switchboard table. --- app/models/switchboard.rb | 21 +++++++++++++++++++++ app/models/switchboard_entry.rb | 2 ++ 2 files changed, 23 insertions(+) (limited to 'app/models') diff --git a/app/models/switchboard.rb b/app/models/switchboard.rb index 74e2767..360de70 100644 --- a/app/models/switchboard.rb +++ b/app/models/switchboard.rb @@ -6,11 +6,32 @@ class Switchboard < ActiveRecord::Base :presence => true, :uniqueness => {:scope => :user_id} + validates :reload_interval, + :numericality => { :only_integer => true, + :greater_than => 250, + :allow_nil => true + } + + validates :entry_width, + :numericality => { :only_integer => true, + :greater_than => 0, + :less_than => 5 + } + belongs_to :user, :touch => true has_many :switchboard_entries, :dependent => :destroy has_many :sip_accounts, :through => :switchboard_entries + before_validation :convert_0_to_nil + def to_s self.name.to_s end + + private + def convert_0_to_nil + if self.reload_interval == 0 + self.reload_interval = nil + end + end end diff --git a/app/models/switchboard_entry.rb b/app/models/switchboard_entry.rb index 76d002f..faeba8c 100644 --- a/app/models/switchboard_entry.rb +++ b/app/models/switchboard_entry.rb @@ -5,6 +5,8 @@ class SwitchboardEntry < ActiveRecord::Base belongs_to :switchboard, :touch => true belongs_to :sip_account, :touch => true + has_many :phone_numbers, :through => :sip_account + validates :switchboard, :presence => true -- cgit v1.2.3