Module: AppKit::AttributeHelper

Includes:
FontAwesome::Sass::Rails::ViewHelpers
Defined in:
app/helpers/app_kit/attribute_helper.rb

Instance Method Summary collapse

Instance Method Details

#detect_attribute_type(record, attribute) ⇒ Object



62
63
64
65
# File 'app/helpers/app_kit/attribute_helper.rb', line 62

def detect_attribute_type(record,attribute)
    record.class.columns_hash[attribute.to_s].type ||
      resource.formatters.has_key(attribute.to_sym)
end

#format_attribute(record, field) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/helpers/app_kit/attribute_helper.rb', line 43

def format_attribute(record,field)
    if field.is_foreign_key?
        associated_record = record.send(field.association.name)
        return link_to associated_record, [app_kit, associated_record]
    end
    if field.enum
      return field.enum[record.send(field.name).to_sym]
    end
    formatter = field.formatter
    format_method = "format_#{formatter}"
    if self.respond_to?(format_method)
      return send(format_method, record,
                  field.name,
                  field.value_for_record(record))
    end
    return record.send(field.name)

end

#format_boolean(record, attribute, val) ⇒ Object



19
20
21
# File 'app/helpers/app_kit/attribute_helper.rb', line 19

def format_boolean(record, attribute, val)
    (val ? icon('toggle-on') : icon('toggle-off'))
end

#format_currency(record, attribute, val) ⇒ Object



11
12
13
# File 'app/helpers/app_kit/attribute_helper.rb', line 11

def format_currency(record,attribute,val)
  number_to_currency(val) || "$0.00"
end

#format_date(record, attribute, val) ⇒ Object



15
16
17
# File 'app/helpers/app_kit/attribute_helper.rb', line 15

def format_date(record,attribute,val)
    val.strftime('%m/%d/%y')
end

#format_datetime(record, attribute, val) ⇒ Object



39
40
41
# File 'app/helpers/app_kit/attribute_helper.rb', line 39

def format_datetime(record,attribute, val)
    val.strftime('%m/%d/%y %l:%m %p')
end

#format_decimal(record, attribute, val) ⇒ Object



35
36
37
# File 'app/helpers/app_kit/attribute_helper.rb', line 35

def format_decimal(record,attribute, val)
    number_with_delimiter val
end

#format_email(record, attribute, val) ⇒ Object



27
28
29
# File 'app/helpers/app_kit/attribute_helper.rb', line 27

def format_email(record, attribute, val)
    mail_to val
end

#format_integer(record, attribute, val) ⇒ Object



31
32
33
# File 'app/helpers/app_kit/attribute_helper.rb', line 31

def format_integer(record, attribute, val)
    number_with_delimiter val
end

#format_phone(record, attribute, val) ⇒ Object



23
24
25
# File 'app/helpers/app_kit/attribute_helper.rb', line 23

def format_phone(record, attribute, val)
    number_to_phone(val)
end

#format_string(record, attribute, val) ⇒ Object

General helpers for dealing with field columns



7
8
9
# File 'app/helpers/app_kit/attribute_helper.rb', line 7

def format_string(record, attribute, val)
    val
end

#get_editor_for_attribute(attribute) ⇒ Object



67
68
69
# File 'app/helpers/app_kit/attribute_helper.rb', line 67

def get_editor_for_attribute(attribute)
    resource.editors[attribute.to_sym]
end