This repository has been archived on 2021-11-24. You can view files and clone it, but cannot push or open issues or pull requests.
phone_app/app/helpers/document_line_helper.rb
2021-11-18 17:47:00 +01:00

64 lines
1.9 KiB
Ruby

# -*- encoding : utf-8 -*-
module DocumentLineHelper
def link_to_remove_fields(name, f, options={})
f.hidden_field(:_destroy) + link_to(name, "#",
:onclick => "if(confirm('Voulez-vous vraiment supprimer cette ligne ?')) {remove_fields(this);return false;}else{return false;}",
:class => (options[:class]))
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 association == :p_articles
new_object.p_product_ref_id = f.object.p_product_ref_id
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
elsif options[:slug]
fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
render("admin/"+association.to_s + "/form_#{options[:slug]}", :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]),
tabindex: options[:tabindex],
style: options[:style]#,
#data: options["data-qty_to_reach"]
end
end