3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/activeadmin_polymorphic/form_builder.rb', line 3
def polymorphic_has_many(assoc, poly_name, options = {}, &block)
custom_settings = :new_record, :allow_destroy, :heading, :sortable, :sortable_start, :types, :path_prefix
builder_options = {new_record: true, path_prefix: :admin}.merge! options.slice *custom_settings
options = {for: assoc }.merge! options.except *custom_settings
options[:class] = [options[:class], "polymorphic_has_many_fields"].compact.join(' ')
sortable_column = builder_options[:sortable]
sortable_start = builder_options.fetch(:sortable_start, 0)
html = "".html_safe
html << template.capture do
contents = "".html_safe
block = polymorphic_form(poly_name, builder_options)
template.assign('polymorphic_has_many_block' => true)
contents = without_wrapper { inputs(options, &block) }
if builder_options[:new_record]
contents << js_for_polymorphic_has_many(
assoc, poly_name, template, builder_options, options[:class]
)
else
contents
end
end
tag = @already_in_an_inputs_block ? :li : :div
html = template.content_tag(tag, html, class: "polymorphic_has_many_container #{assoc}", 'data-sortable' => sortable_column, 'data-sortable-start' => sortable_start)
template.concat(html) if template.output_buffer
html
end
|