module Polygallery::SimpleFormHelper

Public Class Methods

simple_fields_for_polygallery(fb, title=:gallery, *args, &block) click to toggle source
# File lib/polygallery/simple_form_helper.rb, line 6
def self.simple_fields_for_polygallery(fb, title=:gallery, *args, &block)
  ( '<div class="polygallery-fields">' <<
      fb.simple_fields_for(title, *args, &block) << '</div>' ).html_safe
end

Public Instance Methods

simple_fields_for_polygallery(fb, title=:gallery, *args, &block) click to toggle source
# File lib/polygallery/simple_form_helper.rb, line 10
def simple_fields_for_polygallery(fb, title=:gallery, *args, &block)
  defaults = {
    label: nil,
    add_btn: {
      text: 'Add Photo',
      partial: 'polygallery/photos/simple_fields_for',
      class: 'btn btn-default btn-sm pull-right',
      data: { association_insertion_method: 'append',
              association_insertion_node: "##{fb.object.send(title).polygallery_settings[:association_names][:photos]} .photo-receptacle" }},
    remove_btn: { class: 'btn btn-default btn-sm' },
    file_input: {}}
  settings = if (options = args.find{|a| a.is_a? Hash }).nil? then defaults
             else defaults.deep_merge options end
  new_block = block_given? ? block : ->(fb2) {
    render partial: 'polygallery/galleries/simple_fields_for',
           locals: { f: fb2, settings: settings } }
  SimpleFormHelper.simple_fields_for_polygallery(
    fb, title, *args, &new_block)
end