diff --git a/app/controllers/manager/procedures_controller.rb b/app/controllers/manager/procedures_controller.rb index d5bef5228..b3241429f 100644 --- a/app/controllers/manager/procedures_controller.rb +++ b/app/controllers/manager/procedures_controller.rb @@ -1,14 +1,12 @@ module Manager class ProceduresController < Manager::ApplicationController def whitelist - procedure = Procedure.find(params[:id]) procedure.whitelist! flash[:notice] = "Démarche whitelistée." redirect_to manager_procedure_path(procedure) end def draft - procedure = Procedure.find(params[:id]) if procedure.dossiers.empty? procedure.draft! flash[:notice] = "La démarche a bien été passée en brouillon." @@ -19,14 +17,12 @@ module Manager end def hide - procedure = Procedure.find(params[:id]) procedure.hide! flash[:notice] = "La démarche a bien été supprimée, en cas d'erreur contactez un développeur." redirect_to manager_procedures_path end def add_administrateur - procedure = Procedure.find(params[:id]) administrateur = Administrateur.find_by(email: params[:email]) if administrateur procedure.administrateurs << administrateur @@ -36,5 +32,28 @@ module Manager end redirect_to manager_procedure_path(procedure) end + + def change_piece_justificative_template + if type_de_champ.update(type_de_champ_params) + flash[:notice] = "Le modèle est mis à jour." + else + flash[:alert] = type_de_champ.errors.full_messages.join(', ') + end + redirect_to manager_procedure_path(procedure) + end + + private + + def procedure + Procedure.find(params[:id]) + end + + def type_de_champ + TypeDeChamp.find(params[:type_de_champ][:id]) + end + + def type_de_champ_params + params.require(:type_de_champ).permit(:piece_justificative_template) + end end end diff --git a/app/views/fields/types_de_champ_collection_field/_show.html.haml b/app/views/fields/types_de_champ_collection_field/_show.html.haml index 86b298e54..f70d88c66 100644 --- a/app/views/fields/types_de_champ_collection_field/_show.html.haml +++ b/app/views/fields/types_de_champ_collection_field/_show.html.haml @@ -5,6 +5,7 @@ %td.cell-label Libelle %td.cell-label Type de champ %td.cell-label Rempli + %td.cell-label Modifier le modèle %tbody - field.data.order(:order_place).each do |f| %tr @@ -20,5 +21,14 @@ vide - else rempli + + %td.cell-data + - if f.type_champ == 'piece_justificative' + = form_for f, + url: change_piece_justificative_template_manager_procedure_path, + method: :post do |form| + = form.hidden_field :id + = form.file_field :piece_justificative_template + = form.submit 'modifier' - else Aucun diff --git a/config/routes.rb b/config/routes.rb index 20cd28d8a..33493af6c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,6 +11,7 @@ Rails.application.routes.draw do post 'draft', on: :member post 'hide', on: :member post 'add_administrateur', on: :member + post 'change_piece_justificative_template', on: :member end resources :dossiers, only: [:index, :show] do