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

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

  before_action :admin_space
  
  def admin_space
    @admin_space = "default"
  end
  
  def index
    @p_serial_num_types = PSerialNumType.all

    if params[:search][:name]
      @p_serial_num_types = @p_serial_num_types.where("id = ?","#{params[:search][:name]}%")
    end


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

  def show
    @p_serial_num_type = PSerialNumType.find(params[:id])

  end

  def new
    @p_serial_num_type = PSerialNumType.new
  
  end

  def edit
    @p_serial_num_type = PSerialNumType.find(params[:id])
    
  end

  def create
    @p_serial_num_type = PSerialNumType.new(params.require(:p_serial_num_type).permit!)

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

  end


  def update
    @p_serial_num_type = PSerialNumType.find(params[:id])


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


  def destroy
    @p_serial_num_type = PSerialNumType.find(params[:id])
    @p_serial_num_type.destroy
    
  end
end
