2017-09-06 11:21:29 +02:00
|
|
|
module NewGestionnaire
|
|
|
|
class AvisController < ApplicationController
|
|
|
|
layout 'new_application'
|
|
|
|
|
|
|
|
A_DONNER_STATUS = 'a-donner'
|
|
|
|
DONNES_STATUS = 'donnes'
|
|
|
|
|
|
|
|
def index
|
|
|
|
gestionnaire_avis = current_gestionnaire.avis.includes(dossier: [:procedure, :user])
|
|
|
|
@avis_a_donner, @avis_donnes = gestionnaire_avis.partition { |avis| avis.answer.nil? }
|
|
|
|
|
|
|
|
@statut = params[:statut].present? ? params[:statut] : A_DONNER_STATUS
|
|
|
|
|
|
|
|
@avis = case @statut
|
|
|
|
when A_DONNER_STATUS
|
|
|
|
@avis_a_donner
|
|
|
|
when DONNES_STATUS
|
|
|
|
@avis_donnes
|
|
|
|
end
|
|
|
|
end
|
2017-09-06 11:26:32 +02:00
|
|
|
|
|
|
|
def show
|
|
|
|
@avis = avis
|
|
|
|
@dossier = avis.dossier
|
|
|
|
end
|
|
|
|
|
2017-09-06 16:14:03 +02:00
|
|
|
def instruction
|
|
|
|
@avis = avis
|
|
|
|
@dossier = avis.dossier
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
avis.update_attributes(avis_params)
|
|
|
|
flash.notice = 'Votre réponse est enregistrée.'
|
|
|
|
redirect_to instruction_avis_path(avis)
|
|
|
|
end
|
|
|
|
|
2017-09-06 17:06:03 +02:00
|
|
|
def messagerie
|
|
|
|
@avis = avis
|
|
|
|
@dossier = avis.dossier
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_commentaire
|
|
|
|
Commentaire.create(commentaire_params.merge(email: current_gestionnaire.email, dossier: avis.dossier))
|
|
|
|
redirect_to messagerie_avis_path(avis)
|
|
|
|
end
|
|
|
|
|
2017-09-20 10:52:48 +02:00
|
|
|
def create_avis
|
|
|
|
confidentiel = avis.confidentiel || params[:avis][:confidentiel]
|
|
|
|
Avis.create(create_avis_params.merge(claimant: current_gestionnaire, dossier: avis.dossier, confidentiel: confidentiel))
|
|
|
|
redirect_to instruction_avis_path(avis)
|
|
|
|
end
|
|
|
|
|
2017-09-06 11:26:32 +02:00
|
|
|
private
|
|
|
|
|
|
|
|
def avis
|
2017-09-06 17:06:03 +02:00
|
|
|
current_gestionnaire.avis.includes(dossier: [:avis, :commentaires]).find(params[:id])
|
2017-09-06 11:26:32 +02:00
|
|
|
end
|
2017-09-06 16:14:03 +02:00
|
|
|
|
|
|
|
def avis_params
|
|
|
|
params.require(:avis).permit(:answer)
|
|
|
|
end
|
2017-09-06 17:06:03 +02:00
|
|
|
|
|
|
|
def commentaire_params
|
|
|
|
params.require(:commentaire).permit(:body)
|
|
|
|
end
|
2017-09-20 10:52:48 +02:00
|
|
|
|
|
|
|
def create_avis_params
|
|
|
|
params.require(:avis).permit(:email, :introduction)
|
|
|
|
end
|
2017-09-06 11:21:29 +02:00
|
|
|
end
|
|
|
|
end
|