Class: Locomotive::FileInput
- Inherits:
-
SimpleForm::Inputs::FileInput
- Object
- SimpleForm::Inputs::FileInput
- Locomotive::FileInput
- Extended by:
- Forwardable
- Includes:
- SimpleForm::BootstrapHelpers
- Defined in:
- app/inputs/locomotive/file_input.rb
Instance Method Summary collapse
- #button_html(name, dropdown = true) ⇒ Object
- #buttons_html ⇒ Object
- #file_html ⇒ Object
- #filename_html ⇒ Object
- #filename_or_image ⇒ Object
- #hidden_css(name) ⇒ Object
- #hidden_fields ⇒ Object
- #image_html ⇒ Object
- #input(wrapper_options = nil) ⇒ Object
- #new_file_html ⇒ Object
- #no_file_html ⇒ Object
- #persisted_file ⇒ Object
- #persisted_file? ⇒ Boolean
- #text(name) ⇒ Object
- #trash_icon ⇒ Object
Methods included from SimpleForm::BootstrapHelpers
Instance Method Details
#button_html(name, dropdown = true) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/inputs/locomotive/file_input.rb', line 37 def (name, dropdown = true) if dropdown content_tag(:div, content_tag(:button, (text(name) + ' ' + content_tag(:span, '', class: 'caret')).html_safe, class: 'btn btn-primary btn-sm dropdown-toggle', data: { toggle: 'dropdown', aria_expanded: false }) + content_tag(:ul, content_tag(:li, content_tag(:a, text(:select_local_file), href: '#', class: "local-file #{name}")) + content_tag(:li, content_tag(:a, text(:select_content_asset), href: template.content_assets_path(template.current_site), class: 'content-assets')), class: 'dropdown-menu dropdown-menu-right', role: 'menu'), class: "btn-group #{name} #{hidden_css(name)}") else template.link_to(text(name), '#', class: "#{name} btn btn-primary btn-sm #{hidden_css(name)}") end end |
#buttons_html ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'app/inputs/locomotive/file_input.rb', line 28 def col_wrapping :buttons, 4 do (:choose, [:select_content_asset]) + (:change, [:select_content_asset]) + (:cancel, false) + template.link_to(trash_icon, '#', class: "delete #{hidden_css(:delete)}") end end |
#file_html ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/inputs/locomotive/file_input.rb', line 16 def file_html col_wrapping :file, 8 do no_file_html + new_file_html + filename_or_image + @builder.file_field(attribute_name, ) + @builder.hidden_field(:"remove_#{attribute_name}", class: 'remove', value: '0') + @builder.hidden_field(:"remote_#{attribute_name}_url", class: 'remote-url', value: '') + hidden_fields end end |
#filename_html ⇒ Object
89 90 91 |
# File 'app/inputs/locomotive/file_input.rb', line 89 def filename_html template.link_to(File.basename(persisted_file.to_s), persisted_file.url) end |
#filename_or_image ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'app/inputs/locomotive/file_input.rb', line 57 def filename_or_image if object.persisted? && persisted_file? css = "current-file #{persisted_file.image? ? 'image' : ''}" template.content_tag :span, (image_html + filename_html).html_safe, class: css else '' end end |
#hidden_css(name) ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'app/inputs/locomotive/file_input.rb', line 101 def hidden_css(name) displayed = case name when :choose, :no_file then !object.persisted? || !persisted_file? when :change, :delete then object.persisted? && persisted_file? else false end displayed ? '' : 'hide' end |
#hidden_fields ⇒ Object
83 84 85 86 87 |
# File 'app/inputs/locomotive/file_input.rb', line 83 def hidden_fields ([:hidden_fields] || []).map do |name| @builder.hidden_field(name) end.join.html_safe end |
#image_html ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'app/inputs/locomotive/file_input.rb', line 74 def image_html if object.persisted? && persisted_file.image? url = Locomotive::Dragonfly.resize_url persisted_file.url, '60x60#' template.image_tag(url) else '' end end |
#input(wrapper_options = nil) ⇒ Object
10 11 12 13 14 |
# File 'app/inputs/locomotive/file_input.rb', line 10 def input( = nil) row_wrapping(data: { persisted: persisted_file?, persisted_file: persisted_file?, resize_format: [:resize_format] }) do file_html + end end |
#new_file_html ⇒ Object
70 71 72 |
# File 'app/inputs/locomotive/file_input.rb', line 70 def new_file_html template.content_tag :span, 'New file here', class: "new-file #{hidden_css(:new_file)}" end |
#no_file_html ⇒ Object
66 67 68 |
# File 'app/inputs/locomotive/file_input.rb', line 66 def no_file_html template.content_tag :span, text(:none), class: "no-file #{hidden_css(:no_file)}" end |
#persisted_file ⇒ Object
97 98 99 |
# File 'app/inputs/locomotive/file_input.rb', line 97 def persisted_file self.object.send(attribute_name.to_sym) end |
#persisted_file? ⇒ Boolean
93 94 95 |
# File 'app/inputs/locomotive/file_input.rb', line 93 def persisted_file? self.object.send(:"#{attribute_name}?") end |
#text(name) ⇒ Object
111 112 113 |
# File 'app/inputs/locomotive/file_input.rb', line 111 def text(name) I18n.t(name, scope: 'locomotive.inputs.file') end |
#trash_icon ⇒ Object
53 54 55 |
# File 'app/inputs/locomotive/file_input.rb', line 53 def trash_icon template.content_tag(:i, '', class: 'far fa-trash-alt') end |