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

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

  before_action :admin_space
  
  def admin_space
    @admin_space = "default"
  end
  
  def index
    @mail_type_cats = MailTypeCat.all

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

  def show
    @mail_type_cat = MailTypeCat.find(params[:id])

  end

  def new
    @mail_type_cat = MailTypeCat.new
  
  end

  def edit
    @mail_type_cat = MailTypeCat.find(params[:id])
    
  end

  def create
    @mail_type_cat = MailTypeCat.new(params.require(:mail_type_cat).permit!)

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

  end


  def update
    @mail_type_cat = MailTypeCat.find(params[:id])


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


  def destroy
    @mail_type_cat = MailTypeCat.find(params[:id])
    @mail_type_cat.destroy
    
  end
end
