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

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

  before_action :admin_space
  
  def admin_space
    @admin_space = "default"
  end
  
  def index
    @m_odr_product_cats = MOdrProductCat.all
    
    @m_odr_product_cats = sort_by_sorting(@m_odr_product_cats, "created_at DESC")
    
    
    params[:search][:per_page] = params[:search][:per_page] || 50
		per_page = params[:search][:per_page]
		page = (params[:page] and params[:page] != "") ? params[:page] : 1 
		@m_odr_product_cats = @m_odr_product_cats.page(page).per(per_page)
    

  end

  def show
    @m_odr_product_cat = MOdrProductCat.find(params[:id])

  end

  def new
    @m_odr_product_cat = MOdrProductCat.new
  
  end

  def edit
    @m_odr_product_cat = MOdrProductCat.find(params[:id])
    
  end

  def create
    @m_odr_product_cat = MOdrProductCat.new(params.require(:m_odr_product_cat).permit!)

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

  end


  def update
    @m_odr_product_cat = MOdrProductCat.find(params[:id])


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


  def destroy
    @m_odr_product_cat = MOdrProductCat.find(params[:id])
    @m_odr_product_cat.destroy
    
  end
end
