Class: AbAdmin::Views::SearchFormBuilder
- Inherits:
-
Ransack::Helpers::FormBuilder
- Object
- Ransack::Helpers::FormBuilder
- AbAdmin::Views::SearchFormBuilder
- Defined in:
- lib/ab_admin/views/search_form_builder.rb
Instance Method Summary collapse
- #ac_string_field(attr, options = {}) ⇒ Object
- #boolean_field(attr, options = {}) ⇒ Object
- #date_field(attr, options = {}) ⇒ Object
- #filed_type(attr, options = {}) ⇒ Object
- #hidden_field(attr, options = {}) ⇒ Object
- #input(attr, options = {}) ⇒ Object
- #label(attr, text = nil, options = {}) ⇒ Object
- #number_field(attr, options = {}) ⇒ Object
- #select_field(attr, options = {}) ⇒ Object
- #string_field(attr, options = {}) ⇒ Object
Instance Method Details
#ac_string_field(attr, options = {}) ⇒ Object
56 57 58 59 |
# File 'lib/ab_admin/views/search_form_builder.rb', line 56 def ac_string_field(attr, ={}) .reverse_deep_merge!({:input_html => {:class => 'ac_field', :data => {:class => @object.klass.name}}}) string_field(attr, ) end |
#boolean_field(attr, options = {}) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ab_admin/views/search_form_builder.rb', line 70 def boolean_field(attr, ={}) content_tag(:div, :class => 'pull-left') do param = "#{attr}_eq" content_tag(:label, :class => 'checkbox inline') do check_box_tag("q[#{param}]", 1, params[:q][param].to_i == 1, :class => 'inline', :id => "q_#{attr}") + I18n.t('simple_form.yes') end + content_tag(:label, :class => 'checkbox inline') do check_box_tag("q[#{param}]", 0, params[:q][param] && params[:q][param].to_i == 0, :class => 'inline') + I18n.t('simple_form.no') end end + label(attr, [:label], :class => 'right-label') end |
#date_field(attr, options = {}) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/ab_admin/views/search_form_builder.rb', line 39 def date_field(attr, ={}) label(attr, [:label]) + content_tag(:div, :class => 'controls') do gt_param, lt_param = "#{attr}_gteq", "#{attr}_lteq" text_field_tag("q[#{gt_param}]", params[:q][gt_param], :class => 'input-small datepicker', :autocomplete => 'off') + ' - ' + text_field_tag("q[#{lt_param}]", params[:q][lt_param], :class => 'input-small datepicker', :autocomplete => 'off', :id => "q_#{attr}") end end |
#filed_type(attr, options = {}) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/ab_admin/views/search_form_builder.rb', line 91 def filed_type(attr, ={}) return .delete(:as).to_sym if [:as] return :string if attr =~ /^translations_/ input_type = @object.klass.columns_hash[attr.to_s].try(:type) if input_type return :select if [:collection] elsif @object.klass.translates? && @object.klass.translated?(attr) [:value_attr] = "translations_#{attr}" return :string elsif assoc = @object.klass.reflect_on_association(attr.to_sym) [:collection] ||= assoc.klass.limit(500) [:value_attr] = "#{attr}_id" return :select end case input_type when :timestamp, :datetime, :date :date when :decimal, :float, :integer :number else input_type or raise "No available input type for #{attr}" end end |
#hidden_field(attr, options = {}) ⇒ Object
82 83 84 |
# File 'lib/ab_admin/views/search_form_builder.rb', line 82 def hidden_field(attr, ={}) hidden_field_tag("q[#{attr}_eq]", .delete(:value), ) end |
#input(attr, options = {}) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/ab_admin/views/search_form_builder.rb', line 8 def input(attr, ={}) filed_type = filed_type(attr, ) content_tag :div, :class => "clearfix #{filed_type}" do send("#{filed_type}_field", attr, ) end end |
#label(attr, text = nil, options = {}) ⇒ Object
86 87 88 89 |
# File 'lib/ab_admin/views/search_form_builder.rb', line 86 def label(attr, text=nil, ={}) text ||= @object.klass.han(attr) super(attr, text, ) end |
#number_field(attr, options = {}) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/ab_admin/views/search_form_builder.rb', line 61 def number_field(attr, ={}) label(attr, [:label]) + content_tag(:div, :class => 'controls') do opts = [['=', 'eq'], ['>', 'gt'], ['<', 'lt']].map { |m| [m[0], "#{attr}_#{m[1]}"] } current_filter = (opts.detect { |m| params[:q][m[1]].present? } || opts.first)[1] select_tag('', (opts, current_filter), :class => 'input-small predicate-select') + text_field_tag("q[#{current_filter}]", params[:q][current_filter], :class => 'input-small') end end |
#select_field(attr, options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ab_admin/views/search_form_builder.rb', line 15 def select_field(attr, ={}) label(attr, [:label]) + content_tag(:div, :class => 'controls') do param = "#{[:value_attr] || attr}_eq" if [:collection].is_a?(Proc) collection = [:collection].call else collection = [:collection] || [] end if collection.first.try(:respond_to?, :id) collection.map!{|r| [AbAdmin.display_name(r), r.id] } end [:html_options] ||= {} if [:fancy] || !.has_key?(:fancy) [:html_options][:class] = [[:html_options][:class], 'fancy_select'].join(' ') end = [:html_options].merge(:include_blank => true, :id => "q_#{attr}") select_tag("q[#{param}]", (collection, params[:q][param]), ) end end |
#string_field(attr, options = {}) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/ab_admin/views/search_form_builder.rb', line 47 def string_field(attr, ={}) label(attr, [:label]) + content_tag(:div, :class => 'controls') do param = "#{[:value_attr] || attr}_cont" [:input_html] ||= {} [:input_html][:id] = "q_#{attr}" text_field_tag("q[#{param}]", params[:q][param], [:input_html]) end end |