2016-02-05 17:40:58 +01:00
|
|
|
class Admin::GestionnairesController < AdminController
|
|
|
|
include SmartListing::Helper::ControllerExtensions
|
|
|
|
helper SmartListing::Helper
|
|
|
|
|
|
|
|
def index
|
|
|
|
@gestionnaires = smart_listing_create :gestionnaires,
|
|
|
|
current_administrateur.gestionnaires,
|
|
|
|
partial: "admin/gestionnaires/list",
|
|
|
|
array: true
|
|
|
|
@gestionnaire ||= Gestionnaire.new
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def create
|
2016-02-19 14:12:06 +01:00
|
|
|
@gestionnaire = Gestionnaire.create(create_gestionnaire_params)
|
2016-02-05 17:40:58 +01:00
|
|
|
|
2016-02-09 11:00:13 +01:00
|
|
|
if @gestionnaire.errors.messages.empty?
|
|
|
|
flash.notice = 'Gestionnaire ajouté'
|
2016-02-19 14:12:06 +01:00
|
|
|
GestionnaireMailer.new_gestionnaire(@gestionnaire.email, @gestionnaire.password).deliver_now!
|
2016-02-05 17:40:58 +01:00
|
|
|
else
|
|
|
|
flash.alert = @gestionnaire.errors.full_messages.join('<br />').html_safe
|
|
|
|
end
|
|
|
|
|
|
|
|
redirect_to admin_gestionnaires_path
|
|
|
|
end
|
|
|
|
|
2016-02-09 12:23:49 +01:00
|
|
|
|
|
|
|
def destroy
|
|
|
|
Gestionnaire.find(params[:id]).destroy
|
|
|
|
redirect_to admin_gestionnaires_path
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2016-02-09 11:00:13 +01:00
|
|
|
def create_gestionnaire_params
|
2016-02-05 17:40:58 +01:00
|
|
|
params.require(:gestionnaire).permit(:email)
|
|
|
|
.merge(administrateur_id: current_administrateur.id)
|
|
|
|
.merge(password: SecureRandom.hex(5))
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|