31 lines
1.3 KiB
Ruby
31 lines
1.3 KiB
Ruby
# -*- encoding : utf-8 -*-
|
|
module DocumentLineHelper
|
|
|
|
def markdown(text)
|
|
simple_format text
|
|
end
|
|
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(options)
|
|
#new_object = f.object.class.reflect_on_association(association).klass.new(:line_type_id => 1)
|
|
fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
|
|
render("admin/"+association.to_s + "/form", :form => builder)
|
|
end
|
|
link_to_function(name, "add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\");", :class => "btn btn-default")
|
|
end
|
|
|
|
def link_to_function(name, *args, &block)
|
|
html_options = args.extract_options!.symbolize_keys
|
|
|
|
function = block_given? ? update_page(&block) : args[0] || ''
|
|
onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function}; return false;"
|
|
href = html_options[:href] || '#'
|
|
|
|
content_tag(:a, name, html_options.merge(:href => href, :onclick => onclick))
|
|
end
|
|
|
|
|
|
end |