Class: KirguduBase::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- KirguduBase::FormBuilder
show all
- Includes:
- ActionView::Helpers::AssetTagHelper, ActionView::Helpers::TagHelper, GuiHelper
- Defined in:
- app/helpers/kirgudu_base/form_builder.rb
Instance Method Summary
collapse
-
#autocomplete_field(property, html_options = {}) ⇒ Object
-
#autocomplete_with_id(property, html_options = {}) ⇒ Object
-
#check_box(property, html_options = {}) ⇒ Object
-
#chosen_select(property, select_choices, html_options = {}) ⇒ Object
-
#color_picker(property, html_options = {}) ⇒ Object
-
#control(property, data, html_options = {}) ⇒ Object
-
#date_picker(property, html_options = {}) ⇒ Object
-
#elastic_textarea(property, html_options = {}) ⇒ Object
-
#error_label(property, html_options = {}) ⇒ Object
-
#file_input(property, html_options = {}) ⇒ Object
-
#image_selector(property, html_options = {}) ⇒ Object
-
#label(property, html_options = {}) ⇒ Object
-
#label_with_hint(label, hint, html_options = {}) ⇒ Object
-
#masked_field(property, html_options = {}) ⇒ Object
-
#password_field(property, html_options = {}) ⇒ Object
-
#radio_group(label, values, html_options = {}) ⇒ Object
-
#read_only_field(property, data, html_options = {}) ⇒ Object
-
#select(property, select_choices, html_options = {}) ⇒ Object
-
#switch_button(property, html_options = {}) ⇒ Object
-
#text_area(property, html_options = {}) ⇒ Object
-
#text_field(property, html_options = {}) ⇒ Object
Methods included from GuiHelper
#autocomplete_field_tag, #autocomplete_with_id_tag, #chosen_select_tag, #control_tag, #date_picker_tag, #file_input_tag, get_value_for_control, html_options_add_class, html_options_prepare_commons, html_options_set_ids, #left_menu_item_disabled, #left_menu_item_divider, #left_menu_item_link, #left_menu_item_title, #link_to_cart_add, #link_to_cart_remove, #link_to_delete, #link_to_edit, #link_to_entry, #link_to_leftmenu, #link_to_mass, #link_to_nav, #link_to_new, #link_to_paged, #link_to_property, #link_to_search, #link_to_show, #link_to_unless_current_entry, #password_field_tag, #select_tag, #switcher_tag, #text_area_tag, #text_field_tag
Instance Method Details
#autocomplete_field(property, html_options = {}) ⇒ Object
165
166
167
168
169
|
# File 'app/helpers/kirgudu_base/form_builder.rb', line 165
def autocomplete_field(property, html_options = {})
html_options ||= {}
html_options_add_class(html_options, "error") if @object.errors[property.name].present?
end
|
#autocomplete_with_id(property, html_options = {}) ⇒ Object
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
# File 'app/helpers/kirgudu_base/form_builder.rb', line 172
def autocomplete_with_id(property, html_options = {})
html_options ||= {}
autocomplete_with_id_tag(property, @object, html_options)
end
|
#check_box(property, html_options = {}) ⇒ Object
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
# File 'app/helpers/kirgudu_base/form_builder.rb', line 277
def check_box(property, html_options = {})
html_options ||= {}
html_options.merge!(property.html_options) if property.html_options
html_options.merge!(
{
id: "#{@object.class.for_form_params}_#{property.name.to_sym}",
name: "#{@object.class.for_form_params}[#{property.name.to_sym}]",
:"property-name" => property.name.to_s,
:"property-value" => @object[property.name],
value: @object[property.name]
}
)
html_options_add_class(html_options, ["error"]) if @object.errors[property.name].present?
html_options[:parent_value] = @object[property.parent] if property.parent
super(property.name, html_options)
end
|
#chosen_select(property, select_choices, html_options = {}) ⇒ Object
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
|
# File 'app/helpers/kirgudu_base/form_builder.rb', line 341
def chosen_select(property, select_choices, html_options = {})
html_options ||= {}
chosen_select_tag(property, @object, select_choices, html_options)
end
|
#color_picker(property, html_options = {}) ⇒ Object
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
# File 'app/helpers/kirgudu_base/form_builder.rb', line 240
def color_picker(property, html_options = {})
html_options ||= {}
html_options.merge!(property.html_options) if property.html_options
html_options.merge!(
{
id: "#{@object.class.for_form_params}_#{property.name.to_sym}",
name: "#{@object.class.for_form_params}[#{property.name.to_sym}]",
:"property-name" => property.name.to_s,
:"property-value" => @object[property.name]
}
)
html_options_add_class(html_options, ["color-picker", "error"]) if @object.errors[property.name].present?
text_field(property.name, html_options)
end
|
#control(property, data, html_options = {}) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'app/helpers/kirgudu_base/form_builder.rb', line 13
def control(property, data, html_options = {})
if property.read_only == :true
self.read_only_field(property, data, html_options)
else
if property.input_type == :chosen_select
self.chosen_select(property, data, html_options)
elsif property.input_type == :autocomplete_with_id
self.autocomplete_with_id(property, html_options)
elsif property.input_type == :autocomplete
elsif property.input_type == :switch_button
self.switch_button(property, html_options)
elsif property.input_type == :date_picker
self.date_picker(property, html_options)
elsif property.input_type == :time_picker
self.time_picker(property, html_options)
elsif property.input_type == :image_selector
self.image_selector(property, html_options)
elsif property.input_type == :check_box
self.check_box(property, html_options)
elsif property.input_type == :radio_button
elsif property.input_type == :link
self.link(property, html_options)
elsif property.input_type == :elastic_text_area
self.elastic_textarea(property, html_options)
elsif property.input_type == :password
self.elastic_textarea(property, html_options)
elsif property.input_type == :text_area
self.text_area(property, html_options)
elsif property.input_type == :file_input
self.file_input(property, html_options)
elsif property.input_type == :select
elsif property.input_type == :collection_check_boxes
else
self.text_field(property, html_options)
end
end
end
|
#date_picker(property, html_options = {}) ⇒ Object
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
# File 'app/helpers/kirgudu_base/form_builder.rb', line 201
def date_picker(property, html_options = {})
html_options ||= {}
date_picker_tag(property, @object, html_options)
end
|
#elastic_textarea(property, html_options = {}) ⇒ Object
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
# File 'app/helpers/kirgudu_base/form_builder.rb', line 221
def elastic_textarea(property, html_options = {})
html_options ||= {}
html_options.merge!(property.html_options) if property.html_options
html_options.merge!(
{
id: "#{@object.class.for_form_params}_#{property.name.to_sym}",
name: "#{@object.class.for_form_params}[#{property.name.to_sym}]",
:"property-name" => property.name.to_s,
:"property-value" => @object[property.name],
value: @object[property.name]
}
)
html_options_add_class(html_options, "error") if @object.errors[property.name].present?
text_area(property.name, html_options)
end
|
#error_label(property, html_options = {}) ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'app/helpers/kirgudu_base/form_builder.rb', line 72
def error_label(property, html_options = {})
html_options.merge!(generated: "true", style: "display: block")
html_options_add_class(html_options, "error") if @object.errors[property.name].present?
errors_in_html = ""
if @object.errors[property.name].present?
@object.errors[property.name].each do |error_message|
errors_in_html += @template.content_tag("label", error_message.capitalize.html_safe, html_options)
end
end
errors_in_html.html_safe
end
|
381
382
383
384
|
# File 'app/helpers/kirgudu_base/form_builder.rb', line 381
def file_input(property, html_options = {})
file_input_tag(property, @object, html_options)
end
|
#image_selector(property, html_options = {}) ⇒ Object
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
|
# File 'app/helpers/kirgudu_base/form_builder.rb', line 386
def image_selector(property, html_options = {})
html_options ||= {}
control_html = ""
control_html
end
|
#label(property, html_options = {}) ⇒ Object
91
92
93
94
95
|
# File 'app/helpers/kirgudu_base/form_builder.rb', line 91
def label(property, html_options = {})
@template.content_tag("label", html_options) do
@object.class.human_attribute_name(property.name)
end
end
|
#label_with_hint(label, hint, html_options = {}) ⇒ Object
87
88
89
|
# File 'app/helpers/kirgudu_base/form_builder.rb', line 87
def label_with_hint(label, hint, html_options = {})
@template.content_tag("label", (@object.class.human_attribute_name(label) + @template.content_tag("span", hint, class: 'help-block')).html_safe, html_options)
end
|
#masked_field(property, html_options = {}) ⇒ Object
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
# File 'app/helpers/kirgudu_base/form_builder.rb', line 257
def masked_field(property, html_options = {})
html_options ||= {}
html_options.merge!(property.html_options) if property.html_options
html_options.merge!(
{
id: "#{@object.class.for_form_params}_#{property.name.to_sym}",
name: "#{@object.class.for_form_params}[#{property.name.to_sym}]",
:"property-name" => property.name.to_s,
:"property-value" => @object[property.name]
}
)
html_options_add_class(html_options, ["error"]) if @object.errors[property.name].present?
text_field(property.name.to_sym, args)
end
|
#password_field(property, html_options = {}) ⇒ Object
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
# File 'app/helpers/kirgudu_base/form_builder.rb', line 145
def password_field(property, html_options = {})
password_field_tag(property, @object, html_options)
end
|
#radio_group(label, values, html_options = {}) ⇒ Object
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
|
# File 'app/helpers/kirgudu_base/form_builder.rb', line 425
def radio_group(label, values, html_options = {})
label = property.name.to_sym
html_options ||= {}
control_html = ""
values.each do |value_pair|
control_html +=
@template.content_tag('label', class: "radio") do
@template.content_tag('div', class: "radio") do
@template.content_tag('span', class: '') do
@template.tag('input', type: 'radio', name: "#{@object.class.for_form_params}[#{label}]", id: "#{@object.class.for_form_params}_#{label}", value: value_pair[1], style: 'opacity: 0;')
end
end +
value_pair[0]
end
end
control_html.html_safe
end
|
#read_only_field(property, data, html_options = {}) ⇒ Object
98
99
100
101
102
|
# File 'app/helpers/kirgudu_base/form_builder.rb', line 98
def read_only_field(property, data, html_options = {})
@template.content_tag("label", html_options) do
@object.send(property.text_value_property || property.name)
end
end
|
#select(property, select_choices, html_options = {}) ⇒ Object
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
|
# File 'app/helpers/kirgudu_base/form_builder.rb', line 320
def select(property, select_choices, html_options = {})
html_options ||= {}
select_tag(property, @object, select_choices, html_options)
end
|
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
|
# File 'app/helpers/kirgudu_base/form_builder.rb', line 445
def switch_button(property, html_options = {})
html_options ||= {}
html_options.merge!(property.html_options) if property.html_options
html_options.merge!(
{
id: "#{@object.class.for_form_params}_#{property.name.to_sym}",
name: "#{@object.class.for_form_params}[#{property.name.to_sym}]",
value: @object[property.name.to_sym],
:"property-name" => property.name.to_s,
:"property-value" => @object[property.name],
type: "checkbox"
}
)
html_options_add_class(html_options, "switch-button")
@template.tag("input", html_options)
end
|
#text_area(property, html_options = {}) ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# File 'app/helpers/kirgudu_base/form_builder.rb', line 124
def text_area(property, html_options = {})
text_area_tag(property, @object, html_options)
end
|
#text_field(property, html_options = {}) ⇒ Object
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'app/helpers/kirgudu_base/form_builder.rb', line 104
def text_field(property, html_options = {})
html_options ||= {}
html_options.merge!(property.html_options) if property.html_options
html_options.merge!(
{
id: "#{@object.class.for_form_params}_#{property.name}",
name: "#{@object.class.for_form_params}[#{property.name}]",
:"property-name" => property.name,
:"property-value" => @object[property.name]
}
)
html_options_add_class(html_options, "error") if @object.errors[property.name].present?
text_field_tag(property, @object, html_options)
end
|