Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Better labeling of checkboxes

  • Loading branch information...
commit 269148230b11be261c9af789cbb0388e2b64337f 1 parent 2e7d946
@jbarket authored
Showing with 30 additions and 2 deletions.
  1. +29 −1 lib/facet_for.rb
  2. +1 −1  lib/facet_for/version.rb
View
30 lib/facet_for.rb
@@ -214,6 +214,11 @@ def render_facet
facet_html << text_field
when :cont_any
collection_type = :array
+
+ if @facet[:collection].nil?
+ @facet[:collection] = unique_value_collection
+ end
+
if @facet[:collection].first.class == 'String'
collection_type = :string
end
@@ -277,7 +282,16 @@ def text_field(options = {})
def check_box(value = "1")
name = "#{@facet[:column_name]}_#{@facet[:type]}"
- return check_box_tag(self.name_for(name, true), value, check_box_checked(value))
+
+ if @facet[:type] == :cont_any
+ check_box_label = label_tag(self.name_for(name, true),
+ value.to_s.humanize)
+ else
+ check_box_label = label_tag(self.name_for(name, true),
+ @facet[:column_name].to_s.humanize)
+ end
+
+ check_box_tag(self.name_for(name, true), value, check_box_checked(value)) + check_box_label
end
def check_box_checked(value = "1")
@@ -292,6 +306,16 @@ def facet_collection
name = "#{@facet[:column_name]}_eq"
selected = @facet[:object].send(name)
+ # @facet[:collection] should be set if we've given it a valid
+ # association, or passed in a collection by hand.
+ #
+ # this assumes that we want to see all unique values from the database
+ # for the given column
+
+ if @facet[:collection].nil?
+ @facet[:collection] = unique_value_collection
+ end
+
if @facet[:collection].class == Array and
@facet[:collection].first.class == String
@@ -306,6 +330,10 @@ def facet_collection
end
+ def unique_value_collection
+ @facet[:collection] = @facet[:model].select("DISTINCT #{@facet[:column_name]}").where("#{@facet[:column_name]} IS NOT NULL").map { |m| m.send(@facet[:column_name]) }
+ end
+
def label(string_name, string_label = nil)
display_label = string_label || string_name.humanize
label_tag self.name_for(string_name), display_label
View
2  lib/facet_for/version.rb
@@ -1,3 +1,3 @@
module FacetFor
- VERSION = "0.0.7"
+ VERSION = "0.0.8"
end
Please sign in to comment.
Something went wrong with that request. Please try again.