# -*- encoding : utf-8 -*-
class Admin::FoldersController < ApplicationController
  	before_filter :authenticate_admin!
	load_and_authorize_resource
	
	layout "admin"

	navigation :folders


	def index
		@folders = Folder.all
	end

	def new
		current_navigation :new_folders
		@folder = Folder.new
	end
	
	def create
		current_navigation :new_folders
		
		@folder = Folder.new(params[:folder])
		
		if @folder.save
			@folders = Folder.all
			flash[:notice] = "Le dossier à bien été créé."
			
			respond_to do |format|
				format.html { redirect_to(admin_folders_path()) }
				format.js
			end
			
		else
			
			respond_to do |format|
				format.html { render :action => :new}
				format.js { render :action => :new}
			end
					
		end
	end


	def edit
		current_navigation :edit_folders
		
		@folder = Folder.find(params[:id])

	end

	def update
		current_navigation :edit_folders
		
		@folder = Folder.find(params[:id])
		
		if @folder.update_attributes(params[:folder])
			flash[:notice] = "Le dossier à bien été modifié."
			
			respond_to do |format|
				format.html { redirect_to(admin_folders_path()) }
				format.js
			end
			
		else
			respond_to do |format|
				format.html { render :action => :edit}
				format.js { render :action => :edit}
			end		
		end
	end


	def destroy
		@folder = Folder.find(params[:id])
		@folder.destroy
	
		flash[:notice] = "Le dossier à bien été supprimé."
	end
	
	def cible
		@folders = Folder.all
		
		render :layout => false
	end
end
