# -*- encoding : utf-8 -*-
module DocumentLineHelper


  def link_to_remove_fields(name, f)
    f.hidden_field(:_destroy) + link_to(name, "#",:onclick => "if(confirm('Voulez-vous vraiment supprimer cette ligne ?')) {remove_fields(this);return false;}else{return false;}")
  end

  def link_to_add_fields(name, f, association, options={})
    new_object = f.object.class.reflect_on_association(association).klass.new()
    
    
    if association == :product_options
      
      

      new_object.product_option_langs << ProductOptionLang.new(:lang => LangSite.first.slug)

      
      
    
    end
    if options[:partial]
      fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
        render(options[:partial], :form => builder)
      end
    elsif association == :p_payments
      fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
        render("admin/"+association.to_s + "/essentials_form", :form => builder)
      end
    else
      fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
        render("admin/"+association.to_s + "/form", :form => builder)
      end
    end
    
    link_to name,"#", :onclick => "add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\");return false;", :class => (options[:class])
  end
	
end