# -*- encoding : utf-8 -*-
  class Admin::DataFilesController < ApplicationController
    before_action :auth_admin

  
  layout "admin"

  def index
    params[:file_folder_id] = params[:file_folder_id] || 1

    @file_folder = FileFolder.find(params[:file_folder_id])
    @file_folders = FileFolder.all.order(:name)
    @data_files = DataFile.where(:file_folder_id => @file_folder.id).order("created_at DESC")
    @data_file = DataFile.new(:file_folder_id => @file_folder.id)
    if request.xhr?
    render :layout => false
    end
  end

  def new
  end

  def edit
  end

  def create
    @data_file_create = true
    @data_file = DataFile.new(:name => params[:files].original_filename, :file_folder_id => params[:file_folder_id], :file =>params[:files])
    
    if @data_file.save

    else

    end


  end
  
  
  def edit
    @data_file = DataFile.find(params[:id])
  end

  def update
      @data_file = DataFile.find(params[:id])
      if @data_file.update_attributes(params.require(:data_file).permit!)
    else
  
    end
  end
  

  def update
    @data_file = DataFile.find(params[:id])
    if @data_file.update_attributes(params.require(:data_file).permit!)

    else
  
    end
  end

  def destroy
    @data_file = DataFile.find(params[:id])
    @data_file.destroy

    flash[:notice] = "Le fichier à bien été supprimée."
  end

  def show
    @data_file = DataFile.find(params[:id])

  end

end
