Class: DynamicFormField
- Inherits:
-
Object
- Object
- DynamicFormField
- Defined in:
- lib/erp_forms/dynamic_form_field.rb
Class Method Summary collapse
- .basic_field(xtype, options = {}, selections = []) ⇒ Object
- .checkbox(options = {}) ⇒ Object
- .ckeditor(options = {}) ⇒ Object
-
.combobox(selections = [], options = {}) ⇒ Object
BASIC FIELDS #.
- .datefield(options = {}) ⇒ Object
- .displayfield(options = {}) ⇒ Object
-
.email(options = {}) ⇒ Object
SPECIAL FIELDS #.
- .filefield(options = {}) ⇒ Object
-
.hidden(options = {}) ⇒ Object
alias.
- .hiddenfield(options = {}) ⇒ Object
- .numberfield(options = {}) ⇒ Object
- .password(options = {}) ⇒ Object
-
.related_combobox(model = '', displayField = '', options = {}) ⇒ Object
a combobox that dynamically pulls options from a related model.
- .set_default_field_options(options = {}) ⇒ Object
- .textarea(options = {}) ⇒ Object
- .textfield(options = {}) ⇒ Object
- .timefield(options = {}) ⇒ Object
- .yesno(selections = [], options = {}) ⇒ Object
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, ={}, selections=[]) = DynamicFormField.() field = { :xtype => xtype, :fieldLabel => [:fieldLabel], :name => [:name], :value => [:value], :allowBlank => [:allowBlank], :readOnly => [:readOnly], :width =>[:width], :height => [:height], :labelWidth => [:labelWidth], :display_in_grid => [:display_in_grid], :searchable => [:display_in_grid] } field[:buttonText] = [:buttonText] unless [:buttonText].blank? field[:displayField] = [:displayField] unless [:displayField].blank? field[:disabled] = [:disabled] unless [:disabled].nil? field[:editable] = [:editable] unless [:editable].nil? field[:emptyText] = [:emptyText] unless [:emptyText].blank? field[:extraParams] = [:extraParams] unless [:extraParams].blank? field[:fields] = [:fields] unless [:fields].blank? field[:forceSelection] = [:forceSelection] unless [:forceSelection].nil? field[:hidden] = [:hidden] unless [:hidden].nil? field[:hideTrigger] = [:hideTrigger] unless [:hideTrigger].nil? field[:hideMode] = [:hideMode] unless [:hideMode].blank? field[:labelAlign] = [:labelAlign] unless [:labelAlign].blank? field[:mapping] = [:mapping] unless [:mapping].blank? field[:minLength] = [:minLength] unless [:minLength].nil? field[:maxLength] = [:maxLength] unless [:maxLength].nil? field[:minValue] = [:minValue] unless [:minValue].nil? field[:maxValue] = [:maxValue] unless [:maxValue].nil? field[:msgTarget] = [:msgTarget] unless [:msgTarget].blank? field[:regexText] = [:regexText] unless [:regexText].blank? field[:url] = [:url] unless [:url].blank? field[:vtype] = [:vtype] unless [:vtype].blank? field[:validation_regex] = [:validation_regex] unless [:validation_regex].blank? field[:validator_function] = [:validator_function] unless [: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(={}) DynamicFormField.basic_field('checkbox', ) 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(={}) [:height] = 300 if [:height].nil? [:width] = 850 if [:width].nil? if [:ckEditorConfig].nil? [: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', ) 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=[], ={}) [:forceSelection] = true if [:forceSelection].nil? DynamicFormField.basic_field('combobox', , selections) end |
.datefield(options = {}) ⇒ Object
40 41 42 |
# File 'lib/erp_forms/dynamic_form_field.rb', line 40 def self.datefield(={}) DynamicFormField.basic_field('datefield', ) end |
.displayfield(options = {}) ⇒ Object
119 120 121 |
# File 'lib/erp_forms/dynamic_form_field.rb', line 119 def self.displayfield(={}) DynamicFormField.basic_field('displayfield', ) end |
.email(options = {}) ⇒ Object
SPECIAL FIELDS #
26 27 28 29 |
# File 'lib/erp_forms/dynamic_form_field.rb', line 26 def self.email(={}) [:validator_function] = 'validateEmail(v)' DynamicFormField.basic_field('textfield', ) end |
.filefield(options = {}) ⇒ Object
132 133 134 |
# File 'lib/erp_forms/dynamic_form_field.rb', line 132 def self.filefield(={}) DynamicFormField.basic_field('filefield', ) end |
.hidden(options = {}) ⇒ Object
alias
141 142 143 |
# File 'lib/erp_forms/dynamic_form_field.rb', line 141 def self.hidden(={}) DynamicFormField.hiddenfield(={}) end |
.hiddenfield(options = {}) ⇒ Object
136 137 138 |
# File 'lib/erp_forms/dynamic_form_field.rb', line 136 def self.hiddenfield(={}) DynamicFormField.basic_field('hiddenfield', ) end |
.numberfield(options = {}) ⇒ Object
31 32 33 |
# File 'lib/erp_forms/dynamic_form_field.rb', line 31 def self.numberfield(={}) DynamicFormField.basic_field('numberfield', ) end |
.password(options = {}) ⇒ Object
35 36 37 38 |
# File 'lib/erp_forms/dynamic_form_field.rb', line 35 def self.password(={}) [:inputType] = 'password' DynamicFormField.basic_field('textfield', ) end |
.related_combobox(model = '', displayField = '', options = {}) ⇒ Object
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.(model='', displayField = '', ={}) [:forceSelection] = true if [:forceSelection].nil? [:displayField] = displayField [:extraParams] = { :model => model, :displayField => displayField } [:fields] = [ { :name => 'id' }, { :name => displayField } ] DynamicFormField.basic_field('related_combobox', ) 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.(={}) [:fieldLabel] = '' if [:fieldLabel].nil? [:name] = '' if [:name].nil? [:allowBlank] = true if [:allowBlank].nil? [:readOnly] = false if [:readOnly].nil? [:minLength] = nil if [:minLength].nil? [:maxLength] = nil if [:maxLength].nil? [:width] = 200 if [:width].nil? [:height] = nil if [:height].nil? [:labelWidth] = 75 if [:labelWidth].nil? [:display_in_grid] = true if [:display_in_grid].nil? [:searchable] = true if [:searchable].nil? end |
.textarea(options = {}) ⇒ Object
123 124 125 126 |
# File 'lib/erp_forms/dynamic_form_field.rb', line 123 def self.textarea(={}) [:height] = 100 if [:height].nil? DynamicFormField.basic_field('textarea', ) end |
.textfield(options = {}) ⇒ Object
115 116 117 |
# File 'lib/erp_forms/dynamic_form_field.rb', line 115 def self.textfield(={}) DynamicFormField.basic_field('textfield', ) end |
.timefield(options = {}) ⇒ Object
44 45 46 |
# File 'lib/erp_forms/dynamic_form_field.rb', line 44 def self.timefield(={}) DynamicFormField.basic_field('timefield', ) end |
.yesno(selections = [], options = {}) ⇒ Object
48 49 50 51 |
# File 'lib/erp_forms/dynamic_form_field.rb', line 48 def self.yesno(selections=[], ={}) selections = [['yes', 'Yes'],['no', 'No']] DynamicFormField.basic_field('combobox', , selections) end |