Class: ActionAdmin::AttachmentInput
- Inherits:
-
SimpleForm::Inputs::Base
- Object
- SimpleForm::Inputs::Base
- ActionAdmin::AttachmentInput
- Defined in:
- app/inputs/action_admin/attachment_input.rb
Instance Method Summary collapse
- #attachment(image_url = nil) ⇒ Object
- #attachment_url ⇒ 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
49 50 51 52 53 54 55 56 57 58 |
# File 'app/inputs/action_admin/attachment_input.rb', line 49 def (image_url=nil) image = content_tag :img, nil, src: image_url, class: 'width-100 margin-bottom-1', data: { src: 'file.preview.url', url: "#{template.root_url.chomp('/')}[src]" } remove = content_tag :a, 'Remove', class: 'button alert small hollow margin-0', data: { remove: '' } change = content_tag :a, 'Change', class: 'button success small hollow margin-0', data: { open: input_html_id } remove = content_tag :div, remove, class: 'cell auto text-left' change = content_tag :div, change, class: 'cell shrink' = content_tag :div, remove + change, class: 'panel-section expanded border last grid-x' content_tag :div, hidden_input + image + , class: 'attachment text-center', data: { list_item: '' } end |
#attachment_url ⇒ Object
45 46 47 |
# File 'app/inputs/action_admin/attachment_input.rb', line 45 def object.try(attribute_name).try(:file_url, :preview) end |
#empty_input ⇒ Object
28 29 30 |
# File 'app/inputs/action_admin/attachment_input.rb', line 28 def empty_input @builder.hidden_field(final_attribute_name, value: '', id: nil) end |
#final_attribute_name ⇒ Object
20 21 22 23 24 25 26 |
# File 'app/inputs/action_admin/attachment_input.rb', line 20 def final_attribute_name if object.is_a? ::ActiveRecord::Base :"#{attribute_name}_id" else :"#{attribute_name}" end end |
#hidden_input ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'app/inputs/action_admin/attachment_input.rb', line 32 def hidden_input = [:data] ||= {} [:data][:value] = :id @builder.hidden_field(final_attribute_name, ) end |
#input(wrapper_options) ⇒ Object
3 4 5 6 7 8 |
# File 'app/inputs/action_admin/attachment_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 } html + input_template end |
#input_html_id ⇒ Object
41 42 43 |
# File 'app/inputs/action_admin/attachment_input.rb', line 41 def input_html_id hidden_input[/id=\"(.*)\"/, 1].dasherize end |
#input_placeholder ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'app/inputs/action_admin/attachment_input.rb', line 10 def input_placeholder span = content_tag :span, 'No thumbnail', class: 'margin-bottom-1' icon = content_tag :i, nil, class: 'mdi mdi-camera-off' = content_tag :a, 'Add Thumbnail', data: { open: input_html_id }, class: 'button success small hollow' content = content_tag :div, empty_input + icon + span + , class: 'no-content panel-section expanded border first last hide', data: { empty_state: '' } image = () if .present? content + content_tag(:div, image, data: { list_remove: '' }, class: 'attachments') end |
#input_template ⇒ Object
60 61 62 |
# File 'app/inputs/action_admin/attachment_input.rb', line 60 def input_template content_tag :script, , id: "#{input_html_id}-item-template", type: 'text/template' end |
#label(wrapper_options) ⇒ Object
64 65 66 |
# File 'app/inputs/action_admin/attachment_input.rb', line 64 def label() '' end |