Browse files

Added the possibility to remove one filter by clicking on it.

Now clicking an active filter removes it.
  • Loading branch information...
1 parent ebf72bf commit 2d697bfa0dc173d37980188ffd255531cbecdc85 Gaston Kleiman committed with Francesc Esplugas Feb 10, 2010
Showing with 23 additions and 4 deletions.
  1. +23 −4 app/helpers/admin/sidebar_helper.rb
View
27 app/helpers/admin/sidebar_helper.rb
@@ -193,31 +193,50 @@ def relationship_filter(request, filter, habtm = false)
def date_filter(request, filter)
items = %w( today last_few_days last_7_days last_30_days ).map do |timeline|
switch = request.include?("#{filter}=#{timeline}") ? 'on' : 'off'
- options = { filter.to_sym => timeline, :page => nil }
+ if switch == 'on'
+ options = { :page => nil }
+ params.delete(filter)
+ else
+ options = { filter.to_sym => timeline, :page => nil }
+ end
link_to _(timeline.humanize), params.merge(options), :class => switch
end
build_typus_list(items, :attribute => filter)
end
def boolean_filter(request, filter)
+
items = @resource[:class].typus_boolean(filter).map do |key, value|
switch = request.include?("#{filter}=#{key}") ? 'on' : 'off'
- options = { filter.to_sym => key, :page => nil }
+ if switch == 'on'
+ options = { :page => nil }
+ params.delete(filter)
+ else
+ options = { filter.to_sym => key, :page => nil }
+ end
link_to _(value), params.merge(options), :class => switch
end
build_typus_list(items, :attribute => filter)
+
end
def string_filter(request, filter)
+
values = @resource[:class]::const_get("#{filter.to_s.upcase}")
values = values.invert if values.kind_of?(Hash)
items = values.map do |item|
link_name, link_filter = (values.first.kind_of?(Array)) ? [ item.first, item.last ] : [ item, item ]
- switch = request.include?("#{filter}=#{link_filter}") ? 'on' : 'off'
- options = { filter.to_sym => link_filter, :page => nil }
+ switch = (params[filter.to_s] == link_filter) ? 'on' : 'off'
+ if switch == 'on'
+ options = { :page => nil }
+ params.delete(filter)
+ else
+ options = { filter.to_sym => link_filter, :page => nil }
+ end
link_to link_name.capitalize, params.merge(options), :class => switch
end
build_typus_list(items, :attribute => filter)
+
end
end

0 comments on commit 2d697bf

Please sign in to comment.