From 2964ebf277568536ac215f3a651e1841a73d68f8 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 7 Mar 2013 03:11:28 -0500 Subject: call origination fixed --- app/controllers/calls_controller.rb | 7 ++-- app/models/call.rb | 76 +++++++++---------------------------- 2 files changed, 21 insertions(+), 62 deletions(-) diff --git a/app/controllers/calls_controller.rb b/app/controllers/calls_controller.rb index 22ff92d..9d85a10 100644 --- a/app/controllers/calls_controller.rb +++ b/app/controllers/calls_controller.rb @@ -18,11 +18,11 @@ class CallsController < ApplicationController protocol, separator, phone_number = params[:url].partition(':') if ! phone_number.blank? @call = @parent.calls.new() - @call.dest = phone_number + @call.destination = phone_number end elsif !params[:number].blank? @call = @parent.calls.new() - @call.dest = params[:number] + @call.destination = params[:number] end end @@ -31,8 +31,7 @@ class CallsController < ApplicationController end def create - params[:call][:sip_account] = @sip_account - @call = Call.create(params[:call]) + @call = @sip_account.calls.create(params[:call]) if @call && @call.call m = method( :"#{@parent.class.name.underscore}_calls_url" ) diff --git a/app/models/call.rb b/app/models/call.rb index b0cd9b2..8f657fa 100644 --- a/app/models/call.rb +++ b/app/models/call.rb @@ -2,29 +2,31 @@ class Call < ActiveRecord::Base self.table_name = 'calls_active' self.primary_key = 'uuid' - attr_writer :sip_account_id + belongs_to :sip_account + belongs_to :b_sip_account, :class_name => SipAccount - validates :dest, + validates :sip_account_id, :presence => true - - def create(attributes=nil) - if ! attributes - return - end - self.sip_account = SipAccount.where(:id => attributes[:sip_account_id]).first - self.dest = attributes[:dest] - return self + validates :destination, + :presence => true + + def save(attributes=nil) end - def save(attributes=nil) - - end + def call + if self.sip_account && self.destination + return self.sip_account.call(self.destination) + end - def call(number=nil) - if @sip_account && self.dest - return @sip_account.call(self.dest) + if !self.sip_account + errors.add(:sip_account_id, 'no sip_account') end + + if self.destination.blank? + errors.add(:destination, 'no destination') + end + return false end @@ -37,38 +39,6 @@ class Call < ActiveRecord::Base return FreeswitchAPI.execute('uuid_kill', self.uuid, true); end - def sip_account=(sip_a) - @sip_account = sip_a - end - - def sip_account - if @sip_account - return @sip_account - end - - result = self.presence_id.match('^(.+)@(.+)$') - - if result && ! result[1].blank? and ! result[2].blank? - domain = SipDomain.where(:host => result[2]).first - if domain - @sip_account = SipAccount.where(:auth_name => result[1], :sip_domain_id => domain.id).first - end - end - - return @sip_account - end - - def sip_account_bleg - result = self.b_presence_id.match('^(.+)@(.+)$') - - if result && ! result[1].blank? and ! result[2].blank? - domain = SipDomain.where(:host => result[2]).first - if domain - return SipAccount.where(:auth_name => result[1], :sip_domain_id => domain.id).first - end - end - end - def get_variable_from_uuid(channel_uuid, variable_name) if channel_uuid.blank? return nil @@ -92,14 +62,4 @@ class Call < ActiveRecord::Base return get_variable_from_uuid(self.b_uuid, variable_name); end - def is_sip - return self.name.match('^sofia') != nil - end - - def is_caller - if (self.uuid == self.call_uuid) || self.call_uuid.blank? - true - end - end - end -- cgit v1.2.3