Sha256: ecb349406a251535f4ab783792ad0c1a79a56007f6ad4a6d9e2c3e757fe862fb

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

class GalleryInput < SimpleForm::Inputs::FileInput

  include Assetable::Uploaders

  def input
    # TODO:: Find a better way to do this
    fieldname = "#{object_name}[#{attribute_name}_attributes][asset_attachments_attributes]"

    # This is the hidden input that identifies which gallery we are saving
    # otherwise it will create a new gallery each time.
    hidden_input = template.hidden_field_tag("#{object_name}[#{attribute_name}_attributes][id]", (object.send(attribute_name).present? ? object.send(attribute_name).id : ""))

    # This is the hidden inputs for the uploader. Each asset added to the
    # gallery will use this input name
    gallery_hidden_input = template.hidden_field_tag(fieldname, nil, class: "assetable-uploader-input")

    # Gallery preview
    preview = gallery_preview(fieldname).html_safe rescue ""

    # Uploader HTML = preview + hidden input
    uploader_html = template.content_tag(:div, (gallery_hidden_input + preview), class: "uploader-assets-wrapper")

    # Create and return the uploader html
    directions = options[:directions]
    uploader_wrapper = template.content_tag :div, (uploader_html + hidden_input + directions_html(directions, attribute_name).html_safe), class: "gallery-uploader"
    return uploader_wrapper
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
assetable-0.3.1 app/inputs/gallery_input.rb
assetable-0.3.0 app/inputs/gallery_input.rb