summaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/calls_controller.rb54
1 files changed, 53 insertions, 1 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