Class: KirguduBase::FormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Includes:
ActionView::Helpers::AssetTagHelper, ActionView::Helpers::TagHelper, GuiHelper
Defined in:
app/helpers/kirgudu_base/form_builder.rb

Instance Method Summary collapse

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 ||= {}

	#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],
	#		type: "hidden",
	#		:"value-property" => property.data_source.value_property,
	#		:"label-property" => property.data_source.label_property,
	#		url: property.data_source.url,
	#		value: @object.send(property.name),
	#		label: @object.send(property.text_value_property),
	#		placeholder: property.use_i18n ? I18n.t(property.placeholder) : property.placeholder,
	#		:"parent-id" => ("#{@object.class.for_form_params}_#{html_options[:parent]}" if property.parent)
	#	}
	#)
	#
	#html_options_add_class(html_options, "autocomplete-with-id")
	#html_options_add_class(html_options, "error") if @object.errors[property.name].present?
	#
	#@template.content_tag("input", nil, 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?


	#if html_options[:onchange]
	#	onchange_actions = []
	#	if html_options[:onchange].is_a?(Hash)
	#		onchange_actions.push(html_options[:onchange])
	#	elsif html_options[:onchange].is_a?(Array)
	#		html_options[:onchange].each do |a|
	#			onchange_actions.push(a)
	#		end
	#	end
	#
	#	onchange_actions.each do |o|
	#		o[:property_control] = "#{@object.class.for_form_params}_#{o[:property]}"
	#
	#		if o[:source] && o[:source].is_a?(Hash)
	#			o[:source] = Rails.application.routes.url_helpers.url_for(o[:source])
	#		end
	#	end
	#
	#	html_options[:onchange] = onchange_actions
	#end

	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 ||= {}

	#html_options.merge!(property.html_options) if property.html_options
	#html_options.merge!(
	#	{
	#		id: "#{@object.class.for_form_params}_#{property.name.to_s}",
	#		name: "#{@object.class.for_form_params}[#{property.name.to_s}]",
	#		value: @object[property.name.to_sym],
	#		:"property-name" => property.name.to_s,
	#		:"property-value" => @object[property.name],
	#		parent: (property.parent if property.parent),
	#		parent_id: ("#{@object.class.for_form_params}_#{property.parent}" if property.parent),
	#		parent_value: (@object[property.parent] if property.parent),
	#		placeholder: property.placeholder_as_string
	#	}
	#)
	#html_options_add_class(html_options, ["error"]) if @object.errors[property.name].present?
	#
	#
	#if property.data_source.type == :jquery || property.data_source.type == :jquery_db
	#	html_options.merge!({
	#		               :"ds-method" => property.data_source.http_method,
	#		               :"ds-url" => property.data_source.url,
	#		               :"ds-value-property" => property.data_source.value_property,
	#		               :"ds-label-property" => property.data_source.label_property,
	#		               #ds_type: property.data_source.type == :jquery ? :jquery : :local
	#		               :"ds-format" => property.data_source.data_format
	#	               })
	#end


	#raise "CHOSEN SELECT HTML OPTIONS: #{html_options.to_json}"

	#chosen_select_tag(select_choices, 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
			#autocomplete(property, html_options)


		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
			#radio_button(property, html_options)

		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
			#file_input(property, html_options)
		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 ||= {}

	#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?

	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.("label", error_message.capitalize.html_safe, html_options)
		end
	end
	errors_in_html.html_safe
end

#file_input(property, html_options = {}) ⇒ Object



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 = ""
	#
	#
	#image_options =
	#	{
	#		src: thumb_url,
	#		id: "#{@object.class.for_form_params}_#{label}_selected_image"
	#	}
	#image_options[:style] ='display: none' unless @object[label]
	#
	#control_html = @template.content_tag('img', '', image_options) + '<br/>'.html_safe
	#
	#select_image_options =
	#	{
	#		href: "javascript:showImageSelectDialog('##{@object.class.for_form_params}_#{label}_imagesModal'); return false;"
	#	}
	#
	#control_html += @template.content_tag('a', select_image_options) do
	#	"Select Image"
	#end
	#
	#hidden_options = {
	#	type: 'hidden',
	#	id: "#{@object.class.for_form_params}_#{label}",
	#	name: "#{@object.class.for_form_params}[#{label}]"
	#}
	#
	#hidden_options[:value] = @object[label].to_s if @object[label]
	#
	#control_html += @template.content_tag('input', '', hidden_options)

	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.("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.("label", (@object.class.human_attribute_name(label) + @template.("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?
	#TODO: Add Mask Implementation for Control

	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 = {})
	#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?
	#
	#super(property.name, 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.('label', class: "radio") do
				@template.('div', class: "radio") do
					@template.('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.("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 ||= {}

	#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],
	#		parent_value: (@object[property.parent] if property.parent)
	#	}
	#)
	#html_options_add_class(html_options, ["error"]) if @object.errors[property.name].present?

	#select_tag(html_options[:choices], html_options)
	select_tag(property, @object, select_choices, html_options)
end

#switch_button(property, html_options = {}) ⇒ Object



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)

	#label = property.name.to_sym
	#html_options = args.extract_options!
	#html_options.stringify_keys!
	#
	#value_off = html_options['value-off'] || "0"
	#value_on = html_options['value-on'] || "1"
	#
	#off_input_options = {
	#	id: "#{@object.class.for_form_params}-#{label}-off",
	#	name: "#{@object.class.for_form_params}[#{label}]",
	#	type: "radio",
	#	value: value_off
	#}
	#on_input_options = {
	#	id: "#{@object.class.for_form_params}-#{label}-on",
	#	name: "#{@object.class.for_form_params}[#{label}]",
	#	type: "radio",
	#	value: value_on
	#}
	#
	#if @object[property.name] == true
	#	on_input_options['checked'] = true
	#else
	#	off_input_options['checked'] = true
	#end
	#
	#toggle_options = {}
	#
	#toggle_options[:class] = "toggle" + (@object[property.name] == value_on ? ' on' : ' off')
	##toggle_options[:class] = "toggle on"
	#
	#
	#@template.content_tag('div', class: "row-fluid") do
	#	@template.content_tag('div', class: "pull-left") do
	#		@template.content_tag('label', class: 'radio off') do
	#			@template.tag('input', off_input_options)
	#
	#		end +
	#			@template.content_tag('label', class: 'radio on') do
	#				@template.tag('input', on_input_options)
	#			end +
	#			@template.content_tag('div', toggle_options) do
	#				@template.content_tag('div', class: "yes") do
	#					html_options['label-on'] || 'ON'
	#				end +
	#					@template.content_tag('div', class: "switch") do
	#					end +
	#					@template.content_tag('div', class: "no") do
	#						html_options['label-off'] || 'OFF'
	#					end
	#			end
	#	end
	#end
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 = {})
	#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_area_tag(property, @object, html_options)

	#super(property.name, 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