2019-08-06 11:46:55 +02:00
|
|
|
class Admin::AssignsController < AdminController
|
2016-05-24 16:39:39 +02:00
|
|
|
include SmartListing::Helper::ControllerExtensions
|
|
|
|
helper SmartListing::Helper
|
|
|
|
|
2016-05-20 15:36:38 +02:00
|
|
|
before_action :retrieve_procedure
|
|
|
|
|
2018-02-19 11:35:45 +01:00
|
|
|
ASSIGN = 'assign'
|
|
|
|
NOT_ASSIGN = 'not_assign'
|
|
|
|
|
2016-05-20 15:36:38 +02:00
|
|
|
def show
|
2019-08-21 14:09:56 +02:00
|
|
|
assign_scope = @procedure.defaut_groupe_instructeur.instructeurs
|
2018-01-30 14:43:56 +01:00
|
|
|
|
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,
|
2019-08-06 11:46:55 +02:00
|
|
|
partial: "admin/assigns/list_assign",
|
2017-06-12 13:49:51 +02:00
|
|
|
array: true
|
2016-05-24 16:39:39 +02:00
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
not_assign_scope = current_administrateur.instructeurs.where.not(id: assign_scope.ids)
|
2018-10-01 13:24:37 +02:00
|
|
|
|
2019-11-06 12:05:41 +01:00
|
|
|
if params[:filter].present?
|
|
|
|
filter = params[:filter].downcase.strip
|
|
|
|
not_assign_scope = not_assign_scope.where('users.email LIKE ?', "%#{filter}%")
|
2018-10-01 13:24:37 +02:00
|
|
|
end
|
2016-05-24 16:39:39 +02:00
|
|
|
|
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,
|
2019-08-06 11:46:55 +02:00
|
|
|
partial: "admin/assigns/list_not_assign",
|
2017-06-12 13:49:51 +02:00
|
|
|
array: true
|
2016-05-20 15:36:38 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2019-08-06 11:02:54 +02:00
|
|
|
instructeur = Instructeur.find(params[:instructeur_id])
|
2016-09-08 16:21:54 +02:00
|
|
|
procedure = Procedure.find(params[:procedure_id])
|
|
|
|
to = params[:to]
|
|
|
|
|
2018-02-19 11:20:57 +01:00
|
|
|
case to
|
2018-02-19 11:35:45 +01:00
|
|
|
when ASSIGN
|
2019-08-06 11:02:54 +02:00
|
|
|
if instructeur.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
|
2019-08-06 11:02:54 +02:00
|
|
|
if instructeur.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
|
2018-02-19 11:20:57 +01:00
|
|
|
end
|
2016-05-20 15:36:38 +02:00
|
|
|
|
2019-08-06 11:46:55 +02:00
|
|
|
redirect_to admin_procedure_assigns_path, procedure_id: params[:procedure_id]
|
2016-05-20 15:36:38 +02:00
|
|
|
end
|
2017-04-04 15:27:04 +02:00
|
|
|
end
|