2015-09-22 15:00:59 +02:00
|
|
|
class Backoffice::DossiersController < ApplicationController
|
2016-01-08 11:39:04 +01:00
|
|
|
include SmartListing::Helper::ControllerExtensions
|
|
|
|
helper SmartListing::Helper
|
|
|
|
|
2015-09-22 10:15:12 +02:00
|
|
|
before_action :authenticate_gestionnaire!
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2015-12-02 18:03:52 +01:00
|
|
|
def index
|
2015-12-24 15:10:20 +01:00
|
|
|
@liste = params[:liste] || 'a_traiter'
|
2016-01-08 11:39:04 +01:00
|
|
|
|
|
|
|
@dossiers = smart_listing_create :dossiers,
|
|
|
|
dossiers_to_display,
|
|
|
|
partial: "backoffice/dossiers/list",
|
|
|
|
array: true
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2015-11-13 15:23:21 +01:00
|
|
|
total_dossiers_per_state
|
|
|
|
end
|
|
|
|
|
2015-12-02 18:03:52 +01:00
|
|
|
def show
|
2015-12-24 15:10:20 +01:00
|
|
|
create_dossier_facade params[:id]
|
2015-12-02 18:03:52 +01:00
|
|
|
end
|
|
|
|
|
2015-11-17 18:21:03 +01:00
|
|
|
def search
|
2015-11-26 15:47:31 +01:00
|
|
|
@search_terms = params[:q]
|
2015-11-17 18:21:03 +01:00
|
|
|
@dossiers_search, @dossier = Dossier.search(current_gestionnaire, @search_terms)
|
2015-11-26 15:47:31 +01:00
|
|
|
|
|
|
|
unless @dossiers_search.empty?
|
2015-11-30 17:03:36 +01:00
|
|
|
@dossiers_search = @dossiers_search.paginate(:page => params[:page]).decorate
|
2015-11-26 15:47:31 +01:00
|
|
|
end
|
|
|
|
|
2015-11-17 18:21:03 +01:00
|
|
|
@dossier = @dossier.decorate unless @dossier.nil?
|
|
|
|
|
|
|
|
total_dossiers_per_state
|
|
|
|
rescue RuntimeError
|
|
|
|
@dossiers_search = []
|
|
|
|
end
|
|
|
|
|
2015-11-02 11:45:52 +01:00
|
|
|
def valid
|
2015-12-24 15:10:20 +01:00
|
|
|
create_dossier_facade params[:dossier_id]
|
2015-09-24 16:51:14 +02:00
|
|
|
|
2015-12-24 15:10:20 +01:00
|
|
|
@facade.dossier.next_step! 'gestionnaire', 'valid'
|
2015-09-24 16:51:14 +02:00
|
|
|
flash.notice = 'Dossier confirmé avec succès.'
|
|
|
|
|
2015-12-24 15:10:20 +01:00
|
|
|
NotificationMailer.dossier_validated(@facade.dossier).deliver_now!
|
2015-12-15 15:37:46 +01:00
|
|
|
|
2015-09-24 16:51:14 +02:00
|
|
|
render 'show'
|
|
|
|
end
|
2015-10-09 12:05:07 +02:00
|
|
|
|
2015-11-02 15:00:28 +01:00
|
|
|
def close
|
2015-12-24 15:10:20 +01:00
|
|
|
create_dossier_facade params[:dossier_id]
|
2015-10-09 12:05:07 +02:00
|
|
|
|
2015-12-24 15:10:20 +01:00
|
|
|
@facade.dossier.next_step! 'gestionnaire', 'close'
|
2015-10-09 12:05:07 +02:00
|
|
|
flash.notice = 'Dossier traité avec succès.'
|
|
|
|
|
|
|
|
render 'show'
|
|
|
|
end
|
2015-11-02 16:36:52 +01:00
|
|
|
|
2016-07-18 18:24:29 +02:00
|
|
|
def follow
|
|
|
|
follow = current_gestionnaire.toggle_follow_dossier params[:dossier_id]
|
|
|
|
|
|
|
|
flash.notice = (follow.class == Follow ? 'Dossier suivi' : 'Dossier relaché')
|
|
|
|
redirect_to request.referer
|
|
|
|
end
|
|
|
|
|
2015-11-02 16:36:52 +01:00
|
|
|
private
|
|
|
|
|
2015-12-24 15:10:20 +01:00
|
|
|
def dossiers_to_display
|
|
|
|
{'a_traiter' => waiting_for_gestionnaire,
|
|
|
|
'en_attente' => waiting_for_user,
|
2016-07-19 17:18:41 +02:00
|
|
|
'termine' => termine,
|
|
|
|
'suivi' => suivi}[@liste]
|
2015-11-13 15:23:21 +01:00
|
|
|
end
|
|
|
|
|
2015-12-24 15:10:20 +01:00
|
|
|
def waiting_for_gestionnaire
|
|
|
|
@a_traiter_class = (@liste == 'a_traiter' ? 'active' : '')
|
2016-03-14 16:49:12 +01:00
|
|
|
@waiting_for_gestionnaire ||= current_gestionnaire.dossiers_filter.waiting_for_gestionnaire
|
2015-12-24 15:10:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def waiting_for_user
|
|
|
|
@en_attente_class = (@liste == 'en_attente' ? 'active' : '')
|
2016-03-14 16:49:12 +01:00
|
|
|
@waiting_for_user ||= current_gestionnaire.dossiers_filter.waiting_for_user
|
2015-12-24 15:10:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def termine
|
|
|
|
@termine_class = (@liste == 'termine' ? 'active' : '')
|
2016-03-14 16:49:12 +01:00
|
|
|
@termine ||= current_gestionnaire.dossiers_filter.termine
|
2015-12-24 15:10:20 +01:00
|
|
|
end
|
|
|
|
|
2016-07-19 17:18:41 +02:00
|
|
|
def suivi
|
|
|
|
@suivi_class = (@liste == 'suivi' ? 'active' : '')
|
|
|
|
@suivi ||= current_gestionnaire.dossiers_follow
|
|
|
|
end
|
|
|
|
|
2015-12-24 15:10:20 +01:00
|
|
|
def total_dossiers_per_state
|
|
|
|
@dossiers_a_traiter_total = waiting_for_gestionnaire.count
|
|
|
|
@dossiers_en_attente_total = waiting_for_user.count
|
|
|
|
@dossiers_termine_total = termine.count
|
2016-07-19 17:18:41 +02:00
|
|
|
@dossiers_suivi_total = suivi.count
|
2015-12-24 15:10:20 +01:00
|
|
|
end
|
2015-11-02 16:36:52 +01:00
|
|
|
|
2015-12-24 15:10:20 +01:00
|
|
|
def create_dossier_facade dossier_id
|
|
|
|
@facade = DossierFacades.new dossier_id, current_gestionnaire.email
|
2015-11-02 16:36:52 +01:00
|
|
|
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
flash.alert = t('errors.messages.dossier_not_found')
|
|
|
|
redirect_to url_for(controller: '/backoffice')
|
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|