Sha256: 2dbc564a1de4184f840b71c6bed192e467e0a2e7b2269de9d254a9b103d2c314

Contents?: true

Size: 1.75 KB

Versions: 13

Compression:

Stored size: 1.75 KB

Contents

class SelectedListInput < ActiveAdminAddons::InputBase
  def render_custom_input
    concat(label_html)
    concat(render_control_wrapper)
  end

  def load_control_attributes
    load_class(@options[:class])
    load_data_attr(:model, value: model_name)
    load_data_attr(:method, value: method)
    load_data_attr(:url, default: url_from_method)
    load_data_attr(:response_root, default: tableize_method)
    load_data_attr(:fields, default: ["name"], formatter: :to_json)
    load_data_attr(:predicate, default: "contains")
    load_data_attr(:display_name, default: "name")
    load_data_attr(:minimum_input_length, default: 1)
    load_data_attr(:width, default: "100%")
    load_data_attr(
      :order,
      value: @options[:order_by],
      default: get_data_attr_value(:fields).first.to_s + "_desc"
    )
  end

  private

  def render_control_wrapper
    template.content_tag(:div, class: "selected-list-container") do
      template.content_tag(label_html)
      template.concat(render_items_list)
      template.concat(builder.select(build_virtual_attr, [], {}, input_html_options))
    end
  end

  def render_items_list
    template.content_tag(:div, id: selected_values_id, class: "selected-values") do
      template.concat(build_hidden_control(empty_input_id, method_to_input_array_name, ""))
      input_related_items.each { |item| template.concat(render_item(item)) }
    end
  end

  def render_item(item)
    template.content_tag(:div, id: method_to_input_id(item.id), class: "selected-item") do
      template.concat(item_label(item))
      template.concat(
        build_hidden_control(method_to_input_id(item.id), method_to_input_array_name, item.id.to_s)
      )
    end
  end

  def item_label(item)
    item.send(@options[:display_name] || "name")
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
activeadmin_addons-2.0.0.beta.2 app/inputs/selected_list_input.rb
activeadmin_addons-2.0.0.beta.0 app/inputs/selected_list_input.rb
activeadmin_addons-1.10.0 app/inputs/selected_list_input.rb
activeadmin_addons-1.9.0 app/inputs/selected_list_input.rb
activeadmin_addons-1.8.3 app/inputs/selected_list_input.rb
activeadmin_addons-1.8.2 app/inputs/selected_list_input.rb
activeadmin_addons_rails6-1.7.2 app/inputs/selected_list_input.rb
activeadmin_addons-1.7.1 app/inputs/selected_list_input.rb
activeadmin_addons-1.7.0 app/inputs/selected_list_input.rb
activeadmin_addons-1.6.0 app/inputs/selected_list_input.rb
activeadmin_addons-1.5.0 app/inputs/selected_list_input.rb
activeadmin_addons-1.4.0 app/inputs/selected_list_input.rb
activeadmin_addons-1.3.0 app/inputs/selected_list_input.rb