Module: ActiveExt::ExtHelpers::FieldBuilder

Defined in:
lib/active_ext/ext_helpers/field_builder.rb

Class Method Summary collapse

Class Method Details

.build_boolean_field(options = {}) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/active_ext/ext_helpers/field_builder.rb', line 60

def build_boolean_field(options={})
  field_json = {
    :width => 250,
    :xtype => 'combo',
    :labelWidth => 140,
    :forceSelection => true,
    :store => [['true','True'],['false','False']],
    :triggerAction => 'all'
  }

  field_json
end

.build_date_field(options = {}) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'lib/active_ext/ext_helpers/field_builder.rb', line 73

def build_date_field(options={})
  field_json = {
    :width => 250,
    :xtype => 'datefield',
    :labelWidth => 140
  }

  field_json
end

.build_datetime_field(options = {}) ⇒ Object



83
84
85
86
87
88
89
90
91
# File 'lib/active_ext/ext_helpers/field_builder.rb', line 83

def build_datetime_field(options={})
  field_json = {
    :width => 150,
    :xtype => 'datefield',
    :labelWidth => 140
  }

  field_json
end

.build_decimal_field(options = {}) ⇒ Object



113
114
115
116
117
118
119
120
121
# File 'lib/active_ext/ext_helpers/field_builder.rb', line 113

def build_decimal_field(options={})
  field_json = {
    :width => 250,
    :xtype => 'numberfield',
    :labelWidth => 140
  }

  field_json
end

.build_field(column, value, display_only = false, hidden = false) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/active_ext/ext_helpers/field_builder.rb', line 6

def build_field(column, value, display_only = false, hidden = false)
  if display_only
    field_json = display_field(column.options)
  elsif hidden
    field_json = hidden_field(column.options)
  elsif column.options[:readonly]
    field_json = display_field(column.options)
  else
    field_json = self.send("build_#{column.sql_type.to_s}_field", column.options)
  end
  
  field_json[:fieldLabel] = column.name.to_s.humanize
  field_json[:name] = column.name.to_s
  field_json[:allowBlank] = !column.options[:required]

  if display_only
    value = format_display_value(column, value)
  elsif column.options[:readonly]
    value = format_display_value(column, value)
  end

  field_json[:value] = value

  field_json
end

.build_float_field(options = {}) ⇒ Object



123
124
125
126
127
128
129
130
131
# File 'lib/active_ext/ext_helpers/field_builder.rb', line 123

def build_float_field(options={})
  field_json = {
    :width => 250,
    :xtype => 'numberfield',
    :labelWidth => 140
  }

  field_json
end

.build_integer_field(options = {}) ⇒ Object



103
104
105
106
107
108
109
110
111
# File 'lib/active_ext/ext_helpers/field_builder.rb', line 103

def build_integer_field(options={})
  field_json = {
    :width => 250,
    :xtype => 'numberfield',
    :labelWidth => 140
  }

  field_json
end

.build_string_field(options = {}) ⇒ Object



93
94
95
96
97
98
99
100
101
# File 'lib/active_ext/ext_helpers/field_builder.rb', line 93

def build_string_field(options={})
  field_json = {
    :width => 250,
    :xtype => 'textfield',
    :labelWidth => 140
  }

  field_json
end

.build_text_field(options = {}) ⇒ Object



133
134
135
136
137
138
139
140
141
# File 'lib/active_ext/ext_helpers/field_builder.rb', line 133

def build_text_field(options={})
  field_json = {
    :width => 150,
    :xtype => 'textarea',
    :labelWidth => 140
  }

  field_json
end

.display_field(options = {}) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/active_ext/ext_helpers/field_builder.rb', line 50

def display_field(options={})
  field_json = {
    :width => 250,
    :xtype => 'displayfield',
    :labelWidth => 140
  }

  field_json
end

.format_display_value(column, value) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/active_ext/ext_helpers/field_builder.rb', line 32

def format_display_value(column, value)
  if column.sql_type.to_s == 'date'
    value = value.strfdate('%m/%d/%Y') unless value.nil?
  elsif column.sql_type.to_s == 'datetime'
    value = value.strftime('%m/%d/%Y') unless value.nil?
  end

  value
end

.hidden_field(options = {}) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/active_ext/ext_helpers/field_builder.rb', line 42

def hidden_field(options={})
  field_json = {
    :xtype => 'hidden'
  }

  field_json
end