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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'app/inputs/collage_input.rb', line 7
def input(wrapper_options = nil)
content = ActiveSupport::SafeBuffer.new
obj = input_html_options.fetch :object, object
input_html_options.merge! id: object_name.parameterize
associated_records = obj.send(reflection_or_attribute_name)
if object.new_record?
field_name = input_html_options.fetch(:field_name, "#{input_html_options[:id]}") << SecureRandom.hex
else
field_name = input_html_options.fetch :field_name, "#{input_html_options[:id]}"
end
cocoon_content = ActiveSupport::SafeBuffer.new
@builder.simple_fields_for(reflection_or_attribute_name) do |f|
cocoon_content << template.render('admin/form_inputs/collage/media_item_fields', f: f, obj: obj)
end
if associated_records.blank?
cocoon_content << template.content_tag(:div, 'Click the "Add collage item" button below to add images to this collage.', class: 'collage-input__empty-canvas-message')
end
canvas_styles = []
if object.try(:collage_height_ratio).present?
canvas_styles << "height: 0"
canvas_styles << "padding-bottom: #{object.collage_height_ratio}%"
end
cocoon_content = template.content_tag(:div, cocoon_content, class: "collage-input__canvas", id: "#{field_name}_preview", style: canvas_styles.join('; '))
cocoon_content = template.content_tag(:div, cocoon_content, class: "row")
content << template.content_tag(:div, cocoon_content, class: "collage-input__canvas-wrapper well")
cocoon_link = template.link_to_add_association('Add collage item',
@builder,
reflection_or_attribute_name,
class: 'collage-input__link-to-add-association btn btn-default',
partial: 'admin/form_inputs/collage/media_item_fields',
render_options: {
locals: {
obj: obj
}
},
data: {
association_insertion_node: "##{field_name}_preview",
association_insertion_method: 'append' })
content << template.content_tag(:div, cocoon_link, class: 'collage-input__cocoon-links links')
content << @builder.hidden_field(:collage_height_ratio, class: 'collage-input__input--height-ratio')
content
end
|