Class: ActionAdmin::UploadInput
- Inherits:
-
SimpleForm::Inputs::FileInput
- Object
- SimpleForm::Inputs::FileInput
- ActionAdmin::UploadInput
- Defined in:
- app/inputs/action_admin/upload_input.rb
Instance Method Summary collapse
- #attachment(image_url = nil) ⇒ Object
- #attachment_url ⇒ Object
- #attr_html_id ⇒ Object
- #file_input ⇒ 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
47 48 49 50 51 52 |
# File 'app/inputs/action_admin/upload_input.rb', line 47 def (image_url=nil) image = content_tag :img, nil, src: image_url, class: 'width-100 margin-bottom-1', data: { dz_thumbnail: '' } = content_tag :a, 'Remove File', class: 'button alert small hollow margin-0', data: { dz_remove: '' } content_tag :div, hidden_input + image + , class: 'text-center' end |
#attachment_url ⇒ Object
43 44 45 |
# File 'app/inputs/action_admin/upload_input.rb', line 43 def object.send(attribute_name).try(:url) end |
#attr_html_id ⇒ Object
35 36 37 |
# File 'app/inputs/action_admin/upload_input.rb', line 35 def attr_html_id file_input[/id=\"(.*)\"/, 1] end |
#file_input ⇒ Object
23 24 25 |
# File 'app/inputs/action_admin/upload_input.rb', line 23 def file_input @builder.file_field(attribute_name, ) end |
#hidden_input ⇒ Object
27 28 29 30 31 32 33 |
# File 'app/inputs/action_admin/upload_input.rb', line 27 def hidden_input if object.respond_to?("#{attribute_name}_cache") @builder.hidden_field("#{attribute_name}_cache") else ''.html_safe end end |
#input(wrapper_options) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'app/inputs/action_admin/upload_input.rb', line 3 def input() out = ActiveSupport::SafeBuffer.new data = { file_input: '', previews_container: "##{input_html_id}-preview" } html = content_tag :div, input_placeholder, id: input_html_id, class: 'dropzone', data: data out << html out << input_template end |
#input_html_id ⇒ Object
39 40 41 |
# File 'app/inputs/action_admin/upload_input.rb', line 39 def input_html_id attr_html_id.dasherize end |
#input_placeholder ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'app/inputs/action_admin/upload_input.rb', line 12 def input_placeholder span = content_tag :span, 'Drop file here', class: 'margin-bottom-1' icon = content_tag :i, nil, class: 'mdi mdi-upload' = content_tag :label, 'Upload File', for: attr_html_id, class: 'button success small hollow margin-0' content = content_tag :div, icon + span + file_input + , class: 'no-content' image = () if .present? content_tag(:div, content, class: 'dz-message bordered hide') + content_tag(:div, image, id: "#{input_html_id}-preview") end |
#input_template ⇒ Object
54 55 56 |
# File 'app/inputs/action_admin/upload_input.rb', line 54 def input_template content_tag :script, , id: "#{input_html_id}-preview-template", type: 'text/template' end |
#label(wrapper_options) ⇒ Object
58 59 60 |
# File 'app/inputs/action_admin/upload_input.rb', line 58 def label() '' end |