-form.object.element_label = "Avoir"
-form.object.ok = true

.product_stock_form.field
  %hr
  %table{:style => "width:100%;"}
    %tr
      %td
        = form.hidden_field :element_label
        = form.hidden_field :ok
        = form.input :custom, :label => "Ligne avec article personnalisé ?", :input_html => {:class => "custom_check_box" }
      
      %td{:colspan => 6}
        .custom_part= form.input :custom_title, :label => "Description article :"
        
    %tr.no_custom_part
      %td
        %label Produit :
        %input.p_product_autocomplete_input.form-control{:type => "text", :value => ("#{form.object.p_product.code} #{form.object.p_product.name}" if form.object.p_product)}
       
      
        = form.hidden_field :p_product_id, :class => "p_product_id"
        
        :javascript
          $( function() {
              
              $('.p_product_autocomplete_input').autocomplete({
                 source: function( request, response ) {
                         $.ajax( {
                           url: "/admin/p_products/autocomplete.json",
                           dataType: "json",
                           data: {
                             search: request.term
                           },
                           success: function(data){
                           
                             arr = jQuery.map( data, function( item ) {
                                                 return {
                                                     label: item.code+" "+item.name,
                                                     value: item.code+" "+item.name,
                                                     id: item.id
                                                 }
                             });
                             
                             response(arr)
                   
                           }
                           
                         } );
                       },
                 minLength: 2,
                 select: function( event, ui ) {
           
                   $(this).next(".p_product_id").val(ui.item.id)
                   
                   //return false
                 }
              });
              
              
              
            } );
            
        
        
        
      %td
        -if form.object.lock == true
          Externe :
          =form.object.externe ? "oui" : "non"
        -else
          = form.input :externe, :label => "Stock externe ?"
      %td
  

    %tr
   
    
      %td
        = form.input :ok_qte, :label => "Quantité livrée:", :input_html =>{:readonly => false, :class => "sheet_line_qte"}, :inline => true
      %td  
        = form.input :ok_price, :label => "Prix U HT livrée :" , :input_html =>{:readonly => false, :class => "sheet_line_price"}
      
      
      %td
        .number.input.required.numeric.stringish.form-group
          %label Prix U TTC :
          %span.form-wrapper
            %input.sheet_line_price_ttc.form-control{:step => "any", :type => "number"}/
      %td.price_td
        .number.input.required.numeric.stringish.form-group
          %label Prix HT :
          .sheet_line_tot.price_emp
      %td.price_td
        .number.input.required.numeric.stringish.form-group
          %label Prix TTC :
          .sheet_line_tot_ttc.price_emp
          
      
      
      
      
      -if false
        %td= form.input :ok_at, :label => "Date de livraison :", :input_html =>{:readonly => (true if form.object.lock == true)}, :as => :date
     
    -if false 
      %tr
      
        %td= form.input :ok_qte, :label => "Quantité livrée :" , :input_html =>{:readonly => (true if form.object.lock == true)}
        %td= form.input :ok_price, :label => "Prix livré :" , :input_html =>{:readonly => (true if form.object.lock == true)}
    
        %td
          -if form.object.lock == true
            Livrée :
            =form.object.ok ? "oui" : "non"
          -else
            = form.input :ok, :label => "Livrée ?", :input_html =>{:readonly => (true if form.object.lock == true)}
  -if form.object.lock != true  
    =link_to_remove_fields ic(:"trash-o"), form