Class: DynamicFormField

Inherits:
Object
  • Object
show all
Defined in:
lib/erp_forms/dynamic_form_field.rb

Class Method Summary collapse

Class Method Details

.basic_field(xtype, options = {}, selections = []) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/erp_forms/dynamic_form_field.rb', line 145

def self.basic_field(xtype, options={}, selections=[])
  options = DynamicFormField.set_default_field_options(options)

  field = {
      :xtype => xtype,
      :fieldLabel => options[:fieldLabel],
      :name => options[:name],
      :value => options[:value],
      :allowBlank => options[:allowBlank],  
      :readOnly => options[:readOnly],
      :width =>options[:width],
      :height => options[:height],
      :labelWidth => options[:labelWidth],
      :display_in_grid => options[:display_in_grid],
      :searchable => options[:display_in_grid]
  }

  field[:buttonText] = options[:buttonText] unless options[:buttonText].blank?
  field[:displayField] = options[:displayField] unless options[:displayField].blank?
  field[:disabled] = options[:disabled] unless options[:disabled].nil?
  field[:editable] = options[:editable] unless options[:editable].nil?
  field[:emptyText] = options[:emptyText] unless options[:emptyText].blank?
  field[:extraParams] = options[:extraParams] unless options[:extraParams].blank?
  field[:fields] = options[:fields] unless options[:fields].blank?
  field[:forceSelection] = options[:forceSelection] unless options[:forceSelection].nil?
  field[:hidden] = options[:hidden] unless options[:hidden].nil?
  field[:hideTrigger] = options[:hideTrigger] unless options[:hideTrigger].nil?
  field[:hideMode] = options[:hideMode] unless options[:hideMode].blank?
  field[:labelAlign] = options[:labelAlign] unless options[:labelAlign].blank?
  field[:mapping] = options[:mapping] unless options[:mapping].blank?
  field[:minLength] = options[:minLength] unless options[:minLength].nil?
  field[:maxLength] = options[:maxLength] unless options[:maxLength].nil?
  field[:minValue] = options[:minValue] unless options[:minValue].nil?
  field[:maxValue] = options[:maxValue] unless options[:maxValue].nil?
  field[:msgTarget] = options[:msgTarget] unless options[:msgTarget].blank?
  field[:regexText] = options[:regexText] unless options[:regexText].blank?
  field[:url] = options[:url] unless options[:url].blank?
  field[:vtype] = options[:vtype] unless options[:vtype].blank?
  field[:validation_regex] = options[:validation_regex] unless options[:validation_regex].blank?
  field[:validator_function] = options[:validator_function] unless options[:validator_function].blank?

  field[:store] = selections if selections and selections != []    
  
  field
end

.checkbox(options = {}) ⇒ Object



128
129
130
# File 'lib/erp_forms/dynamic_form_field.rb', line 128

def self.checkbox(options={})
  DynamicFormField.basic_field('checkbox', options)
end

.ckeditor(options = {}) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/erp_forms/dynamic_form_field.rb', line 71

def self.ckeditor(options={})
  options[:height] = 300 if options[:height].nil? 
  options[:width] = 850 if options[:width].nil? 

  if options[:ckEditorConfig].nil?
    options[:ckEditorConfig] = {
    #    :width => options[:width],
    #    :height => options[:height],
        :extraPlugins => 'compasssave,jwplayer',
        :toolbar => [
          ['Source','-','CompassSave','Preview','Print'],
          ['Cut','Copy','Paste','PasteText','PasteFromWord'],
          ['Undo','Redo'],
          ['Find','Replace'],
          ['SpellChecker','-','SelectAll'],
          ['TextColor','BGColor'],
          ['Bold','Italic','Underline','Strike'],
          ['Subscript','Superscript','-','jwplayer'],
          ['Table','NumberedList','BulletedList'],
          ['Outdent','Indent','Blockquote'],
          ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
          ['BidiLtr','BidiRtl'],
          ['Link','Unlink','Anchor'],
          ['HorizontalRule','SpecialChar','PageBreak'],
          ['ShowBlocks','RemoveFormat'],
          ['Styles','Format','Font','FontSize' ],
          ['Maximize','-','About']
        ]
      }
  end

  DynamicFormField.basic_field('ckeditor', options)
end

.combobox(selections = [], options = {}) ⇒ Object

BASIC FIELDS #

ComboBox with a static store, if you need a dynamic store use DynamicFormField.related_combobox selections is an array of tuples, i.e. [[‘AL’, ‘Alabama’],[‘AK’, ‘Alaska’]] - [value, text]



