.wrapper
  =render :partial => "public/p_products/shop_top"



  
  :scss 
    .products_search{
      background:#efad1b;
      padding:20px 0;
    }
  .products_search
    .container
      -PProduct.where(:s_brand_id => nil).each do |p_product|

        -p_product.code


        - ref_p_product = PProduct.where("s_brand_id is not NULL").where("code LIKE ?", "%"+p_product.code.sub("6KG", "").sub("RSTO", "").sub("RST", "").to_s+"%").first

        -if ref_p_product




          -if p_product_ref = ref_p_product.p_product_refs.first


            -pprf = p_product.p_product_refs.first

            - pprf.uv = p_product_ref.uv if pprf and p_product_ref.uv
            - pprf.save

          - p_product.uv = ref_p_product.uv if ref_p_product.uv
          - p_product.s_brand_id = ref_p_product.s_brand_id if ref_p_product.s_brand_id
          - p_product.country = ref_p_product.country if ref_p_product.country
          - p_product.sub_country = ref_p_product.sub_country if ref_p_product.sub_country
          - p_product.domaine = ref_p_product.domaine if ref_p_product.domaine

          - p_product.save


      .qi_search_row

        =form_tag "", :method => "get",  :onsubmit => "" do

          =hidden_field_tag :column, params[:column]
          =hidden_field_tag :direction, params[:direction]

          %table
            %tr
       
              %td{:style => "width:150px;"}=text_field_tag :code, params[:code],:class => "form-control", :placeholder => "Code produit"

              %td{:style => "width:400px;"}=text_field_tag :name, params[:name],:class => "form-control", :placeholder => "Nom produit"



              %td
                Catégorie :
                =select_tag "search[p_product_cat_id]", options_for_select([["",""]]+PProductCat.where(commercial_show: true).order(:name).all.map{|a| [a.name, a.id]}, params[:search][:p_product_cat_id])

             
              %td
                Marque :
                =select_tag "search[s_brand_id]", options_for_select([["",""]]+SBrand.order(:name).all.map{|a| [a.name, a.id]}, params[:search][:s_brand_id])

          %center{:style => "margin-top:20px;"}
            =link_to ic(:search)+" Rechercher", "#", :class => "btn btn-primary", :onclick => "$(this).closest('form').submit();$(this).html('...');return false;"

          

  .container
    .display_select{:style => "float:right"}
      .btn{:class => "display-products", :data => {"display-product" => "true"}}
        =ic :"th-list"
        Afficher en liste
      
      .btn{:class => "display-products", :data => {"display-product" => "false"}}
        =ic :"th-large"
        Afficher en mosaique
  
    .clear
    #product_index.products_index
      =render(:partial => "public/p_products/index")

    .clear


:coffeescript
  $(".display-products").on "click", (event) ->
    btn = $(event.target)

    displayProduct = btn.data("display-product")

    # alert(displayProduct)

    # debugger
    # console.log(displayProduct)
    if (displayProduct == true)
      # btn.data("display-product","false")
      displayProduct = "false"

    else
      # alert "TESTS"
      # btn.data("display-product","true")
      displayProduct = "true"
    
    data = {change_display_product_value: displayProduct}

    $.ajax({url:"/public/p_products.js", type: "GET", data: data});


