summaryrefslogtreecommitdiff
path: root/app/models/automatic_call_distributor.rb
blob: a34392e1dbe0bce13c6c4df94bebd66cae92c94d (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
31
class AutomaticCallDistributor < ActiveRecord::Base
  attr_accessible :uuid, :name, :strategy, :automatic_call_distributorable_type, :automatic_call_distributorable_id, :max_callers, :agent_timeout, :retry_timeout, :join, :leave, :gs_node_id, :announce_position, :announce_call_agents, :greeting, :goodbye, :music

  belongs_to :automatic_call_distributorable, :polymorphic => true, :touch => true

  has_many :acd_agents, :dependent => :destroy
  has_many :phone_numbers, :as => :phone_numberable, :dependent => :destroy
  accepts_nested_attributes_for :phone_numbers, 
                                :reject_if => lambda { |phone_number| phone_number[:number].blank? }, 
                                :allow_destroy => true

  validates_presence_of :strategy

  STRATEGIES  = ['ring_all', 'round_robin']
  JOIN_ON = ['agents_available', 'agents_active', 'always']
  LEAVE_ON = ['no_agents_available_timeout', 'no_agents_active_timeout', 'no_agents_available', 'no_agents_active', 'timeout', 'never']

  after_initialize :set_defaults

  def to_s
    self.name
  end

  private
  def set_defaults 
    self.announce_call_agents ||= 'ivr/ivr-stay_on_line_call_answered_momentarily.wav'
    self.greeting ||= 'ivr/ivr-thank_you_for_calling.wav'
    self.goodbye ||= 'ivr/ivr-thank_you_for_calling.wav'
    self.music ||= 'local_stream://mohl'
  end
end