2018-04-13 16:56:00 +02:00
|
|
|
module NewAdministrateur
|
|
|
|
class ProceduresController < AdministrateurController
|
2019-09-24 16:38:58 +02:00
|
|
|
before_action :retrieve_procedure, only: [:champs, :annotations, :edit, :monavis, :update_monavis]
|
2019-02-06 18:19:27 +01:00
|
|
|
before_action :procedure_locked?, only: [:champs, :annotations]
|
2019-01-17 15:15:46 +01:00
|
|
|
|
2018-04-13 16:56:00 +02:00
|
|
|
def apercu
|
|
|
|
@dossier = procedure_without_control.new_dossier
|
2018-04-13 17:29:34 +02:00
|
|
|
@tab = apercu_tab
|
2018-04-13 16:56:00 +02:00
|
|
|
end
|
|
|
|
|
2019-09-24 16:38:58 +02:00
|
|
|
def new
|
|
|
|
@procedure ||= Procedure.new(for_individual: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@procedure = Procedure.new(procedure_params.merge(administrateurs: [current_administrateur]))
|
|
|
|
|
|
|
|
if !@procedure.save
|
|
|
|
flash.now.alert = @procedure.errors.full_messages
|
|
|
|
render 'new'
|
|
|
|
else
|
|
|
|
flash.notice = 'Démarche enregistrée.'
|
|
|
|
current_administrateur.instructeur.assign_to_procedure(@procedure)
|
|
|
|
|
|
|
|
redirect_to champs_procedure_path(@procedure)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@procedure = current_administrateur.procedures.find(params[:id])
|
|
|
|
|
|
|
|
if !@procedure.update(procedure_params)
|
|
|
|
flash.now.alert = @procedure.errors.full_messages
|
|
|
|
render 'edit'
|
|
|
|
elsif @procedure.brouillon?
|
|
|
|
reset_procedure
|
|
|
|
flash.notice = 'Démarche modifiée. Tous les dossiers de cette démarche ont été supprimés.'
|
|
|
|
redirect_to edit_admin_procedure_path(id: @procedure.id)
|
|
|
|
else
|
|
|
|
flash.notice = 'Démarche modifiée.'
|
|
|
|
redirect_to edit_admin_procedure_path(id: @procedure.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def monavis
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_monavis
|
|
|
|
if !@procedure.update(procedure_params)
|
|
|
|
flash.now.alert = @procedure.errors.full_messages
|
|
|
|
else
|
|
|
|
flash.notice = 'le champ MonAvis a bien été mis à jour'
|
|
|
|
end
|
|
|
|
render 'monavis'
|
|
|
|
end
|
|
|
|
|
2018-04-13 16:56:00 +02:00
|
|
|
private
|
|
|
|
|
2018-04-13 17:29:34 +02:00
|
|
|
def apercu_tab
|
|
|
|
params[:tab] || 'dossier'
|
|
|
|
end
|
|
|
|
|
2018-04-13 16:56:00 +02:00
|
|
|
def procedure_without_control
|
|
|
|
Procedure.find(params[:id])
|
|
|
|
end
|
2019-09-24 16:38:58 +02:00
|
|
|
|
|
|
|
def procedure_params
|
|
|
|
editable_params = [:libelle, :description, :organisation, :direction, :lien_site_web, :cadre_juridique, :deliberation, :notice, :web_hook_url, :euro_flag, :logo, :auto_archive_on, :monavis_embed]
|
|
|
|
permited_params = if @procedure&.locked?
|
|
|
|
params.require(:procedure).permit(*editable_params)
|
|
|
|
else
|
|
|
|
params.require(:procedure).permit(*editable_params, :duree_conservation_dossiers_dans_ds, :duree_conservation_dossiers_hors_ds, :for_individual, :path)
|
|
|
|
end
|
|
|
|
permited_params
|
|
|
|
end
|
2018-04-13 16:56:00 +02:00
|
|
|
end
|
|
|
|
end
|