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
|
2016-08-11 15:27:35 +02:00
|
|
|
smartlisting_dossier (params[:liste] || 'a_traiter')
|
2015-11-13 15:23:21 +01:00
|
|
|
end
|
|
|
|
|
2015-12-02 18:03:52 +01:00
|
|
|
def show
|
2015-12-24 15:10:20 +01:00
|
|
|
create_dossier_facade params[:id]
|
2016-08-08 12:52:30 +02:00
|
|
|
@champs = @facade.champs_private unless @facade.nil?
|
2015-12-02 18:03:52 +01:00
|
|
|
end
|
|
|
|
|
2016-08-25 12:30:15 +02:00
|
|
|
def download_dossiers_tps
|
|
|
|
dossiers = current_gestionnaire.dossiers.where.not(state: :draft)
|
|
|
|
|
|
|
|
response.headers['Content-Type'] = 'text/csv'
|
|
|
|
|
|
|
|
render csv: dossiers, status: 200
|
|
|
|
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
|
|
|
|
2016-08-11 15:27:35 +02:00
|
|
|
create_dossiers_list_facade
|
|
|
|
|
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?
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2016-08-01 18:10:32 +02:00
|
|
|
def reload_smartlisting
|
|
|
|
begin
|
|
|
|
@liste = URI(request.referer).query.split('=').second
|
|
|
|
rescue NoMethodError
|
|
|
|
@liste = 'a_traiter'
|
|
|
|
end
|
2016-08-11 15:27:35 +02:00
|
|
|
|
|
|
|
smartlisting_dossier @liste
|
2016-08-01 18:10:32 +02:00
|
|
|
|
|
|
|
render 'backoffice/dossiers/index', formats: :js
|
|
|
|
end
|
|
|
|
|
2015-11-02 16:36:52 +01:00
|
|
|
private
|
|
|
|
|
2016-08-11 15:27:35 +02:00
|
|
|
def smartlisting_dossier liste
|
|
|
|
create_dossiers_list_facade liste
|
|
|
|
|
2016-08-01 18:10:32 +02:00
|
|
|
@dossiers = smart_listing_create :dossiers,
|
2016-08-11 15:27:35 +02:00
|
|
|
@dossiers_list_facade.dossiers_to_display,
|
2016-08-01 18:10:32 +02:00
|
|
|
partial: "backoffice/dossiers/list",
|
|
|
|
array: true
|
|
|
|
end
|
|
|
|
|
2016-08-11 15:27:35 +02:00
|
|
|
def create_dossiers_list_facade liste='a_traiter'
|
|
|
|
@dossiers_list_facade = DossiersListFacades.new current_gestionnaire, liste
|
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
|