2015-11-16 16:16:08 +01:00
|
|
|
class Admin::ProceduresController < AdminController
|
2016-01-07 15:29:29 +01:00
|
|
|
include SmartListing::Helper::ControllerExtensions
|
|
|
|
helper SmartListing::Helper
|
2015-10-26 15:54:20 +01:00
|
|
|
|
2015-12-24 15:57:03 +01:00
|
|
|
before_action :retrieve_procedure, only: [:show, :edit]
|
|
|
|
before_action :procedure_locked?, only: [:edit]
|
2015-12-21 12:02:53 +01:00
|
|
|
|
2015-10-26 15:54:20 +01:00
|
|
|
def index
|
2016-01-07 15:29:29 +01:00
|
|
|
@procedures = smart_listing_create :procedures,
|
|
|
|
current_administrateur.procedures.where(archived: false),
|
|
|
|
partial: "admin/procedures/list",
|
|
|
|
array: true
|
|
|
|
|
2015-12-24 15:22:07 +01:00
|
|
|
active_class
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
|
2015-11-27 16:23:02 +01:00
|
|
|
def archived
|
2016-01-07 15:29:29 +01:00
|
|
|
@procedures = smart_listing_create :procedures,
|
|
|
|
current_administrateur.procedures.where(archived: true),
|
|
|
|
partial: "admin/procedures/list",
|
|
|
|
array: true
|
|
|
|
|
2015-12-24 15:22:07 +01:00
|
|
|
archived_class
|
2016-01-07 15:29:29 +01:00
|
|
|
|
|
|
|
render 'index'
|
2015-11-27 16:23:02 +01:00
|
|
|
end
|
|
|
|
|
2015-10-26 15:54:20 +01:00
|
|
|
def show
|
2015-12-24 15:57:03 +01:00
|
|
|
@facade = AdminProceduresShowFacades.new @procedure.decorate
|
2015-12-04 16:17:35 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2016-01-07 15:29:29 +01:00
|
|
|
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@procedure ||= Procedure.new
|
2015-12-08 10:11:58 +01:00
|
|
|
@procedure.module_api_carto ||= ModuleAPICarto.new
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2015-11-04 17:27:01 +01:00
|
|
|
@procedure = Procedure.new(create_procedure_params)
|
2015-12-08 10:11:58 +01:00
|
|
|
@procedure.module_api_carto = ModuleAPICarto.new(create_module_api_carto_params) if @procedure.valid?
|
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
|
2015-12-10 17:13:39 +01:00
|
|
|
|
2015-10-26 15:54:20 +01:00
|
|
|
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-12-24 15:22:07 +01:00
|
|
|
def active_class
|
2016-01-19 17:19:38 +01:00
|
|
|
@active_class = 'active'
|
2015-12-24 15:22:07 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def archived_class
|
2016-01-19 17:19:38 +01:00
|
|
|
@archived_class = 'active'
|
2015-12-24 15:22:07 +01:00
|
|
|
end
|
|
|
|
|
2015-10-26 15:54:20 +01:00
|
|
|
private
|
|
|
|
|
2015-10-29 17:22:57 +01:00
|
|
|
def create_procedure_params
|
2015-12-10 17:13:39 +01:00
|
|
|
params.require(:procedure).permit(:libelle, :description, :organisation, :direction, :lien_demarche, :euro_flag, :logo, module_api_carto_attributes: [:id, :use_api_carto, :quartiers_prioritaires, :cadastre]).merge(administrateur_id: current_administrateur.id)
|
2015-12-08 10:11:58 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def create_module_api_carto_params
|
|
|
|
params.require(:procedure).require(:module_api_carto_attributes).permit(:id, :use_api_carto, :quartiers_prioritaires, :cadastre)
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
end
|