demarches-normaliennes/app/controllers/new_administrateur/procedures_controller.rb

65 lines
1.6 KiB
Ruby
Raw Normal View History

2018-04-13 16:56:00 +02:00
module NewAdministrateur
class ProceduresController < AdministrateurController
2018-11-14 16:28:02 +01:00
before_action :retrieve_procedure, only: [:champs, :annotations, :update]
before_action :procedure_locked?, only: [:champs, :annotations, :update]
2018-11-14 16:24:34 +01:00
TYPE_DE_CHAMP_ATTRIBUTES_BASE = [
2018-11-14 16:24:34 +01:00
:_destroy,
:libelle,
:description,
:order_place,
:type_champ,
:id,
:mandatory,
:piece_justificative_template,
:quartiers_prioritaires,
:cadastres,
:parcelles_agricoles,
drop_down_list_attributes: [:value]
]
TYPE_DE_CHAMP_ATTRIBUTES = TYPE_DE_CHAMP_ATTRIBUTES_BASE.dup
TYPE_DE_CHAMP_ATTRIBUTES << {
types_de_champ_attributes: TYPE_DE_CHAMP_ATTRIBUTES_BASE
}
2018-04-13 16:56:00 +02:00
def apercu
@dossier = procedure_without_control.new_dossier
@tab = apercu_tab
2018-04-13 16:56:00 +02:00
end
2018-11-14 16:24:34 +01:00
def update
if @procedure.update(procedure_params)
2018-11-14 16:28:02 +01:00
flash.now.notice = if params[:procedure][:types_de_champ_attributes].present?
'Formulaire mis à jour.'
2018-11-14 16:28:02 +01:00
elsif params[:procedure][:types_de_champ_private_attributes].present?
'Annotations privées mises à jour.'
2018-11-14 16:28:02 +01:00
else
'Démarche enregistrée.'
end
2018-11-14 16:24:34 +01:00
reset_procedure
else
flash.now.alert = @procedure.errors.full_messages
end
end
2018-04-13 16:56:00 +02:00
private
def apercu_tab
params[:tab] || 'dossier'
end
2018-04-13 16:56:00 +02:00
def procedure_without_control
Procedure.find(params[:id])
end
2018-11-14 16:24:34 +01:00
def procedure_params
params.required(:procedure).permit(
types_de_champ_attributes: TYPE_DE_CHAMP_ATTRIBUTES,
types_de_champ_private_attributes: TYPE_DE_CHAMP_ATTRIBUTES
)
end
2018-04-13 16:56:00 +02:00
end
end