From 4d7d5ad238990582d6c90a25272f2141ea9a3b28 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Fri, 8 Mar 2013 05:50:02 -0500 Subject: toggle action added to acd_agents --- app/controllers/acd_agents_controller.rb | 32 +++++++++++++++++++----------- app/models/ability.rb | 5 +++++ app/models/acd_agent.rb | 9 +++++++++ app/models/sip_account.rb | 2 ++ app/views/acd_agents/_index_core.html.haml | 13 ++++++++++-- app/views/sip_accounts/show.html.haml | 7 +++++++ config/routes.rb | 6 +++++- 7 files changed, 59 insertions(+), 15 deletions(-) diff --git a/app/controllers/acd_agents_controller.rb b/app/controllers/acd_agents_controller.rb index 4c08f68..e2aabdf 100644 --- a/app/controllers/acd_agents_controller.rb +++ b/app/controllers/acd_agents_controller.rb @@ -1,7 +1,7 @@ class AcdAgentsController < ApplicationController - load_and_authorize_resource :automatic_call_distributor - load_and_authorize_resource :acd_agent, :through => [:automatic_call_distributor] - + load_and_authorize_resource :automatic_call_distributor, :except => [:toggle] + load_and_authorize_resource :acd_agent, :through => [:automatic_call_distributor], :except => [:toggle] + load_and_authorize_resource :acd_agent, :only => [:toggle] before_filter :spread_breadcrumbs def index @@ -62,16 +62,24 @@ class AcdAgentsController < ApplicationController redirect_to automatic_call_distributor_acd_agents_path(@automatic_call_distributor), :notice => t('acd_agents.controller.successfuly_destroyed') end + def toggle + @acd_agent.toggle_status + redirect_to request.referer + end + + private def spread_breadcrumbs - if @automatic_call_distributor.automatic_call_distributorable.class == User - add_breadcrumb t("#{@automatic_call_distributor.automatic_call_distributorable.class.name.underscore.pluralize}.index.page_title"), method( :"tenant_#{@automatic_call_distributor.automatic_call_distributorable.class.name.underscore.pluralize}_path" ).(@automatic_call_distributor.tenant) - add_breadcrumb @automatic_call_distributor.automatic_call_distributorable, method( :"tenant_#{@automatic_call_distributor.automatic_call_distributorable.class.name.underscore}_path" ).(@automatic_call_distributor.tenant, @automatic_call_distributor.automatic_call_distributorable) - end - add_breadcrumb t("automatic_call_distributors.index.page_title"), method( :"#{@automatic_call_distributor.automatic_call_distributorable.class.name.underscore}_automatic_call_distributors_path" ).(@automatic_call_distributor.automatic_call_distributorable) - add_breadcrumb @automatic_call_distributor, method( :"#{@automatic_call_distributor.automatic_call_distributorable.class.name.underscore}_automatic_call_distributor_path" ).(@automatic_call_distributor.automatic_call_distributorable, @automatic_call_distributor) - add_breadcrumb t("acd_agents.index.page_title"), automatic_call_distributor_acd_agents_path(@automatic_call_distributor) - if @acd_agent && !@acd_agent.new_record? - add_breadcrumb @acd_agent, automatic_call_distributor_acd_agent_path(@automatic_call_distributor, @acd_agent) + if @automatic_call_distributor + if @automatic_call_distributor.automatic_call_distributorable.class == User + add_breadcrumb t("#{@automatic_call_distributor.automatic_call_distributorable.class.name.underscore.pluralize}.index.page_title"), method( :"tenant_#{@automatic_call_distributor.automatic_call_distributorable.class.name.underscore.pluralize}_path" ).(@automatic_call_distributor.tenant) + add_breadcrumb @automatic_call_distributor.automatic_call_distributorable, method( :"tenant_#{@automatic_call_distributor.automatic_call_distributorable.class.name.underscore}_path" ).(@automatic_call_distributor.tenant, @automatic_call_distributor.automatic_call_distributorable) + end + add_breadcrumb t("automatic_call_distributors.index.page_title"), method( :"#{@automatic_call_distributor.automatic_call_distributorable.class.name.underscore}_automatic_call_distributors_path" ).(@automatic_call_distributor.automatic_call_distributorable) + add_breadcrumb @automatic_call_distributor, method( :"#{@automatic_call_distributor.automatic_call_distributorable.class.name.underscore}_automatic_call_distributor_path" ).(@automatic_call_distributor.automatic_call_distributorable, @automatic_call_distributor) + add_breadcrumb t("acd_agents.index.page_title"), automatic_call_distributor_acd_agents_path(@automatic_call_distributor) + if @acd_agent && !@acd_agent.new_record? + add_breadcrumb @acd_agent, automatic_call_distributor_acd_agent_path(@automatic_call_distributor, @acd_agent) + end end end end diff --git a/app/models/ability.rb b/app/models/ability.rb index 3cd1d4d..fe67547 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -170,6 +170,11 @@ class Ability can :manage, Ringtone, :ringtoneable_type => 'SipAccount', :ringtoneable_id => user.sip_account_ids can :create, Ringtone + # User can read and toggle status of ACD agents + # + can :read, AcdAgent, :destination_type => 'SipAccount', :destination_id => user.sip_account_ids + can :toggle, AcdAgent, :destination_type => 'SipAccount', :destination_id => user.sip_account_ids + # SoftkeyFunctions # can :read, SoftkeyFunction diff --git a/app/models/acd_agent.rb b/app/models/acd_agent.rb index 4be4700..61899f8 100644 --- a/app/models/acd_agent.rb +++ b/app/models/acd_agent.rb @@ -20,6 +20,15 @@ class AcdAgent < ActiveRecord::Base self.name || I18n.t('acd_agents.name') + ' ID ' + self.id.to_s end + def toggle_status + if self.status == 'active' + self.status = 'inactive' + else + self.status = 'active' + end + return self.save + end + private def set_presence dialplan_function = nil diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index 1ff3c9a..a5b8bad 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -41,6 +41,8 @@ class SipAccount < ActiveRecord::Base has_many :call_legs, :class_name => 'Call' has_many :b_call_legs, :class_name => 'Call', :foreign_key => 'b_sip_account_id' + has_many :acd_agents, :as => :destination, :dependent => :destroy + # Delegations: # delegate :host, :to => :sip_domain, :allow_nil => true diff --git a/app/views/acd_agents/_index_core.html.haml b/app/views/acd_agents/_index_core.html.haml index c8967cd..f1172f2 100644 --- a/app/views/acd_agents/_index_core.html.haml +++ b/app/views/acd_agents/_index_core.html.haml @@ -1,8 +1,8 @@ %table.table.table-striped %thead %tr + %th %th= t('acd_agents.index.name') - %th= t('acd_agents.index.status') %th= t('acd_agents.index.last_call') %th= t('acd_agents.index.calls_answered') %th= t('acd_agents.index.destination') @@ -10,8 +10,17 @@ %tbody - for acd_agent in acd_agents %tr + %td + - if acd_agent.status == 'active' + %a.btn.btn-small.btn-success{ :href => toggle_acd_agent_path(acd_agent) } + %i.icon-ok.icon-white + - elsif acd_agent.status == 'inactive' + %a.btn.btn-small.btn-danger{ :href => toggle_acd_agent_path(acd_agent) } + %i.icon-ban-circle.icon-white + - else + %a.btn.btn-small.btn-warning{ :href => toggle_acd_agent_path(acd_agent) } + = acd_agent.status %td= acd_agent.name - %td= acd_agent.status %td= acd_agent.last_call %td= acd_agent.calls_answered %td= acd_agent.destination diff --git a/app/views/sip_accounts/show.html.haml b/app/views/sip_accounts/show.html.haml index 365aea8..9f84c92 100644 --- a/app/views/sip_accounts/show.html.haml +++ b/app/views/sip_accounts/show.html.haml @@ -99,3 +99,10 @@ - if @sip_account.calls.count > 0 %h2= t("calls.index.page_title") = render "calls/index_core", :calls => @sip_account.calls, :parent => @sip_account + +- if (can?(:read, AcdAgent) && @sip_account.acd_agents.count > 0) || can?(:create, @sip_account.acd_agents.build) + %h2= t('acd_agents.index.page_title') + - if @sip_account.acd_agents.count > 0 + = render "acd_agents/index_core", :acd_agents => @sip_account.acd_agents + %br + = render :partial => 'shared/create_link', :locals => { :parent => @sip_account, :child_class => AcdAgent } diff --git a/config/routes.rb b/config/routes.rb index 0b953ee..d74df15 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -57,8 +57,11 @@ Gemeinschaft42c::Application.routes.draw do collection { post :sort } end - resources :acd_agents, :only => [] do + resources :acd_agents do resources :phone_numbers + member do + get 'toggle' + end end resources :automatic_call_distributors, :only => [] do @@ -260,6 +263,7 @@ Gemeinschaft42c::Application.routes.draw do resources :call_forwards resources :ringtones resources :calls + resources :acd_agents resources :call_histories do collection do delete 'destroy_multiple' -- cgit v1.2.3