Class: Backend::KujakuHelper::Kujaku::ChoiceFeather

Inherits:
Feather
  • Object
show all
Defined in:
app/helpers/backend/kujaku_helper.rb

Overview

Choice feather permit to select one among many choice to filter

Direct Known Subclasses

DateFeather, NeedleChoiceFeather

Instance Attribute Summary

Attributes inherited from Feather

#uid

Instance Method Summary collapse

Methods inherited from Feather

#feather_name, feather_name, inherited, #initialize, #inspect

Constructor Details

This class inherits a constructor from Backend::KujakuHelper::Kujaku::Feather

Instance Method Details

#configure(*args) ⇒ Object


118
119
120
121
# File 'app/helpers/backend/kujaku_helper.rb', line 118

def configure(*args)
  @name = @options.delete(:name) || :s
  @choices = args
end

#to_htmlObject


123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'app/helpers/backend/kujaku_helper.rb', line 123

def to_html
  first = @choices.first
  @template.params[@name] ||= (first.is_a?(Array) ? first.first : first).to_s
  scope = @options[:scope] || [:labels]
  html = @template.(:label, @options[:label] || :state.tl)
  default_value = @template.params[@name]
  @choices.each do |choice|
    if choice.is_a?(Array)
      label = choice[0]
      value = choice[1]
    else
      label = ::I18n.translate(choice, scope: scope)
      value = choice
    end
    default_value ||= value.to_s
    html << @template.(:span, class: 'radio') do
      @template.(:label, for: "#{@name}_#{value}") do
        @template.radio_button_tag(@name, value, default_value.to_s == value.to_s) <<
          ' '.html_safe <<
          label
      end
    end
  end
  html
end