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

52 lines
1.5 KiB
Ruby
Raw Normal View History

2018-08-29 22:11:38 +02:00
class Admin::InstructeursController < AdminController
include SmartListing::Helper::ControllerExtensions
helper SmartListing::Helper
before_action :retrieve_procedure
2018-02-19 11:35:45 +01:00
ASSIGN = 'assign'
NOT_ASSIGN = 'not_assign'
def show
assign_scope = @procedure.gestionnaires
2018-08-29 22:11:38 +02:00
@instructeurs_assign = smart_listing_create :instructeurs_assign,
2017-06-12 13:49:51 +02:00
assign_scope,
2018-08-29 22:11:38 +02:00
partial: "admin/instructeurs/list_assign",
2017-06-12 13:49:51 +02:00
array: true
not_assign_scope = current_administrateur.gestionnaires.where.not(id: assign_scope.ids)
2017-07-20 14:51:57 +02:00
not_assign_scope = not_assign_scope.where("email LIKE ?", "%#{params[:filter]}%") if params[:filter]
2018-08-29 22:11:38 +02:00
@instructeurs_not_assign = smart_listing_create :instructeurs_not_assign,
2017-06-12 13:49:51 +02:00
not_assign_scope,
2018-08-29 22:11:38 +02:00
partial: "admin/instructeurs/list_not_assign",
2017-06-12 13:49:51 +02:00
array: true
@gestionnaire ||= Gestionnaire.new
end
def update
2018-08-29 22:11:38 +02:00
gestionnaire = Gestionnaire.find(params[:instructeur_id])
procedure = Procedure.find(params[:procedure_id])
to = params[:to]
case to
2018-02-19 11:35:45 +01:00
when ASSIGN
2018-02-20 11:24:32 +01:00
if gestionnaire.assign_to_procedure(procedure)
2018-08-29 22:11:38 +02:00
flash.notice = "L'instructeur a bien été affecté"
2018-02-20 11:24:32 +01:00
else
2018-08-29 22:11:38 +02:00
flash.alert = "L'instructeur a déjà été affecté"
2018-02-20 11:24:32 +01:00
end
2018-02-19 11:35:45 +01:00
when NOT_ASSIGN
2018-02-20 11:24:32 +01:00
if gestionnaire.remove_from_procedure(procedure)
2018-08-29 22:11:38 +02:00
flash.notice = "L'instructeur a bien été désaffecté"
2018-02-20 11:24:32 +01:00
else
2018-08-29 22:11:38 +02:00
flash.alert = "L'instructeur a déjà été désaffecté"
2018-02-20 11:24:32 +01:00
end
end
2018-08-29 22:11:38 +02:00
redirect_to admin_procedure_instructeurs_path, procedure_id: params[:procedure_id]
end
2017-04-04 15:27:04 +02:00
end