2015-11-16 16:16:08 +01:00
|
|
|
class Admin::PiecesJustificativesController < AdminController
|
2015-11-20 13:54:08 +01:00
|
|
|
before_action :retrieve_procedure
|
2015-12-24 15:57:03 +01:00
|
|
|
before_action :procedure_locked?
|
2018-08-13 17:49:15 +02:00
|
|
|
before_action :reset_procedure, only: [:update, :destroy, :move_up, :move_down]
|
2015-11-16 16:16:08 +01:00
|
|
|
|
2015-11-20 13:54:08 +01:00
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2018-03-02 16:27:03 +01:00
|
|
|
if @procedure.update(update_params)
|
2017-01-31 15:13:06 +01:00
|
|
|
flash.now.notice = 'Modifications sauvegardées'
|
|
|
|
else
|
|
|
|
flash.now.notice = 'Une erreur est survenue'
|
|
|
|
end
|
2015-11-20 13:54:08 +01:00
|
|
|
render 'show', format: :js
|
|
|
|
end
|
|
|
|
|
2015-11-20 15:12:47 +01:00
|
|
|
def destroy
|
|
|
|
@procedure.types_de_piece_justificative.find(params[:id]).destroy
|
|
|
|
|
|
|
|
render 'show', format: :js
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
render json: { message: 'Type de piece justificative not found' }, status: 404
|
|
|
|
end
|
|
|
|
|
2016-06-08 16:45:18 +02:00
|
|
|
def move_up
|
|
|
|
index = params[:index].to_i - 1
|
|
|
|
if @procedure.switch_types_de_piece_justificative index
|
|
|
|
render 'show', format: :js
|
|
|
|
else
|
|
|
|
render json: {}, status: 400
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def move_down
|
|
|
|
if @procedure.switch_types_de_piece_justificative params[:index].to_i
|
|
|
|
render 'show', format: :js
|
|
|
|
else
|
|
|
|
render json: {}, status: 400
|
|
|
|
end
|
2015-11-20 13:54:08 +01:00
|
|
|
end
|
2018-08-13 17:49:15 +02:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def update_params
|
|
|
|
params
|
|
|
|
.require(:procedure)
|
|
|
|
.permit(types_de_piece_justificative_attributes: [:libelle, :description, :id, :order_place, :mandatory, :lien_demarche])
|
|
|
|
end
|
2017-01-18 17:13:54 +01:00
|
|
|
end
|