2015-11-16 16:16:08 +01:00
|
|
|
class Admin::ProceduresController < AdminController
|
2015-10-26 15:54:20 +01:00
|
|
|
|
|
|
|
def index
|
2015-11-27 10:39:05 +01:00
|
|
|
@procedures = current_administrateur.procedures.where(archived: false)
|
2015-12-03 15:38:17 +01:00
|
|
|
.paginate(:page => params[:page]).decorate
|
|
|
|
@page = 'active'
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
|
2015-11-27 16:23:02 +01:00
|
|
|
def archived
|
2015-12-03 15:38:17 +01:00
|
|
|
@procedures = current_administrateur.procedures.where(archived: true)
|
2015-12-04 16:17:35 +01:00
|
|
|
.paginate(:page => params[:page]).decorate
|
2015-12-03 15:38:17 +01:00
|
|
|
@page = 'archived'
|
2015-11-27 16:23:02 +01:00
|
|
|
end
|
|
|
|
|
2015-10-26 15:54:20 +01:00
|
|
|
def show
|
2015-12-04 16:17:35 +01:00
|
|
|
informations
|
2015-11-09 17:15:51 +01:00
|
|
|
|
2015-12-04 16:17:35 +01:00
|
|
|
@facade = AdminProceduresShowFacades.new @procedure
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
informations
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@procedure ||= Procedure.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2015-11-04 17:27:01 +01:00
|
|
|
@procedure = Procedure.new(create_procedure_params)
|
2015-10-26 15:54:20 +01:00
|
|
|
|
|
|
|
unless @procedure.save
|
|
|
|
flash.now.alert = @procedure.errors.full_messages.join('<br />').html_safe
|
|
|
|
return render 'new'
|
|
|
|
end
|
|
|
|
|
|
|
|
flash.notice = 'Procédure enregistrée'
|
2015-11-26 18:41:41 +01:00
|
|
|
redirect_to admin_procedure_types_de_champ_path(procedure_id: @procedure.id)
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2015-11-27 10:39:05 +01:00
|
|
|
@procedure = current_administrateur.procedures.find(params[:id])
|
2015-10-26 15:54:20 +01:00
|
|
|
|
2015-10-29 17:22:57 +01:00
|
|
|
unless @procedure.update_attributes(create_procedure_params)
|
2015-10-26 15:54:20 +01:00
|
|
|
flash.now.alert = @procedure.errors.full_messages.join('<br />').html_safe
|
2015-12-04 16:17:35 +01:00
|
|
|
return render 'edit'
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
flash.notice = 'Préocédure modifiée'
|
|
|
|
redirect_to admin_procedures_path
|
|
|
|
end
|
|
|
|
|
2015-11-26 18:41:41 +01:00
|
|
|
def archive
|
|
|
|
@procedure = current_administrateur.procedures.find(params[:procedure_id])
|
2015-11-27 17:13:06 +01:00
|
|
|
@procedure.update_attributes({archived: params[:archive]})
|
2015-11-26 18:41:41 +01:00
|
|
|
|
2015-11-27 17:13:06 +01:00
|
|
|
flash.notice = 'Procédure éditée'
|
2015-11-26 18:41:41 +01:00
|
|
|
redirect_to admin_procedures_path
|
|
|
|
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
flash.alert = 'Procédure inéxistante'
|
|
|
|
redirect_to admin_procedures_path
|
|
|
|
end
|
|
|
|
|
2015-10-26 15:54:20 +01:00
|
|
|
private
|
|
|
|
|
2015-10-29 17:22:57 +01:00
|
|
|
def create_procedure_params
|
2015-11-16 18:25:31 +01:00
|
|
|
params.require(:procedure).permit(:libelle, :description, :organisation, :direction, :lien_demarche, :use_api_carto).merge(administrateur_id: current_administrateur.id)
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
2015-12-04 16:17:35 +01:00
|
|
|
|
|
|
|
def informations
|
|
|
|
@procedure = current_administrateur.procedures.find(params[:id]).decorate
|
|
|
|
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
flash.alert = 'Procédure inéxistante'
|
|
|
|
redirect_to admin_procedures_path
|
|
|
|
end
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|