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

64 lines
1.9 KiB
Ruby
Raw Normal View History

class Admin::AccompagnateursController < 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
# FIXME: remove this comment (no code to remove) when
# https://github.com/Sology/smart_listing/issues/134
# is fixed.
#
# No need to permit parameters for smart_listing, because
# there are no sortable columns
#
# END OF FIXME
@accompagnateurs_assign = smart_listing_create :accompagnateurs_assign,
2017-06-12 13:49:51 +02:00
assign_scope,
partial: "admin/accompagnateurs/list_assign",
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]
# FIXME: remove this comment (no code to remove) when
# https://github.com/Sology/smart_listing/issues/134
# is fixed.
#
# No need to permit parameters for smart_listing, because
# there are no sortable columns
#
# END OF FIXME
@accompagnateurs_not_assign = smart_listing_create :accompagnateurs_not_assign,
2017-06-12 13:49:51 +02:00
not_assign_scope,
partial: "admin/accompagnateurs/list_not_assign",
array: true
@gestionnaire ||= Gestionnaire.new
end
def update
gestionnaire = Gestionnaire.find(params[:accompagnateur_id])
procedure = Procedure.find(params[:procedure_id])
to = params[:to]
case to
2018-02-19 11:35:45 +01:00
when ASSIGN
gestionnaire.assign_to_procedure(procedure)
2018-02-19 11:22:20 +01:00
flash.notice = "L'accompagnateur a bien été affecté"
2018-02-19 11:35:45 +01:00
when NOT_ASSIGN
gestionnaire.remove_from_procedure(procedure)
2018-02-19 11:22:20 +01:00
flash.notice = "L'accompagnateur a bien été désaffecté"
end
redirect_to admin_procedure_accompagnateurs_path, procedure_id: params[:procedure_id]
end
2017-04-04 15:27:04 +02:00
end