demarches-normaliennes/app/controllers/users/description_controller.rb

69 lines
1.9 KiB
Ruby
Raw Normal View History

class Users::DescriptionController < UsersController
2015-08-10 11:05:06 +02:00
def show
@dossier = current_user_dossier
2015-08-10 11:05:06 +02:00
@dossier = @dossier.decorate
@procedure = @dossier.procedure
@champs = @dossier.ordered_champs
2015-08-18 10:43:36 +02:00
rescue ActiveRecord::RecordNotFound
flash.alert = t('errors.messages.dossier_not_found')
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
@dossier = current_user_dossier
unless @dossier.update_attributes(create_params)
2015-08-21 11:37:13 +02:00
@dossier = @dossier.decorate
@procedure = @dossier.procedure
2015-08-21 11:37:13 +02:00
flash.now.alert = @dossier.errors.full_messages.join('<br />').html_safe
return render 'show'
end
2015-08-20 16:37:03 +02:00
unless params[:cerfa_pdf].nil?
2015-08-20 15:15:20 +02:00
cerfa = @dossier.cerfa
cerfa.content = params[:cerfa_pdf]
cerfa.save
end
2015-08-10 11:05:06 +02:00
unless params[:champs].nil?
@dossier.champs.each do |champ|
champ.value = params[:champs]["'#{champ.id}'"]
champ.save
end
end
@dossier.pieces_justificatives.each do |piece_justificative|
unless params["piece_justificative_#{piece_justificative.type}"].nil?
piece_justificative.content = params["piece_justificative_#{piece_justificative.type}"]
piece_justificative.save
end
end
2015-08-10 11:05:06 +02:00
if !@dossier.draft?
commentaire = Commentaire.create
commentaire.email = 'Modification détails'
commentaire.body = 'Les informations détaillées de la demande ont été modifiées. Merci de le prendre en compte.'
commentaire.dossier = @dossier
commentaire.save
else
@dossier.initiated!
end
2015-08-10 11:05:06 +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
private
def create_params
params.permit(:nom_projet, :description)
end
2015-08-10 11:05:06 +02:00
end