Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Getting ready for changes to add sections and better labels on the fi…

…lters
  • Loading branch information...
commit 1cdb14e1425b94e220230b6563cfb42a284ffe7d 1 parent 2d0948d
@jeffrafter authored
View
33 app/helpers/simple_admin/filter_helper.rb
@@ -1,10 +1,31 @@
module SimpleAdmin
module FilterHelper
+ def filter_fields(attributes)
+ attributes.map do |col|
+ options = col.options.dup
+ expand_block_options!(options)
+ case col.kind
+ when :attribute, :filter
+ filter_for(col.attribute, @interface.constant, options)
+ when :content
+ instance_exec(self, &col.data)
+ when :fieldset
+ content_tag :fieldset, options do
+ content_tag :legend do
+ options[:legend]
+ end unless options[:legend].blank
+ filter_fields(col.attributes)
+ end
+ else
+ content_tag :div, options do
+ filter_fields(col.attributes)
+ end
+ end
+ end.join.html_safe
+ end
+
def filter_for(method, klass, options={})
- options ||= {}
- options = options.dup
options[:as] ||= default_filter_type(klass, method)
- expand_block_options!(options)
return "" unless options[:as]
field_type = options.delete(:as)
wrapper_options = options[:wrapper_html] || {}
@@ -110,7 +131,7 @@ def find_collection_for_column(klass, column, options) #:nodoc:
end
def boolean_collection(klass, column, options)
- [['Yes', true], ['No', false]]
+ [['', true]]
end
def filter_check_boxes_input(klass, method, options = {})
@@ -130,6 +151,8 @@ def filter_check_boxes_input(klass, method, options = {})
].join("\n").html_safe
end
+ alias_method :filter_checkboxes_input, :filter_check_boxes_input
+
# Returns the default filter type for a given attribute
def default_filter_type(klass, method)
if column = column_for(klass, method)
@@ -143,6 +166,8 @@ def default_filter_type(klass, method)
return :numeric
when :float, :decimal
return :numeric
+ when :boolean
+ return :check_boxes
end
end
View
4 app/views/simple_admin/admin/index.html.erb
@@ -70,9 +70,7 @@
<h3>Filters</h3>
<div class="panel_contents">
<%= form_tag '', :class => "q_search", :id => "q_search", :method => "get" do %>
- <% @interface.filters_for(:index).each do |col| %>
- <%= filter_for(col.attribute, @interface.constant, col.options) %>
- <% end %>
+ <%= filter_fields(@interface.filters_for(:index)) %>
<div class="buttons">
<input name="commit" type="submit" value="Filter" />
<a href="?" class="clear_filters_btn">Clear Filters</a>
Please sign in to comment.
Something went wrong with that request. Please try again.