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

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

  before_action :admin_space
  
  def admin_space
    @admin_space = "stocks"
  end
  
  def index
    @p_origines = POrigine.all

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

  def show
    @p_origine = POrigine.find(params[:id])

  end

  def new
    @p_origine = POrigine.new
  
  end

  def edit
    @p_origine = POrigine.find(params[:id])
    
  end

  def create
    @p_origine = POrigine.new(params.require(:p_origine).permit!)

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

  end


  def update
    @p_origine = POrigine.find(params[:id])


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


  def destroy
    @p_origine = POrigine.find(params[:id])
    @p_origine.destroy
    
  end
end
