Module: Admin::Resources::DataTypes::BooleanHelper

Defined in:
app/helpers/admin/resources/data_types/boolean_helper.rb

Instance Method Summary collapse

Instance Method Details

#boolean_filter(filter) ⇒ Object



22
23
24
25
26
# File 'app/helpers/admin/resources/data_types/boolean_helper.rb', line 22

def boolean_filter(filter)
  values  = @resource.typus_boolean(filter)
  items = [[Typus::I18n.t("Show by %{attribute}", :attribute => @resource.human_attribute_name(filter).downcase), ""]]
  items += values.map { |k, v| [Typus::I18n.t(k.humanize), v] }
end

#display_boolean(item, attribute) ⇒ Object



3
4
5
6
7
# File 'app/helpers/admin/resources/data_types/boolean_helper.rb', line 3

def display_boolean(item, attribute)
  data = item.send(attribute)
  boolean_assoc = item.class.typus_boolean(attribute)
  (data ? boolean_assoc.rassoc("true") : boolean_assoc.rassoc("false")).first
end

#table_boolean_field(attribute, item) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/helpers/admin/resources/data_types/boolean_helper.rb', line 9

def table_boolean_field(attribute, item)
  status = item.send(attribute)
  boolean_assoc = item.class.typus_boolean(attribute)
  human_boolean = (status ? boolean_assoc.rassoc("true") : boolean_assoc.rassoc("false")).first

  options = { :controller => "/admin/#{item.class.to_resource}",
              :action => "toggle",
              :id => item.id,
              :field => attribute.gsub(/\?$/, '') }
  confirm = Typus::I18n.t("Change %{attribute}?", :attribute => item.class.human_attribute_name(attribute).downcase)
  link_to Typus::I18n.t(human_boolean), options, :confirm => confirm
end