From db9dbf03d88cfbd68ce99a242730b9e870339539 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Thu, 7 Mar 2013 13:15:35 +0100 Subject: Added Switchboard scaffold. --- app/models/call_route.rb | 2 +- app/models/switchboard.rb | 14 ++++++++++++++ app/models/user.rb | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 app/models/switchboard.rb (limited to 'app/models') diff --git a/app/models/call_route.rb b/app/models/call_route.rb index 8bc811a..6c54549 100644 --- a/app/models/call_route.rb +++ b/app/models/call_route.rb @@ -7,7 +7,7 @@ class CallRoute < ActiveRecord::Base has_many :route_elements, :dependent => :destroy, :order => :position validates :name, - :presence => true + :presence => true validates :routing_table, :presence => true, diff --git a/app/models/switchboard.rb b/app/models/switchboard.rb new file mode 100644 index 0000000..cb0c70f --- /dev/null +++ b/app/models/switchboard.rb @@ -0,0 +1,14 @@ +class Switchboard < ActiveRecord::Base + # https://github.com/rails/strong_parameters + include ActiveModel::ForbiddenAttributesProtection + + validates :name, + :presence => true, + :uniqueness => {:scope => :user_id} + + belongs_to :user, :touch => true + + def to_s + self.name.to_s + end +end diff --git a/app/models/user.rb b/app/models/user.rb index 913d75f..6091e32 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -94,6 +94,8 @@ class User < ActiveRecord::Base has_many :group_memberships, :as => :item, :dependent => :destroy, :uniq => true has_many :groups, :through => :group_memberships + has_many :switchboards, :dependent => :destroy + # Avatar like photo mount_uploader :image, ImageUploader -- cgit v1.2.3 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 From 21d0843117c0962bd962fc50fccaf276a5b3067f Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Sun, 10 Mar 2013 08:43:23 +0100 Subject: Misc --- app/models/switchboard_entry.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'app/models') diff --git a/app/models/switchboard_entry.rb b/app/models/switchboard_entry.rb index d1e9a0c..76d002f 100644 --- a/app/models/switchboard_entry.rb +++ b/app/models/switchboard_entry.rb @@ -12,6 +12,7 @@ class SwitchboardEntry < ActiveRecord::Base :presence => true validates :name, + :length => { :maximum => 10 }, :uniqueness => {:scope => :switchboard_id}, :allow_blank => true, :allow_nil => true -- cgit v1.2.3