Sha256: 813860fbbebed7e3312e49139656ea84ffa948d168e0575a1609b5bfe9b3a748

Contents?: true

Size: 1.44 KB

Versions: 26

Compression:

Stored size: 1.44 KB

Contents

module Locomotive
  class FileInput

    include Formtastic::Inputs::Base

    def to_html
      input_wrapping do
        label_html
      end
    end

    def input_wrapping(&block)
      template.content_tag(:li,
        [template.capture(&block), file_wrapper_html, error_html, hint_html].join("\n").html_safe,
        wrapper_html_options
      )
    end

    def file_wrapper_html
      prefix = builder.custom_namespace.present? ? "#{builder.custom_namespace}_" : ''

      template_id = "#{prefix}#{method}_file_input"

      template.content_tag(:script,
        %(
          {{#if url}}
          #{with_file_html}
          {{else}}
          #{without_file_html}
          {{/if}}).html_safe,
        type: 'text/html', id: template_id)
    end

    def with_file_html
      cancel_message = I18n.t('locomotive.shared.form.cancel')

      html =  template.link_to '{{filename}}', '{{url}}', target: '_blank'
      html += builder.file_field(method, input_html_options.merge(style: 'display: none'))
      html += template.link_to I18n.t('locomotive.shared.form.change_file'), '#', class: 'change', :'data-alt-label' => cancel_message
      html += template.link_to I18n.t('locomotive.shared.form.delete_file'), '#', class: 'delete', :'data-alt-label' => cancel_message
      html += builder.hidden_field "remove_#{method}", class: 'remove-flag'
    end

    def without_file_html
      builder.file_field(method, input_html_options).html_safe
    end

  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
locomotive_cms-2.5.7 app/inputs/locomotive/file_input.rb
locomotive_cms-2.5.6 app/inputs/locomotive/file_input.rb
locomotive_cms-2.5.6.rc2 app/inputs/locomotive/file_input.rb
locomotive_cms-2.5.6.rc1 app/inputs/locomotive/file_input.rb
locomotive_cms-2.5.5 app/inputs/locomotive/file_input.rb
locomotive_cms-2.5.4 app/inputs/locomotive/file_input.rb
locomotive_cms-2.5.3 app/inputs/locomotive/file_input.rb
locomotive_cms-2.5.2 app/inputs/locomotive/file_input.rb
locomotive_cms-2.5.1 app/inputs/locomotive/file_input.rb
locomotive_cms-2.5.0 app/inputs/locomotive/file_input.rb
locomotive_cms-2.5.0.rc3 app/inputs/locomotive/file_input.rb
locomotive_cms-2.5.0.rc2 app/inputs/locomotive/file_input.rb
locomotive_cms-2.5.0.rc1 app/inputs/locomotive/file_input.rb
locomotive_cms-2.4.1 app/inputs/locomotive/file_input.rb
locomotive_cms-2.4.0 app/inputs/locomotive/file_input.rb
locomotive_cms-2.3.1 app/inputs/locomotive/file_input.rb
locomotive_cms-2.3.0 app/inputs/locomotive/file_input.rb
locomotive_cms-2.2.3 app/inputs/locomotive/file_input.rb
locomotive_cms-2.2.2 app/inputs/locomotive/file_input.rb
locomotive_cms-2.2.1 app/inputs/locomotive/file_input.rb