Class: ActionAdmin::AttachmentsInput
- Inherits:
-
SimpleForm::Inputs::Base
- Object
- SimpleForm::Inputs::Base
- ActionAdmin::AttachmentsInput
- Defined in:
- app/inputs/action_admin/attachments_input.rb
Instance Method Summary collapse
- #attachment(image_url = nil) ⇒ Object
- #attachment_urls ⇒ Object
- #attachments(urls = []) ⇒ Object
- #empty_input ⇒ Object
- #final_attribute_name ⇒ Object
- #hidden_input ⇒ Object
- #input(wrapper_options) ⇒ Object
- #input_html_id ⇒ Object
- #input_placeholder ⇒ Object
- #input_template ⇒ Object
- #label(wrapper_options) ⇒ Object
Instance Method Details
#attachment(image_url = nil) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'app/inputs/action_admin/attachments_input.rb', line 54 def (image_url=nil) image = content_tag :img, nil, src: image_url, class: 'width-100 margin-bottom-1', data: { src: 'file.small.url', url: "#{template.root_url.chomp('/')}[src]" } filename = content_tag :span, nil, class: 'filename', data: { text: 'name' } remove = content_tag :span, nil, class: 'remove-button mdi mdi-close', data: { remove: '' } thumb = content_tag :div, image + filename + remove, class: 'thumbnail' content_tag :div, hidden_input + thumb, class: 'attachment', data: { list_item: '' } end |
#attachment_urls ⇒ Object
46 47 48 |
# File 'app/inputs/action_admin/attachments_input.rb', line 46 def Array(object.try(attribute_name)).map { |a| a.try(:file_url, :small) } end |
#attachments(urls = []) ⇒ Object
50 51 52 |
# File 'app/inputs/action_admin/attachments_input.rb', line 50 def (urls=[]) urls.map { |u| (u) }.join.html_safe end |
#empty_input ⇒ Object
29 30 31 |
# File 'app/inputs/action_admin/attachments_input.rb', line 29 def empty_input @builder.hidden_field(final_attribute_name, value: '', id: nil, multiple: true) end |
#final_attribute_name ⇒ Object
21 22 23 24 25 26 27 |
# File 'app/inputs/action_admin/attachments_input.rb', line 21 def final_attribute_name if object.is_a? ::ActiveRecord::Base :"#{attribute_name}_ids" else :"#{attribute_name}" end end |
#hidden_input ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'app/inputs/action_admin/attachments_input.rb', line 33 def hidden_input = [:data] ||= {} [:data][:value] = :id @builder.hidden_field(final_attribute_name, .merge(multiple: true)) end |
#input(wrapper_options) ⇒ Object
3 4 5 6 7 8 |
# File 'app/inputs/action_admin/attachments_input.rb', line 3 def input() modal = .fetch :modal, 'media-modal' html = content_tag :div, input_placeholder, id: input_html_id, data: { media_attach: modal, media_multiple: true } html + input_template end |
#input_html_id ⇒ Object
42 43 44 |
# File 'app/inputs/action_admin/attachments_input.rb', line 42 def input_html_id hidden_input[/id=\"(.*)\"/, 1].dasherize end |
#input_placeholder ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'app/inputs/action_admin/attachments_input.rb', line 10 def input_placeholder span = content_tag :span, 'No media attached', class: 'margin-bottom-1' icon = content_tag :i, nil, class: 'mdi mdi-camera-off' = content_tag :a, 'Add media', data: { open: input_html_id }, class: 'button success small hollow margin-0' content = content_tag :div, empty_input + icon + span, class: 'no-content hide', data: { empty_state: '' } images = () if .present? grid = content_tag(:div, images, data: { list_remove: '' }, class: 'attachments-grid removable') content + grid + content_tag(:div, , class: 'panel-section expanded border last') end |
#input_template ⇒ Object
63 64 65 |
# File 'app/inputs/action_admin/attachments_input.rb', line 63 def input_template content_tag :script, , id: "#{input_html_id}-item-template", type: 'text/template' end |
#label(wrapper_options) ⇒ Object
67 68 69 |
# File 'app/inputs/action_admin/attachments_input.rb', line 67 def label() '' end |