summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/calls_controller.rb54
-rw-r--r--app/models/call.rb39
-rw-r--r--app/models/sip_account.rb2
-rw-r--r--app/views/calls/_form.html.haml7
-rw-r--r--app/views/calls/_form_core.html.haml2
-rw-r--r--app/views/calls/_index_core.html.haml34
-rw-r--r--app/views/calls/index.html.haml6
-rw-r--r--app/views/calls/new.html.haml3
-rw-r--r--app/views/sip_accounts/show.html.haml6
-rw-r--r--config/locales/views/calls/de.yml37
-rw-r--r--config/locales/views/calls/en.yml37
-rw-r--r--config/routes.rb1
12 files changed, 218 insertions, 10 deletions
diff --git a/app/controllers/calls_controller.rb b/app/controllers/calls_controller.rb
index d5f3b42..5534b1b 100644
--- a/app/controllers/calls_controller.rb
+++ b/app/controllers/calls_controller.rb
@@ -1,6 +1,58 @@
class CallsController < ApplicationController
+ load_resource :sip_account
+ load_resource :call
+ before_filter :set_and_authorize_parent
+
def index
- @calls = Call.all
+ if @parent
+ @calls = @parent.calls
+ else
+ @calls = Call.all
+ end
+ end
+
+ def new
+ if !params[:url].blank?
+ protocol, separator, phone_number = params[:url].partition(':')
+ if ! phone_number.blank?
+ @call = @parent.calls.new()
+ @call.dest = phone_number
+ end
+ elsif !params[:number].blank?
+ @call = @parent.calls.new()
+ @call.dest = params[:number]
+ end
+ end
+
+ def show
+ redirect_to :index
+ end
+
+ def create
+ params[:call][:sip_account] = @sip_account
+ @call = Call.create(params[:call])
+
+ if @call && @call.call
+ m = method( :"#{@parent.class.name.underscore}_calls_url" )
+ redirect_to m.( @parent ), :notice => t('calls.controller.successfuly_created')
+ else
+ render :new
+ end
+ end
+
+ def destroy
+ @call.destroy
+ if @parent
+ m = method( :"#{@parent.class.name.underscore}_calls_url" )
+ else
+ m = method( :"calls_url" )
+ end
+ redirect_to m.(@parent), :notice => t('calls.controller.successfuly_destroyed')
+ end
+
+ private
+ def set_and_authorize_parent
+ @parent = @sip_account
end
end
diff --git a/app/models/call.rb b/app/models/call.rb
index c0f0f08..db6d9d6 100644
--- a/app/models/call.rb
+++ b/app/models/call.rb
@@ -1,9 +1,31 @@
class Call < ActiveRecord::Base
self.table_name = 'detailed_calls'
self.primary_key = 'uuid'
+
+ attr_writer :sip_account_id
+
+ validates :dest,
+ :presence => true
- def readonly?
- return 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
+ end
+
+ def save(attributes=nil)
+
+ end
+
+ def call(number=nil)
+ if @sip_account && self.dest
+ return @sip_account.call(self.dest)
+ end
+ return false
end
def destroy
@@ -15,15 +37,25 @@ 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
- return SipAccount.where(:auth_name => result[1], :sip_domain_id => domain.id).first
+ @sip_account = SipAccount.where(:auth_name => result[1], :sip_domain_id => domain.id).first
end
end
+
+ return @sip_account
end
def sip_account_bleg
@@ -69,4 +101,5 @@ class Call < ActiveRecord::Base
true
end
end
+
end
diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb
index 034af7c..2040b41 100644
--- a/app/models/sip_account.rb
+++ b/app/models/sip_account.rb
@@ -38,6 +38,8 @@ class SipAccount < ActiveRecord::Base
has_many :ringtones, :as => :ringtoneable, :dependent => :destroy
+ has_many :calls, :finder_sql => lambda { |s| "SELECT DISTINCT detailed_calls.* FROM detailed_calls WHERE presence_id LIKE '#{self.auth_name}@%'" }
+
# Delegations:
#
delegate :host, :to => :sip_domain, :allow_nil => true
diff --git a/app/views/calls/_form.html.haml b/app/views/calls/_form.html.haml
new file mode 100644
index 0000000..ccdcd72
--- /dev/null
+++ b/app/views/calls/_form.html.haml
@@ -0,0 +1,7 @@
+= simple_form_for([ @parent, @call ]) do |f|
+ = f.error_notification
+
+ = render "form_core", :f => f
+
+ .form-actions
+ = f.button :submit, conditional_t('calls.form.submit')
diff --git a/app/views/calls/_form_core.html.haml b/app/views/calls/_form_core.html.haml
new file mode 100644
index 0000000..4cdd55e
--- /dev/null
+++ b/app/views/calls/_form_core.html.haml
@@ -0,0 +1,2 @@
+.inputs
+ = f.input :dest, :as => :string, :label => t('calls.form.destination.label'), :hint => conditional_hint('calls.form.destination.hint'), :autofocus => true
diff --git a/app/views/calls/_index_core.html.haml b/app/views/calls/_index_core.html.haml
index 10f79f1..e5b769e 100644
--- a/app/views/calls/_index_core.html.haml
+++ b/app/views/calls/_index_core.html.haml
@@ -1,10 +1,38 @@
%table.table.table-striped
%thead
%tr
- %th= t('calls.index.uuid')
+ %th
+ %th= t('calls.index.created')
+ %th= t('calls.index.destination')
+ %th= t('calls.index.caller')
+ %th= t('calls.index.callee')
+ %th= t('calls.index.callstate')
+ %th= t('calls.index.codecs')
+ %th
%tbody
- - for call in @calls
+ - for call in calls
%tr
%td
- = call.uuid
+ - if call.direction == 'inbound'
+ %i.icon-arrow-left
+ - else
+ %i.icon-arrow-right
+ %td
+ = call.created
+ %td
+ = call.dest
+ %td
+ = "#{call.cid_name} #{call.cid_num}"
+ %td
+ = "#{call.callee_name} #{call.callee_num}"
+ %td
+ = call.callstate
+ %td
+ = "#{call.read_codec}/#{call.write_codec}"
+
+ %td
+ %p
+ %a.btn.btn-small.btn-danger{'data-confirm' => t('calls.index.actions.confirm_destroy'), 'data-method' => 'delete', :href => method( :"#{parent.class.name.underscore}_call_path" ).(parent, call), :rel => 'nofollow'}
+ %i.icon-trash.icon-white
+ =t('calls.index.actions.destroy')
diff --git a/app/views/calls/index.html.haml b/app/views/calls/index.html.haml
index be678cd..a87f809 100644
--- a/app/views/calls/index.html.haml
+++ b/app/views/calls/index.html.haml
@@ -1,6 +1,8 @@
- content_for :title, t("calls.index.page_title")
- if @calls.count > 0
- = render "index_core", :calls => @calls
+ = render "index_core", :calls => @calls, :parent => @parent
-= render :partial => 'shared/create_link', :locals => {:parent => @parent, :child_class => Call} \ No newline at end of file
+%a.btn.btn-small.btn-default{:href => method( :"new_#{@parent.class.name.underscore}_call_path" ).(@parent) }
+ %i.icon-plus
+ =t("calls.index.actions.create")
diff --git a/app/views/calls/new.html.haml b/app/views/calls/new.html.haml
new file mode 100644
index 0000000..44bb6ae
--- /dev/null
+++ b/app/views/calls/new.html.haml
@@ -0,0 +1,3 @@
+- content_for :title, t("calls.new.page_title")
+
+= render "form"
diff --git a/app/views/sip_accounts/show.html.haml b/app/views/sip_accounts/show.html.haml
index 0aaf920..365aea8 100644
--- a/app/views/sip_accounts/show.html.haml
+++ b/app/views/sip_accounts/show.html.haml
@@ -94,4 +94,8 @@
- if @sip_account.softkeys.count > 0
= render "softkeys/index_core", :softkeys => @sip_account.softkeys
%br
- = render :partial => 'shared/create_link', :locals => { :parent => @sip_account, :child_class => Softkey } \ No newline at end of file
+ = render :partial => 'shared/create_link', :locals => { :parent => @sip_account, :child_class => Softkey }
+
+- if @sip_account.calls.count > 0
+ %h2= t("calls.index.page_title")
+ = render "calls/index_core", :calls => @sip_account.calls, :parent => @sip_account
diff --git a/config/locales/views/calls/de.yml b/config/locales/views/calls/de.yml
new file mode 100644
index 0000000..1410e34
--- /dev/null
+++ b/config/locales/views/calls/de.yml
@@ -0,0 +1,37 @@
+de:
+ calls:
+ name: 'Anruf'
+ controller:
+ successfuly_created: 'Einen neue Anruf wurde erstellt.'
+ successfuly_updated: 'Der Anruf wurde aktualisiert.'
+ successfuly_destroyed: 'Der Anruf wurde aufgelegt.'
+ index:
+ page_title: 'Anrufe'
+ uuid: 'UUID'
+ actions:
+ confirm_destroy: 'Sind Sie sicher, dass Sie diese Anruf auflegen möchten?'
+ destroy: 'Löschen'
+ edit: 'Bearbeiten'
+ show: 'Anzeigen'
+ create: 'Neuer Anruf'
+ create_for: 'Neuer Anruf für %{resource}'
+ show:
+ page_title: 'Anruf'
+ uuid: 'UUID'
+ actions:
+ confirm_destroy: 'Sind Sie sicher, dass Sie diese Anruf auflegen möchten?'
+ destroy: 'Auflegen'
+ edit: 'Bearbeiten'
+ view_all: 'Alle Anrufe anzeigen'
+ new:
+ page_title: 'Neuer Anruf'
+ edit:
+ page_title: 'Anruf bearbeiten'
+ form:
+ uuid:
+ label: 'UUID'
+ hint: ''
+ destination:
+ label: 'Ziel'
+ hint: ''
+ submit: 'Absenden'
diff --git a/config/locales/views/calls/en.yml b/config/locales/views/calls/en.yml
new file mode 100644
index 0000000..9161d03
--- /dev/null
+++ b/config/locales/views/calls/en.yml
@@ -0,0 +1,37 @@
+en:
+ calls:
+ name: 'Call'
+ controller:
+ successfuly_created: 'Successfully created call.'
+ successfuly_updated: 'Successfully updated call.'
+ successfuly_destroyed: 'Successfully hung up call.'
+ index:
+ page_title: 'Calls'
+ uuid: 'UUID'
+ actions:
+ confirm_destroy: 'Are you sure you want to drop this call?'
+ destroy: 'Hang up'
+ edit: 'Edit'
+ show: 'View'
+ create: 'New'
+ create_for: 'New call for sip account %{resource}'
+ show:
+ page_title: 'Call'
+ uuid: 'UUID'
+ actions:
+ confirm_destroy: 'Are you sure you want to drop this call?'
+ destroy: 'Delete'
+ edit: 'Edit'
+ view_all: 'View all calls'
+ new:
+ page_title: 'New call'
+ edit:
+ page_title: 'Editing call'
+ form:
+ uuid:
+ label: 'UUID'
+ hint: ''
+ destination:
+ label: 'Destination'
+ hint: ''
+ submit: 'Submit'
diff --git a/config/routes.rb b/config/routes.rb
index adff556..2fe1682 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -257,6 +257,7 @@ Gemeinschaft42c::Application.routes.draw do
resources :softkeys
resources :call_forwards
resources :ringtones
+ resources :calls
resources :call_histories do
collection do
delete 'destroy_multiple'