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
35
36
37
38
39
|
# File 'lib/activeadmin-magicfields/form_builder.rb', line 4
def sections_has_many(assoc, options = {}, &block)
custom_settings = :new_record, :allow_destroy, :heading, :sortable, :sortable_start, :types, :path_prefix, :part_objects, :form_prefix
builder_options = {new_record: true, path_prefix: :admin, part_objects: nil, form_prefix: ''}.merge! options.slice *custom_settings
options = {for: assoc }.merge! options.except *custom_settings
options[:class] = [options[:class], "jsonb"].compact.join(' ')
sortable_column = builder_options[:sortable]
sortable_start = builder_options.fetch(:sortable_start, 0)
collection = options[:collection]
html = "".html_safe
html << template.capture do
contents = "".html_safe
block = sections_form(assoc, builder_options, collection)
template.assign('sections_has_many_block' => true)
builder_options[:part_objects].each do |part_object|
if part_object.part.blank?
part = Part.new
part_object.part = part
end
contents << @template.render("admin/part_objects/part_object", part_object: part_object, part:part_object.part, form_prefix: builder_options[:form_prefix] + @object_name)
end
contents << js_for_section_has_many(
assoc, template, builder_options, options[:class], collection
)
end
tag = @already_in_an_inputs_block ? :li : :div
html = template.content_tag(tag, html, class: "json_container #{assoc}", 'data-sortable' => sortable_column)
template.concat(html) if template.output_buffer
html
end
|