diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/api/v1/calls_controller.rb | 17 | ||||
-rw-r--r-- | app/models/switchboard.rb | 11 | ||||
-rw-r--r-- | app/serializers/switchboard_entry_serializer.rb | 2 | ||||
-rw-r--r-- | app/serializers/switchboard_serializer.rb | 1 | ||||
-rw-r--r-- | app/views/switchboards/show.html.erb | 39 |
5 files changed, 54 insertions, 16 deletions
diff --git a/app/controllers/api/v1/calls_controller.rb b/app/controllers/api/v1/calls_controller.rb index e6fbed4..329bd94 100644 --- a/app/controllers/api/v1/calls_controller.rb +++ b/app/controllers/api/v1/calls_controller.rb @@ -14,6 +14,23 @@ module Api if params[:transfer_blind] @call.transfer_blind(params[:transfer_blind]) + else + if params[:transfer_attended] && @call.b_sip_account.phones.first.phone_model.manufacturer.name == 'SNOM Technology AG' + phone = @call.b_sip_account.phones.first + ip_address = phone.ip_address + http_user = phone.http_user + http_password = phone.http_password + + # Hold + open("http://#{ip_address}/command.htm?key=F_HOLD", :http_basic_authentication=>[http_user, http_password]) + + # Call the other party + (0..(params[:transfer_attended].length - 1)).each do |i| + digit = params[:transfer_attended][i] + open("http://#{ip_address}/command.htm?key=#{digit}", :http_basic_authentication=>[http_user, http_password]) + end + open("http://#{ip_address}/command.htm?key=ENTER", :http_basic_authentication=>[http_user, http_password]) + end end respond_with @call diff --git a/app/models/switchboard.rb b/app/models/switchboard.rb index 095f878..d62657f 100644 --- a/app/models/switchboard.rb +++ b/app/models/switchboard.rb @@ -25,8 +25,13 @@ class Switchboard < ActiveRecord::Base } belongs_to :user, :touch => true + has_many :switchboard_entries, :dependent => :destroy + has_many :switchable_switchboard_entries, :class_name => "SwitchboardEntry", :conditions => {:switchable => true} + has_many :sip_accounts, :through => :switchboard_entries + has_many :switchable_sip_accounts, :source => :sip_account, :through => :switchable_switchboard_entries, :uniq => true + has_many :phone_numbers, :through => :sip_accounts before_validation :convert_0_to_nil @@ -36,7 +41,11 @@ class Switchboard < ActiveRecord::Base end def active_calls - self.switchboard_entries.where(:switchable => true).map{|se| se.sip_account}.uniq.map{|sip_account| sip_account.calls}.flatten + Call.where("sip_account_id = ? or b_sip_account_id = ?", self.switchable_sip_account_ids, self.switchable_sip_account_ids).order(:start_stamp) + end + + def dispatchable_incoming_calls + Call.where("b_sip_account_id = ?", self.switchable_sip_account_ids).order(:start_stamp) end private diff --git a/app/serializers/switchboard_entry_serializer.rb b/app/serializers/switchboard_entry_serializer.rb index 1b6c761..5d76e16 100644 --- a/app/serializers/switchboard_entry_serializer.rb +++ b/app/serializers/switchboard_entry_serializer.rb @@ -1,5 +1,5 @@ class SwitchboardEntrySerializer < ActiveModel::Serializer - attributes :id, :name, :path_to_user, :avatar_src, :callstate + attributes :id, :name, :path_to_user, :avatar_src, :callstate, :switchable has_one :sip_account, embed: :ids has_one :switchboard, embed: :ids diff --git a/app/serializers/switchboard_serializer.rb b/app/serializers/switchboard_serializer.rb index 6d39667..7c21f82 100644 --- a/app/serializers/switchboard_serializer.rb +++ b/app/serializers/switchboard_serializer.rb @@ -6,4 +6,5 @@ class SwitchboardSerializer < ActiveModel::Serializer has_many :sip_accounts, :through => :switchboard_entries has_many :phone_numbers has_many :active_calls + has_many :dispatchable_incoming_calls end diff --git a/app/views/switchboards/show.html.erb b/app/views/switchboards/show.html.erb index 1a8e5a0..b390ce5 100644 --- a/app/views/switchboards/show.html.erb +++ b/app/views/switchboards/show.html.erb @@ -40,21 +40,32 @@ </p> {{/if}} - <p> - {{#each phoneNumber in switchboardEntry.sipAccount.phoneNumberShortList}} - <span class="label"> - {{phoneNumber.number}} - </span> + {{#if switchboardEntry.switchable}} + <p> + {{#each phoneNumber in switchboardEntry.sipAccount.phoneNumberShortList}} + <span class="label"> + {{phoneNumber.number}} + </span> + {{/each}} + </p> + {{else}} + <p> + {{#each phoneNumber in switchboardEntry.sipAccount.phoneNumberShortList}} + <span class="label"> + {{phoneNumber.number}} + </span> - {{#if activeCalls.length}} - <p> - {{#each activeCall in activeCalls}} - <button {{action transfer_blind activeCall.id phoneNumber.number}} class="btn btn-small">Transfer</button> - {{/each}} - </p> - {{/if}} - {{/each}} - </p> + {{#if dispatchableIncomingCalls.length}} + <p> + {{#each dispatchableIncomingCall in dispatchableIncomingCalls}} + <button {{action transfer_blind dispatchableIncomingCall.id phoneNumber.number}} class="btn btn-small">Transfer</button> + <button {{action transfer_attended dispatchableIncomingCall.id phoneNumber.number}} class="btn btn-small">Attended Transfer</button> + {{/each}} + </p> + {{/if}} + {{/each}} + </p> + {{/if}} {{#if switchboardEntry.sipAccount.calls.length}} <p> |