# -*- encoding : utf-8 -*-

class Admin::ImportCsvHeadersController < ApplicationController
  layout "admin"
  before_action :auth_admin

  before_action :admin_space
  
  def admin_space
    @admin_space = "default"
  end
  
  def index
    @import_csv_headers = ImportCsvHeader.order(:name).all

    @import_csv_headers = sort_by_sorting(@import_csv_headers, "id DESC")
    respond_to do |format|
      format.html{
      
        params[:search][:per_page] = params[:search][:per_page] || 100
        per_page = params[:search][:per_page]
        page = (params[:page] and params[:page] != "") ? params[:page] : 1 
        @import_csv_headers = @import_csv_headers.page(page).per(per_page)
      
      }
    end
  end

  def show
    @import_csv_header = ImportCsvHeader.find(params[:id])

  end

  def new
    @import_csv_header = ImportCsvHeader.new
  
  end

  def edit
    @import_csv_header = ImportCsvHeader.find(params[:id])
    
  end

  def create
    @import_csv_header = ImportCsvHeader.new(params.require(:import_csv_header).permit!)

    if @import_csv_header.save
      
    else
      render action: "new"
 
    end

  end


  def update
    @import_csv_header = ImportCsvHeader.find(params[:id])


    if @import_csv_header.update_attributes(params.require(:import_csv_header).permit!)
      
    else
     render action: "edit" 
      
    end
      
  end


  def destroy
    @import_csv_header = ImportCsvHeader.find(params[:id])
    @import_csv_header.destroy
    
  end
end
