summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/api/v1/calls_controller.rb17
-rw-r--r--app/models/switchboard.rb11
-rw-r--r--app/serializers/switchboard_entry_serializer.rb2
-rw-r--r--app/serializers/switchboard_serializer.rb1
-rw-r--r--app/views/switchboards/show.html.erb39
-rw-r--r--config/locales/views/switchboard_entries/de.yml5
-rw-r--r--config/locales/views/switchboard_entries/en.yml5
-rw-r--r--public/js/app.js36
8 files changed, 97 insertions, 19 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>
diff --git a/config/locales/views/switchboard_entries/de.yml b/config/locales/views/switchboard_entries/de.yml
index 41804b5..e79b6e8 100644
--- a/config/locales/views/switchboard_entries/de.yml
+++ b/config/locales/views/switchboard_entries/de.yml
@@ -11,6 +11,7 @@ de:
sip_account_id: 'SIP-Account'
name: 'Name'
position: 'Position'
+ switchable: 'Vermittelbar'
actions:
confirm_destroy: 'Sind Sie sicher, dass Sie folgendes löschen möchten: Switchboard-Eintrag'
destroy: 'Löschen'
@@ -24,6 +25,7 @@ de:
sip_account_id: 'SIP-Account'
name: 'Name'
position: 'Position'
+ switchable: 'Vermittelbar'
actions:
confirm_destroy: 'Sind Sie sicher, dass die dieses Element löschen möchten?'
destroy: 'Löschen'
@@ -52,4 +54,7 @@ de:
position:
label: 'Position'
hint: ''
+ switchable:
+ label: 'Vermittelbarer SIP-Account'
+ hint: 'Gespräche an diesen SIP-Account können im Switchboard vermittelt werden.'
submit: 'Absenden' \ No newline at end of file
diff --git a/config/locales/views/switchboard_entries/en.yml b/config/locales/views/switchboard_entries/en.yml
index 71f2fe4..a964a41 100644
--- a/config/locales/views/switchboard_entries/en.yml
+++ b/config/locales/views/switchboard_entries/en.yml
@@ -11,6 +11,7 @@ en:
sip_account_id: 'Sip account'
name: 'Name'
position: 'Position'
+ switchable: 'Switchable'
actions:
confirm_destroy: 'Are you sure you want to delete this Switchboardentry?'
destroy: 'Delete'
@@ -24,6 +25,7 @@ en:
sip_account_id: 'Sip account'
name: 'Name'
position: 'Position'
+ switchable: 'Switchable'
actions:
confirm_destroy: 'Are you sure you want to delete this element?'
destroy: 'Delete'
@@ -52,4 +54,7 @@ en:
position:
label: 'Position'
hint: ''
+ switchable:
+ label: 'Switchable SIP-Account'
+ hint: 'Only calls to switchable SIP-Accounts can be transfered.'
submit: 'Submit' \ No newline at end of file
diff --git a/public/js/app.js b/public/js/app.js
index 6d8448a..531e4b8 100644
--- a/public/js/app.js
+++ b/public/js/app.js
@@ -27,10 +27,14 @@ App.SwitchboardRoute = Ember.Route.extend({
// Controller
App.SwitchboardController = Ember.ObjectController.extend({
transfer_blind: function(call_id, destination) {
- console.log('test')
request_url = '/api/v1/calls/' + call_id + '.json';
jQuery.get(request_url, { transfer_blind: destination });
- }
+ },
+
+ transfer_attended: function(call_id, destination) {
+ request_url = '/api/v1/calls/' + call_id + '.json';
+ jQuery.get(request_url, { transfer_attended: destination });
+ }
});
// Models
@@ -47,6 +51,7 @@ DS.RESTAdapter.reopen({
App.Switchboard = DS.Model.extend({
switchboardEntrys: DS.hasMany('App.SwitchboardEntry'),
activeCalls: DS.hasMany('App.ActiveCall'),
+ dispatchableIncomingCalls: DS.hasMany('App.DispatchableIncomingCall'),
name: DS.attr('string')
});
@@ -56,7 +61,8 @@ App.SwitchboardEntry = DS.Model.extend({
name: DS.attr('string'),
path_to_user: DS.attr('string'),
avatar_src: DS.attr('string'),
- callstate: DS.attr('string')
+ callstate: DS.attr('string'),
+ switchable: DS.attr('boolean')
});
App.ActiveCall = DS.Model.extend({
@@ -83,6 +89,30 @@ App.ActiveCall = DS.Model.extend({
}.property('b_callstate')
});
+App.DispatchableIncomingCall = DS.Model.extend({
+ start_stamp: DS.attr('number'),
+ callstate: DS.attr('string'),
+ b_callstate: DS.attr('string'),
+ destination: DS.attr('string'),
+ b_caller_id_number: DS.attr('string'),
+
+ isActive: function() {
+ if (this.get('b_callstate') == 'ACTIVE') {
+ return true
+ } else {
+ return false
+ }
+ }.property('b_callstate'),
+
+ isRinging: function() {
+ if (this.get('b_callstate') == 'RINGING') {
+ return true
+ } else {
+ return false
+ }
+ }.property('b_callstate')
+});
+
App.Adapter = DS.RESTAdapter.extend();
App.store = App.Store.create({