class UiBibzInputs::CollectionInput

Public Instance Methods

collection() click to toggle source
# File lib/ui_bibz/inputs/ui_bibz_inputs/collection_input.rb, line 62
def collection
  @collection ||= if options[:grouped]
                    grouped_collection.map { |collection| collection.try(:send, group_method) }.detect(&:present?) || []
                  else
                    collection = options.delete(:collection) || self.class.boolean_collection
                    collection.respond_to?(:call) ? collection.call : collection.to_a
                  end
end
group_label_method() click to toggle source
# File lib/ui_bibz/inputs/ui_bibz_inputs/collection_input.rb, line 75
def group_label_method
  label = options.delete(:group_label_method)

  unless label
    common_method_for = detect_common_display_methods(detect_collection_classes(grouped_collection))
    label = common_method_for[:label]
  end

  label
end
group_method() click to toggle source
# File lib/ui_bibz/inputs/ui_bibz_inputs/collection_input.rb, line 71
def group_method
  @group_method ||= options.delete(:group_method)
end
grouped_collection() click to toggle source
# File lib/ui_bibz/inputs/ui_bibz_inputs/collection_input.rb, line 51
def grouped_collection
  @grouped_collection ||= begin
    grouped_collection = options.delete(:collection)
    grouped_collection.respond_to?(:call) ? grouped_collection.call : grouped_collection.to_a
  end
end
input_attribute_name() click to toggle source
# File lib/ui_bibz/inputs/ui_bibz_inputs/collection_input.rb, line 58
def input_attribute_name
  "#{@builder.object_name}[#{attribute_name}]"
end
input_html_options() click to toggle source
Calls superclass method
# File lib/ui_bibz/inputs/ui_bibz_inputs/collection_input.rb, line 8
def input_html_options
  opts = super
  input_classes = UiBibz::Utils::Screwdriver.join_classes(@builder.options[:input_html].try(:[], :class), options[:input_html].try(:[], :class), options[:class])
  opts = opts.merge({ prompt: options[:prompt] })               if options[:prompt].present?
  opts = opts.merge({ disabled: options[:disabled] })           if options[:disabled].present?
  opts = opts.merge({ include_blank: options[:include_blank] }) if options[:include_blank].present?
  opts = opts.merge({ multiple: options[:multiple] })           if options[:multiple].present?
  (@builder.options[:input_html] || {}).merge(options[:input_html] || {}).merge(opts || {}).merge({ class: input_classes })
end
new_options() click to toggle source
# File lib/ui_bibz/inputs/ui_bibz_inputs/collection_input.rb, line 18
def new_options
  label_method, value_method = detect_collection_methods

  if options[:option_tags].nil?
    if options[:grouped] == true
      options.merge({ option_tags: option_groups_from_collection_for_select(
        grouped_collection,
        group_method, group_label_method,
        value_method, label_method,
        new_value
      ) })
    else
      options.merge({ option_tags: options_from_collection_for_select(
        collection, value_method, label_method, new_value
      ) })
    end
  else
    options
  end
end
new_value() click to toggle source
# File lib/ui_bibz/inputs/ui_bibz_inputs/collection_input.rb, line 39
def new_value
  if @builder.object.send(attribute_name).blank?
    @builder.object.send(attribute_name)
  else
    begin
      ActiveSupport::JSON.decode(@builder.object.send(attribute_name).to_s)
    rescue StandardError
      @builder.object.send(attribute_name)
    end
  end
end