summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-03-26 16:55:08 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-04-03 22:09:33 +0200
commit64653a9149eca977c16233abb0a472730b94a464 (patch)
tree7cfd94c7a7cd44374cf88c61f0f7bd926c351615 /app/models
parent877364c24ef9c7954f0e193456bb3f2d39169977 (diff)
Store reload interval in the Switchboard table.
Diffstat (limited to 'app/models')
-rw-r--r--app/models/switchboard.rb21
-rw-r--r--app/models/switchboard_entry.rb2
2 files changed, 23 insertions, 0 deletions
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