110
111
112
113
# File 'lib/erp_forms/dynamic_form_field.rb', line 110

def self.combobox(selections=[], options={})
  options[:forceSelection] = true if options[:forceSelection].nil?
  DynamicFormField.basic_field('combobox', options, selections)
end

.datefield(options = {}) ⇒ Object



40
41
42
# File 'lib/erp_forms/dynamic_form_field.rb', line 40

def self.datefield(options={})
  DynamicFormField.basic_field('datefield', options)
end

.displayfield(options = {}) ⇒ Object



119
120
121
# File 'lib/erp_forms/dynamic_form_field.rb', line 119

def self.displayfield(options={})
  DynamicFormField.basic_field('displayfield', options)
end

.email(options = {}) ⇒ Object

SPECIAL FIELDS #



26
27
28
29
# File 'lib/erp_forms/dynamic_form_field.rb', line 26

def self.email(options={})
  options[:validator_function] = 'validateEmail(v)'
  DynamicFormField.basic_field('textfield', options)
end

.filefield(options = {}) ⇒ Object



132
133
134
# File 'lib/erp_forms/dynamic_form_field.rb', line 132

def self.filefield(options={})
  DynamicFormField.basic_field('filefield', options)
end

.hidden(options = {}) ⇒ Object

alias



141
142
143
# File 'lib/erp_forms/dynamic_form_field.rb', line 141

def self.hidden(options={})
  DynamicFormField.hiddenfield(options={})
end

.hiddenfield(options = {}) ⇒ Object



136
137
138
# File 'lib/erp_forms/dynamic_form_field.rb', line 136

def self.hiddenfield(options={})
  DynamicFormField.basic_field('hiddenfield', options)
end

.numberfield(options = {}) ⇒ Object



31
32
33
# File 'lib/erp_forms/dynamic_form_field.rb', line 31

def self.numberfield(options={})
  DynamicFormField.basic_field('numberfield', options)
end

.password(options = {}) ⇒ Object



35
36
37
38
# File 'lib/erp_forms/dynamic_form_field.rb', line 35

def self.password(options={})
  options[:inputType] = 'password'
  DynamicFormField.basic_field('textfield', options)
end

a combobox that dynamically pulls options from a related model



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/erp_forms/dynamic_form_field.rb', line 54

def self.related_combobox(model='', displayField = '', options={})
  options[:forceSelection] = true if options[:forceSelection].nil?
  options[:displayField] = displayField

  options[:extraParams] = {
    :model => model,
    :displayField => displayField
  }

  options[:fields] = [
    { :name => 'id' },
    { :name => displayField }
  ]

  DynamicFormField.basic_field('related_combobox', options)
end

.set_default_field_options(options = {}) ⇒ Object



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/erp_forms/dynamic_form_field.rb', line 191

def self.set_default_field_options(options={})
  options[:fieldLabel] = '' if options[:fieldLabel].nil?
  options[:name] = '' if options[:name].nil?
  options[:allowBlank] = true if options[:allowBlank].nil?
  options[:readOnly] = false if options[:readOnly].nil?
  options[:minLength] = nil if options[:minLength].nil?
  options[:maxLength] = nil if options[:maxLength].nil?
  options[:width] = 200 if options[:width].nil?
  options[:height] = nil if options[:height].nil?
  options[:labelWidth] = 75 if options[:labelWidth].nil?
  options[:display_in_grid] = true if options[:display_in_grid].nil?
  options[:searchable] = true if options[:searchable].nil?
  
  options
end

.textarea(options = {}) ⇒ Object



123
124
125
126
# File 'lib/erp_forms/dynamic_form_field.rb', line 123

def self.textarea(options={})
  options[:height] = 100 if options[:height].nil? 
  DynamicFormField.basic_field('textarea', options)
end

.textfield(options = {}) ⇒ Object



115
116
117
# File 'lib/erp_forms/dynamic_form_field.rb', line 115

def self.textfield(options={})
  DynamicFormField.basic_field('textfield', options)
end

.timefield(options = {}) ⇒ Object



44
45
46
# File 'lib/erp_forms/dynamic_form_field.rb', line 44

def self.timefield(options={})
  DynamicFormField.basic_field('timefield', options)
end

.yesno(selections = [], options = {}) ⇒ Object



48
49
50
51
# File 'lib/erp_forms/dynamic_form_field.rb', line 48

def self.yesno(selections=[], options={})
  selections = [['yes', 'Yes'],['no', 'No']]
  DynamicFormField.basic_field('combobox', options, selections)
end