Sha256: 60cef2d42bbc61ac9628f3e29aa05b9723cb985c3e0fab8b4153cf0572303860

Contents?: true

Size: 1.64 KB

Versions: 7

Compression:

Stored size: 1.64 KB

Contents

<%
  # headmin/filters/select
  #
  # ==== Options
  # * +name</tt> - Name of the filter parameter
  # * +label</tt> - Display name
  # * +options</tt> - List of options to select from
  #
  # ==== Examples
  #   Basic version
  #   <%= render "headmin/filters/select", name: :poll_type, label: 'Type', options: [["General", "general", "Fun", "fun"]] %#>

  name = local_assigns.has_key?(:name) ? name.to_sym : nil
  label = local_assigns.has_key?(:label) ? label : name.to_s.humanize
  options = local_assigns.has_key?(:options) ? options : []

  select_options = {
    class: "form-select",
    prompt: t('.blank'),
    include_blank: false,
    required: true,
    'data-filters-target': 'input',
    'data-action': "change->filters#update"
  }
%>

<%= content_for :filters_menu do %>
  <%= render 'headmin/filters/filter/menu_item', name: name, label: label %>
<% end %>

<%= content_for :filters_templates do %>
  <%= render 'headmin/filters/filter/template', name: name, label: label do %>
    <%= select_tag("#{name}[]", options_for_select(options), select_options) %>
  <% end %>
<% end %>

<%= content_for :filters_buttons do %>
  <% (params[name] || []).each_with_index do |param, index| %>
    <% selected_option = options.detect { |value, key, config| (key.present? ? key : value) == param } %>
    <% selected_value = selected_option.is_a?(Array) ? selected_option.first : selected_option %>
    <%= render 'headmin/filters/filter/button', name: name, label: label, value: selected_value, id: "#{name}_#{index}_#{SecureRandom.hex}" do %>
      <%= select_tag("#{name}[]", options_for_select(options, param), select_options) %>
    <% end %>
  <% end %>
<% end %>

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
headmin-0.4.2 app/views/headmin/filters/_select.html.erb
headmin-0.4.1 app/views/headmin/filters/_select.html.erb
headmin-0.4.0 app/views/headmin/filters/_select.html.erb
headmin-0.3.4 app/views/headmin/filters/_select.html.erb
headmin-0.3.3 app/views/headmin/filters/_select.html.erb
headmin-0.3.2 app/views/headmin/filters/_select.html.erb
headmin-0.3.1 app/views/headmin/filters/_select.html.erb