Sha256: 658f056f3ba66716e640bf50d85ca51ea450870a3f65a6379f186e672b8682f3

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

require 'erector'

class PrettyFileInput::Component < Erector::Widget
  needs :name,                # input name that will be sent to the server
        persisted: false,     # is parent object is not persisted, no AJAX calls will be made
        filename: nil,        # pre-populate the filename span
        method: nil,          # override the parent form's method
        action: nil,          # override the parent form's action
        additional_params: {} # additional parameters to be sent to server with each request

  def content
    div(
      class: "pfi cf #{@filename ? 'is_uploaded' : ''}",
      'data-pfi' => {
        name: @name,
        persisted: @persisted,
        action: @action,
        method: @method,
        additionalParams: @additional_params
      }.to_json
    ) {
      div.pfi_uploaded {
        span.pfi_existing_filename @filename
        text ' '
        a.button.mini.info 'Remove', 'data-pfi-remove' => true
      }
      div.pfi_not_uploaded {
        input type: 'file'
        span.pfi_status
      }
    }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pretty_file_input-0.0.1 lib/pretty_file_input/component.rb