111 lines
2.3 KiB
Ruby
111 lines
2.3 KiB
Ruby
# -*- encoding : utf-8 -*-
|
|
class Admin::AdminsController < ApplicationController
|
|
before_filter :authenticate_admin!
|
|
layout "admin"
|
|
|
|
##navigation :admins
|
|
|
|
|
|
def index
|
|
|
|
|
|
@breadcrumb = ["liste des administrateurs"]
|
|
|
|
@order = magick_order("email", "DESC")
|
|
|
|
@admins = Admin.order(@order).page(magick_page()).per(magick_per_page())
|
|
|
|
if @admins.num_pages.to_i < magick_page().to_i
|
|
params[:page] = @admins.num_pages
|
|
@admins = Admin.order(@order).page(magick_page()).per(magick_per_page())
|
|
end
|
|
|
|
end
|
|
|
|
def show
|
|
@admin = Admin.find(params[:id])
|
|
|
|
respond_to do |format|
|
|
format.html
|
|
end
|
|
end
|
|
|
|
|
|
def new
|
|
@breadcrumb = [["liste des administrateurs", admin_admins_path],"Ajouter un administrateur"]
|
|
@admin = Admin.new
|
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
end
|
|
end
|
|
|
|
def edit
|
|
@breadcrumb = [["liste des administrateurs", admin_admins_path],"Modifier un administrateur"]
|
|
@admin = Admin.find(params[:id])
|
|
end
|
|
|
|
|
|
def create
|
|
@admin = Admin.new(params[:admin])
|
|
|
|
respond_to do |format|
|
|
if @admin.save
|
|
flash[:notice] = "L'administrateur "+@admin.email.to_s+" à été ajouté avec succès."
|
|
format.html { redirect_to(admin_admins_path) }
|
|
format.js
|
|
else
|
|
format.html { render :action => "new" }
|
|
format.js { render :action => "new" }
|
|
end
|
|
end
|
|
end
|
|
|
|
def update
|
|
@breadcrumb = [["liste des administrateurs", admin_admins_path],"Modifier un administrateur"]
|
|
|
|
@admin = Admin.find(params[:id])
|
|
|
|
if params[:admin][:password] == ""
|
|
params[:admin].delete(:password)
|
|
params[:admin].delete(:password_confirmation)
|
|
end
|
|
|
|
respond_to do |format|
|
|
if @admin.update_attributes(params[:admin])
|
|
|
|
flash[:notice] = "L'administrateur "+@admin.email.to_s+" à été modifié avec succès."
|
|
format.html { redirect_to(admin_admins_path) }
|
|
format.js
|
|
else
|
|
format.html { render :action => "edit" }
|
|
format.js { render :action => "edit" }
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
def destroy
|
|
@admin = Admin.find(params[:id])
|
|
|
|
if @admin == current_admin
|
|
respond_to do |format|
|
|
format.html {
|
|
redirect_to(admin_admins_url, :alert => "Vous ne pouvez pas supprimer l'administrateur actuellement connecté.")
|
|
}
|
|
end
|
|
else
|
|
@admin.destroy
|
|
|
|
respond_to do |format|
|
|
format.html {
|
|
redirect_to(admin_admins_url, :notice => "L'utilisateur "+@admin.email.to_s+" à bien été supprimé.")
|
|
}
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
end
|