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

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

  before_action :admin_space
  
  def admin_space
    @admin_space = "default"
  end
  
  def index
    @order_hists = OrderHist.all

    @order_hists = sort_by_sorting(@order_hists, "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 
        @order_hists = @order_hists.page(page).per(per_page)
      
      }
    end
  end

  def show
    @order_hist = OrderHist.find(params[:id])

  end

  def new
    @order_hist = OrderHist.new
  
  end

  def edit
    @order_hist = OrderHist.find(params[:id])
    
  end

  def create
    @order_hist = OrderHist.new(params.require(:order_hist).permit!)

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

  end


  def update
    @order_hist = OrderHist.find(params[:id])


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


  def destroy
    @order_hist = OrderHist.find(params[:id])
    @order_hist.destroy
    
  end
end
