demarches-normaliennes/app/controllers/admin/pieces_justificatives_controller.rb

51 lines
1.3 KiB
Ruby
Raw Normal View History

class Admin::PiecesJustificativesController < AdminController
before_action :retrieve_procedure
before_action :procedure_locked?
before_action :reset_procedure, only: [:update, :destroy, :move_up, :move_down]
def show
end
def update
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
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
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
end
private
def update_params
params
.require(:procedure)
.permit(types_de_piece_justificative_attributes: [:libelle, :description, :id, :order_place, :mandatory, :lien_demarche])
end
end