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

class Admin::ParticularsController < ApplicationController
  layout "admin"
  before_action :auth_admin
  
  before_action :admin_space
  
  def admin_space
    @admin_space = "ventes"
  end
  


  def index
    @particulars = Particular.order(:name).all

   
  end

  def show
    @particular = Particular.find(params[:id])

  end

  def new
    
    
		@particular = Particular.new(:open_range_ids => OpenRange.all.ids)
    if params[:p_customer_id]
      @particular.owner = PCustomer.find(params[:p_customer_id])
    end
  end

 

  def edit
  
    
    @particular = Particular.find(params[:id])
  end

  def create
    @particular = Particular.new(params.require(:particular).permit!)


    if @particular.save
      if @particular.owner and @particular.owner_type == "PCustomer"
        @p_customer = @particular.owner
      end
    else
      render action: "new"
 
    end

  end


  def update
    @particular = Particular.find(params[:id])


    if @particular.update_attributes(params.require(:particular).permit!)

    else
     render action: "edit" 
      
    end
      
  end


  def destroy
    @particular = Particular.find(params[:id])
    @particular.destroy
    
    
  end
end
