2015-10-09 14:43:19 +02:00
|
|
|
class Users::DescriptionController < UsersController
|
2016-01-26 15:52:05 +01:00
|
|
|
before_action only: [:show] do
|
|
|
|
authorized_routes? self.class
|
|
|
|
end
|
2016-01-25 15:54:21 +01:00
|
|
|
|
2015-08-10 11:05:06 +02:00
|
|
|
def show
|
2016-03-15 17:17:56 +01:00
|
|
|
@dossier = current_user_dossier.decorate
|
2015-08-11 15:39:16 +02:00
|
|
|
|
2015-09-21 17:59:03 +02:00
|
|
|
@procedure = @dossier.procedure
|
2015-11-04 11:14:07 +01:00
|
|
|
@champs = @dossier.ordered_champs
|
2015-08-20 12:20:54 +02:00
|
|
|
|
2015-08-18 10:43:36 +02:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
2015-09-23 16:56:30 +02:00
|
|
|
flash.alert = t('errors.messages.dossier_not_found')
|
2015-10-09 17:33:33 +02:00
|
|
|
redirect_to url_for(root_path)
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def error
|
|
|
|
show
|
|
|
|
flash.now.alert = 'Un ou plusieurs attributs obligatoires sont manquants ou incorrects.'
|
|
|
|
render 'show'
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2015-10-09 17:33:33 +02:00
|
|
|
@dossier = current_user_dossier
|
2016-02-02 18:37:38 +01:00
|
|
|
@procedure = @dossier.procedure
|
2016-03-15 17:17:56 +01:00
|
|
|
@champs = @dossier.ordered_champs
|
|
|
|
|
2015-11-03 16:52:58 +01:00
|
|
|
unless @dossier.update_attributes(create_params)
|
2015-08-21 11:37:13 +02:00
|
|
|
@dossier = @dossier.decorate
|
|
|
|
|
|
|
|
flash.now.alert = @dossier.errors.full_messages.join('<br />').html_safe
|
|
|
|
return render 'show'
|
|
|
|
end
|
2016-02-04 14:08:35 +01:00
|
|
|
|
2016-02-02 18:37:38 +01:00
|
|
|
if @procedure.cerfa_flag?
|
|
|
|
unless params[:cerfa_pdf].nil?
|
2016-03-17 17:33:38 +01:00
|
|
|
cerfa = Cerfa.new(content: params[:cerfa_pdf], dossier: @dossier, user: current_user)
|
2016-02-18 15:46:59 +01:00
|
|
|
unless cerfa.save
|
|
|
|
flash.now.alert = cerfa.errors.full_messages.join('<br />').html_safe
|
|
|
|
return render 'show'
|
|
|
|
end
|
2016-02-02 18:37:38 +01:00
|
|
|
end
|
2015-08-11 15:39:16 +02:00
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2015-11-03 16:52:58 +01:00
|
|
|
unless params[:champs].nil?
|
|
|
|
@dossier.champs.each do |champ|
|
|
|
|
champ.value = params[:champs]["'#{champ.id}'"]
|
2016-03-15 17:17:56 +01:00
|
|
|
|
2016-06-22 11:25:41 +02:00
|
|
|
if champ.type_champ == 'datetime'
|
|
|
|
champ.value = params[:champs]["'#{champ.id}'"]+
|
|
|
|
' ' +
|
|
|
|
params[:time_hour]["'#{champ.id}'"] +
|
|
|
|
':' +
|
|
|
|
params[:time_minute]["'#{champ.id}'"]
|
|
|
|
end
|
|
|
|
|
2016-03-15 17:17:56 +01:00
|
|
|
if champ.mandatory? && (champ.value.nil? || champ.value.blank?)
|
|
|
|
flash.now.alert = "Le champ #{champ.libelle} doit être rempli."
|
|
|
|
return render 'show'
|
|
|
|
end
|
|
|
|
|
2015-11-03 16:52:58 +01:00
|
|
|
champ.save
|
|
|
|
end
|
2015-11-03 16:16:39 +01:00
|
|
|
end
|
|
|
|
|
2016-03-22 17:36:36 +01:00
|
|
|
unless (errors_upload = PiecesJustificativesService.upload!(@dossier, current_user, params)).empty?
|
2016-04-15 15:32:15 +02:00
|
|
|
flash.alert = errors_upload.html_safe
|
2016-03-22 17:36:36 +01:00
|
|
|
return render 'show'
|
2015-08-11 15:39:16 +02:00
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2016-01-27 15:48:27 +01:00
|
|
|
if @dossier.draft?
|
2015-11-02 15:31:15 +01:00
|
|
|
@dossier.initiated!
|
2015-09-28 10:32:41 +02:00
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2015-09-28 10:32:41 +02:00
|
|
|
flash.notice = 'Félicitation, votre demande a bien été enregistrée.'
|
|
|
|
redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: @dossier.id)
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
|
2016-03-22 17:36:36 +01:00
|
|
|
def pieces_justificatives
|
|
|
|
invite = current_user.invite? params[:dossier_id]
|
|
|
|
|
|
|
|
@dossier ||= Dossier.find(params[:dossier_id]) if invite
|
|
|
|
@dossier ||= current_user_dossier
|
|
|
|
|
|
|
|
if !((errors_upload = PiecesJustificativesService.upload!(@dossier, current_user, params)).empty?)
|
|
|
|
flash.alert = errors_upload.html_safe
|
|
|
|
else
|
|
|
|
flash.notice = 'Nouveaux fichiers envoyés'
|
|
|
|
end
|
|
|
|
|
|
|
|
return redirect_to users_dossiers_invite_path(id: current_user.invites.find_by_dossier_id(@dossier.id).id) if invite
|
|
|
|
|
|
|
|
redirect_to users_dossier_recapitulatif_path
|
|
|
|
end
|
|
|
|
|
2016-01-26 15:52:05 +01:00
|
|
|
def self.route_authorization
|
|
|
|
{
|
|
|
|
states: [:draft, :initiated, :replied, :updated]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2015-08-10 11:05:06 +02:00
|
|
|
private
|
|
|
|
|
2015-08-11 15:39:16 +02:00
|
|
|
def create_params
|
2016-07-19 16:10:50 +02:00
|
|
|
params.permit()
|
2015-08-11 15:39:16 +02:00
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|