Sha256: 1dd3c2babf620e75d1cc4821724105598f2d0dd39b95e2cc30274a3acdf73779

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 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
    uploader_wrapper = template.content_tag :div, (uploader_html + hidden_input + directions_html.html_safe), class: "gallery-uploader"
    return uploader_wrapper
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
assetable-0.2.4 app/inputs/gallery_input.rb
assetable-0.2.2 app/inputs/gallery_input.rb
assetable-0.2.1 app/inputs/gallery_input.rb