Module: KirguduBase::GuiHelper

Included in:
AdminController, CabinetController, FacadeController, FormBuilder, OldFormBuilder
Defined in:
app/helpers/kirgudu_base/gui_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_value_for_control(property, data_source) ⇒ Object



616
617
618
619
620
621
622
623
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 616

def self.get_value_for_control(property, data_source)
	if data_source.is_a?(Hash)
		#raise "Data Source from HASH: #{data_source.to_json}"
		data_source[property.name]
	else
		data_source.send(property.name)
	end
end

.html_options_add_class(html_options, classes_to_add) ⇒ Object



576
577
578
579
580
581
582
583
584
585
586
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 576

def self.html_options_add_class(html_options, classes_to_add)
	classes = html_options[:class] ? html_options[:class].split(' ') : []
	if classes_to_add.is_a?(Array)
		classes_to_add.each do |item|
			classes << item.to_s unless classes.include?(item.to_s)
		end
	else
		classes << classes_to_add.to_s unless classes.include?(classes_to_add.to_s)
	end
	html_options[:class] = classes.join(" ") if classes.length > 0
end

.html_options_prepare_commons(html_options, property, data_source) ⇒ Object



625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 625

def self.html_options_prepare_commons(html_options, property, data_source)

	control_value = ::KirguduBase::GuiHelper.get_value_for_control(property, data_source)

	html_options.merge!(property.html_options) if property.html_options

	html_options.merge!(
		value: control_value,
		:"property-name" => property.name,
		:"property-value" => control_value,
		:"parent-property" => (property.parent if property.parent),
		:"placeholder" => (property.i18n_data_as_string(:placeholder) if property.placeholder)
	)

	# Adding to control attribute value: class = 'error' if error
	if data_source.respond_to?(:errors) && data_source.errors.is_a?(Hash)
		::KirguduBase::GuiHelper.html_options_add_class(html_options, ["error"]) if data_source.errors[property.name].present?
	end

	::KirguduBase::GuiHelper.html_options_set_ids(html_options, property, data_source)
end

.html_options_set_ids(html_options, property, data_source) ⇒ Object



589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 589

def self.html_options_set_ids(html_options, property, data_source)
	if data_source.is_a?(Hash)
		html_options.merge!(
			{
				id: property.name,
				name: property.name
			}
		)
	elsif data_source.class.respond_to?(:for_form_params)
		html_options.merge!(
			{
				id: "#{data_source.class.for_form_params}_#{property.name}",
				name: "#{data_source.class.for_form_params}[#{property.name}]"
			}
		)
	else
		for_form_params = data_source.class.to_s.underscore.gsub('/', '_')

		html_options.merge!(
			{
				id: "#{for_form_params}_#{property.name}",
				name: "#{for_form_params}[#{property.name}]"
			}
		)
	end
end

Instance Method Details

#autocomplete_field_tag(property, data_source, html_options = {}) ⇒ Object



157
158
159
160
161
162
163
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 157

def autocomplete_field_tag(property, data_source, html_options = {})
	html_options ||= {}

	html_options_add_class(html_options, "error") if @object.errors[property.name].present?

	#ToDo: Fix it
end

#autocomplete_with_id_tag(property, data_source, html_options = {}) ⇒ Object



166
167
168
169
170
171
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
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 166

def autocomplete_with_id_tag(property, data_source, html_options = {})

	html_options ||= {}


	label_value = if data_source.is_a?(Hash)
		              data_source[property.text_value_property]
		          else
			          data_source.send(property.text_value_property)
		          end

	html_options.merge!(property.html_options) if property.html_options
	html_options.merge!(
		{
			:"value-property" => property.data_source.value_property,
			:"label-property" => property.data_source.label_property,
			url: property.data_source.url,
			label: label_value
		}
	)

	::KirguduBase::GuiHelper.html_options_add_class(html_options, "autocomplete-with-id")

	::KirguduBase::GuiHelper.html_options_prepare_commons(html_options, property, data_source)

	html_options[:"control-type"] = "autocomplete-with-id"
	html_options[:type] = "hidden"

	#raise "HTML OPTIONS in autocomplete: #{html_options.to_json}"

	("input", nil, html_options)
end

#chosen_select_tag(property, data_source, choices_data, html_options = {}) ⇒ Object



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
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
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 232

def chosen_select_tag(property, data_source, choices_data, html_options = {})
	#options = {}.merge(params)
	#options[:id] = SecureRandom.uuid.underscore unless options[:id]
	#
	#classes = options[:class] ? options[:class].to_s.split(' ') : []
	#classes.push ("chzn-select") unless classes.include?("chzn-select")
	#options[:class] = classes.join(' ')
	#options[:'control-type'] = "chosen-select"
	#
	#if options[:placeholder]
	#	options[:"data-placeholder"] = options[:placeholder]
	#	options[:placeholder] = nil
	#end
	#
	######################## BUILDING ONCHANGE COMMANDS #####################
	#
	#if options[:onchange]
	#	options[:onchange] = options[:onchange].to_json
	#end
	#
	##if options[:onchange]
	##	commands_set = []
	##	if options[:onchange].is_a?(Hash)
	##		commands_set.push(options[:onchange])
	##	elsif options[:onchange].is_a?(Array)
	##		options[:onchange].each do |command|
	##			if command.is_a?(Hash)
	##				commands_set.push(command)
	##			end
	##		end
	##	end
	##
	##	commands_set.each do |cmd_options|
	##		cmd_options[:id] = "#{options[:id]}_onchange_action"
	##		cmd_options[:style] = "display: none;"
	##		result += content_tag("div", "", cmd_options)
	##	end
	##end
	#
	#
	############################## BUILDING CHOICES #########################
	#
	#choices_html = ""
	#if choices && choices.is_a?(Array)
	#
	#	if options[:parent]
	#		if options[:parent_value].nil?
	#			options[:disabled] = "disabled"
	#		end
	#	end
	#
	#	choices_html = content_tag('option', '', value: '')
	#	choices.each do |chs|
	#		choice_id = chs[1]
	#		choice_label = chs[0]
	#		choice_attributes = Hash.new
	#		choice_attributes[:value] = choice_id
	#		if options[:value]
	#			choice_attributes[:selected] = "selected" if choice_id.to_s == options[:value].to_s
	#		end
	#
	#		choices_html += content_tag('option', choice_label, choice_attributes)
	#	end
	#else
	#	options[:disabled] = "disabled"
	#end
	#
	#
	#content_tag('select', choices_html.html_safe, options)

	html_options ||= {}
	::KirguduBase::GuiHelper.html_options_add_class(html_options, ["chzn-select"])
	html_options[:'control-type'] = 'chosen-select'

	select_tag(property, data_source, choices_data, html_options)
end

#control_tag(property, data_source, additional_data, html_options = {}) ⇒ Object



10
11
12
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
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 10

def control_tag(property, data_source, additional_data, html_options = {})

	if property.input_type == :chosen_select
		chosen_select_tag(property, data_source, additional_data, html_options)
	elsif property.input_type == :select
		select_tag(property, data_source, additional_data, html_options)
	elsif property.input_type == :autocomplete_with_id
		autocomplete_with_id_tag(property, data_source, html_options)
	elsif property.input_type == :autocomplete
		#autocomplete(property, html_options)


	elsif property.input_type == :switch_button
		switch_button_tag(property, data_source, html_options)

	elsif property.input_type == :date_picker
		#date_picker_tag(property, html_options)

	elsif property.input_type == :time_picker
		time_picker_tag(property, data_source, html_options)

	elsif property.input_type == :image_selector
		image_selector_tag(property, data_source, html_options)

	elsif property.input_type == :check_box
		check_box_tag(property, data_source, html_options)

	elsif property.input_type == :radio_button
		#radio_button(property, html_options)

	elsif property.input_type == :link
		link_tag(property, data_source, html_options)

	elsif property.input_type == :elastic_text_area
		elastic_textarea_tag(property, data_source, html_options)

	elsif property.input_type == :password
		elastic_textarea_tag(property, data_source, html_options)

	elsif property.input_type == :text_area
		text_area_tag(property, data_source, html_options)

	elsif property.input_type == :file_input
		#file_input(property, data_source, html_options)
	elsif property.input_type == :collection_check_boxes

	else
		text_field_tag(property, data_source, html_options)
	end
end

#date_picker_tag(property, data_source, html_options = {}) ⇒ Object



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 215

def date_picker_tag(property, data_source, html_options={})
	html_options ||= {}

	::KirguduBase::GuiHelper.html_options_prepare_commons(html_options, property, data_source)

	::KirguduBase::GuiHelper.html_options_add_class(html_options, ["date-picker"])

	html_options[:"data-date-format"] = "dd-mm-yyyy" #ToDo: Fix for all date formats
	html_options[:type] = "text"
	html_options[:"control-type"] = "date-picker"

	html_options[:id] = SecureRandom.uuid.underscore unless html_options[:id]

	("input", '', html_options)
end

#file_input_tag(property, data_source, html_options = {}) ⇒ Object



200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 200

def file_input_tag(property, data_source, html_options={})
	html_options ||= {}

	::KirguduBase::GuiHelper.html_options_prepare_commons(html_options, property, data_source)


	html_options[:type] = "file"
	html_options[:"control-type"] = "file-input"

	html_options[:id] = SecureRandom.uuid.underscore unless html_options[:id]

	("input", '', html_options)
end

#left_menu_item_disabled(text, image_path) ⇒ Object



395
396
397
398
399
400
401
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 395

def left_menu_item_disabled(text, image_path)
	raise "Stale method: 'left_menu_item_disabled'"
	('li') do
		tag('img', src: image_path, width: "16", height: "16", valign: "middle") +
			text
	end
end

#left_menu_item_dividerObject



383
384
385
386
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 383

def left_menu_item_divider
	raise "Stale method: 'left_menu_item_divider'"
	('li', "", class: "divider")
end


371
372
373
374
375
376
377
378
379
380
381
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 371

def left_menu_item_link(text, path, image_path, html_options = {})
	raise "Stale method: 'left_menu_item_link'"
	is_active = "current" if current_page?(path)

	('li', class: is_active) do
		("a", href: path, target: options[:target]) do
			tag('img', src: image_path, width: "16", height: "16", valign: "middle") +
				text
		end
	end
end

#left_menu_item_title(title) ⇒ Object



388
389
390
391
392
393
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 388

def left_menu_item_title(title)
	raise "Stale method: 'left_menu_item_title'"
	('li', class: "menuText") do
		"#{title}:"
	end
end


508
509
510
511
512
513
514
515
516
517
518
519
520
521
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 508

def link_to_cart_add(*args, &block)
	raise "Stale method: 'link_to_cart_add'"
	if block_given?
		options = args.first || {}
		html_options = args.second
		link_to_cart_add(capture(&block), options, html_options)
	else
		name = args[0]
		options = args[1] || {}
		html_options = args[2] || {}
		html_options['link-type'] = 'cart-add'
		link_to_nav1(name, options, html_options)
	end
end


523
524
525
526
527
528
529
530
531
532
533
534
535
536
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 523

def link_to_cart_remove(*args, &block)
	raise "Stale method: 'link_to_cart_remove'"
	if block_given?
		options = args.first || {}
		html_options = args.second
		link_to_cart_remove(capture(&block), options, html_options)
	else
		name = args[0]
		options = args[1] || {}
		html_options = args[2] || {}
		html_options['link-type'] = 'cart-add'
		link_to_nav1(name, options, html_options)
	end
end


491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 491

def link_to_delete(*args, &block)
	raise "Stale method: 'link_to_delete'"
	if block_given?
		options = args.first || {}
		html_options = args.second
		link_to_delete(capture(&block), options, html_options)
	else
		name = args[0]
		options = args[1] || {}
		html_options = args[2] || {}
		html_options['link-type'] = 'delete'
		html_options['http-method'] = 'delete'
		html_options['confirm-message'] = 'Are You sure You want to delete This Object?'
		link_to_nav1(name, options, html_options)
	end
end


461
462
463
464
465
466
467
468
469
470
471
472
473
474
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 461

def link_to_edit(*args, &block)
	raise "Stale method: 'link_to_edit'"
	if block_given?
		options = args.first || {}
		html_options = args.second
		link_to_edit(capture(&block), options, html_options)
	else
		name = args[0]
		options = args[1] || {}
		html_options = args[2] || {}
		html_options['link-type'] = 'edit'
		link_to_nav1(name, options, html_options)
	end
end

#link_to_entry(body, opts = {}, html_options = {}) ⇒ Object



404
405
406
407
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 404

def link_to_entry(body, opts = {}, html_options = {})
	raise "Stale method: 'link_to_entry'"
	link_to body, url_for(:params => build_query_string_params(request.params, opts)), html_options
end


553
554
555
556
557
558
559
560
561
562
563
564
565
566
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 553

def link_to_leftmenu(*args, &block)
	raise "Stale method: 'link_to_leftmenu'"
	if block_given?
		options = args.first || {}
		html_options = args.second
		link_to_leftmenu(capture(&block), options, html_options)
	else
		name = args[0]
		options = args[1] || {}
		html_options = args[2] || {}
		html_options['link-type'] = 'left-menu'
		link_to_nav1(name, options, html_options)
	end
end


538
539
540
541
542
543
544
545
546
547
548
549
550
551
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 538

def link_to_mass(*args, &block)
	raise "Stale method: 'link_to_mass'"
	if block_given?
		options = args.first || {}
		html_options = args.second
		link_to_mass(capture(&block), options, html_options)
	else
		name = args[0]
		options = args[1] || {}
		html_options = args[2] || {}
		html_options['link-type'] = 'mass-action'
		link_to_nav1(name, options, html_options)
	end
end


568
569
570
571
572
573
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 568

def link_to_nav(label, url, html_options = {})
	raise "Stale method: 'link_to_nav'"
	html_options ||= {}
	::KirguduBase::GuiHelper.html_options_add_class(html_options, "navigate-link")
	link_to label, url, html_options
end


476
477
478
479
480
481
482
483
484
485
486
487
488
489
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 476

def link_to_new(*args, &block)
	raise "Stale method: 'link_to_new'"
	if block_given?
		options = args.first || {}
		html_options = args.second
		link_to_new(capture(&block), options, html_options)
	else
		name = args[0]
		options = args[1] || {}
		html_options = args[2] || {}
		html_options['link-type'] = 'new'
		link_to_nav1(name, options, html_options)
	end
end


415
416
417
418
419
420
421
422
423
424
425
426
427
428
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 415

def link_to_paged(*args, &block)
	raise "Stale method: 'link_to_paged'"
	if block_given?
		options = args.first || {}
		html_options = args.second
		link_to_paged(capture(&block), options, html_options)
	else
		name = args[0]
		options = args[1] || {}
		html_options = args[2] || {}
		html_options['link-type'] = 'paged'
		link_to_nav1(name, options, html_options)
	end
end


350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 350

def link_to_property(property, entry, html_options = {})
	html_options ||= {}
	if property.target
		if property.target == :blank
			html_options[:target] = "_blank"
		elsif property.target == :hover_preview

		elsif property.target == :model_dialog

		end
	end
	html_options[:"control-type"] = "link"
	html_options[:"link-target"] = property.target if property.target
	link_value = entry.send(property.name)
	link_label = property.i18n_data_as_string(:placeholder) || link_value

	link_to(link_label, link_value, html_options) unless link_value.nil? && link_value.blank?

end


445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 445

def link_to_search(*args, &block)
	raise "Stale method: 'link_to_search'"
	if block_given?
		options = args.first || {}
		html_options = args.second
		link_to_search(capture(&block), options, html_options)
	else
		name = args[0]
		options = args[1] || {}
		html_options = args[2] || {}
		html_options['link-type'] = 'search'
		link_to_nav1(name, options, html_options)
	end

end


430
431
432
433
434
435
436
437
438
439
440
441
442
443
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 430

def link_to_show(*args, &block)
	raise "Stale method: 'link_to_show'"
	if block_given?
		options = args.first || {}
		html_options = args.second
		link_to_show(capture(&block), options, html_options)
	else
		name = args[0]
		options = args[1] || {}
		html_options = args[2] || {}
		html_options['link-type'] = 'show'
		link_to_nav1(name, options, html_options)
	end
end

#link_to_unless_current_entry(body, opts = {}, html_options = {}) ⇒ Object



409
410
411
412
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 409

def link_to_unless_current_entry(body, opts = {}, html_options = {})
	raise "Stale method: 'link_to_unless_current_entry'"
	link_to_unless_current body, url_for(:params => build_query_string_params(request.params, opts)), html_options
end

#password_field_tag(property, data_source, html_options = {}) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 91

def password_field_tag(property, data_source, html_options = {})
	html_options ||= {}

	::KirguduBase::GuiHelper.html_options_prepare_commons(html_options, property, data_source)

	html_options.merge!({
		                    type: "password",
		                    :"control-type" => "password-field"
	                    })


	html_options[:id] = SecureRandom.uuid.underscore unless html_options[:id]

	("input", '', html_options)
end

#select_tag(property, data_source, choices_data, html_options = {}) ⇒ Object



310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 310

def select_tag(property, data_source, choices_data, html_options = {})

	html_options ||= {}

	control_value = ::KirguduBase::GuiHelper.get_value_for_control(property, data_source)

	html_options[:'control-type'] ||= 'select'

	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

	choices_html = ("option", property.i18n_data_as_string(:placeholder) || "", value: "")
	choices_data.each do |chs|
		choice_id = chs[1]
		choice_label = chs[0]
		choice_attributes = {
			value: choice_id
		}

		choice_attributes[:selected] = "selected" if control_value && choice_id.to_s == control_value.to_s

		choices_html += ("option", choice_label, choice_attributes)
	end if choices_data

	::KirguduBase::GuiHelper.html_options_prepare_commons(html_options, property, data_source)

	html_options[:id] = SecureRandom.uuid.underscore unless html_options[:id]

	("select", choices_html.html_safe, html_options)
end

#switcher_tag(label, data, *args) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 108

def switcher_tag(label, data, *args)
	options = args.extract_options!
	options ||= {}
	options.symbolize_keys!

	value_off = options[:'value-off'] || "0"
	value_on = options[:'value-on'] || "1"

	off_input_options = {type: "radio", name: "#{label}", id: "#{label}-off", value: value_off, control_type: "switcher"}
	on_input_options = {type: "radio", name: "#{label}", id: "#{label}-on", value: value_on, control_type: "switcher"}

	if data == true
		on_input_options[:'checked'] = true
	else
		off_input_options[:'checked'] = true
	end

	toggle_options = {}

	toggle_options[:class] = "toggle" + (data == value_on ? ' on' : ' off')
	toggle_options[:class] = "toggle on"


	control_html =
		('div', class: "row-fluid") do
			('div', class: "pull-left") do
				('label', class: 'radio off') do
					tag('input', off_input_options)

				end +
					('label', class: 'radio on') do
						tag('input', on_input_options)
					end +
					('div', toggle_options) do
						('div', class: "yes") do
							options['label-on'] || 'ON'
						end +
							('div', class: "switch") do
							end +
							('div', class: "no") do
								options['label-off'] || 'OFF'
							end
					end
			end
		end
	control_html
end

#text_area_tag(property, data_source, html_options = {}) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 76

def text_area_tag(property, data_source, html_options = {})
	html_options ||= {}

	::KirguduBase::GuiHelper.html_options_prepare_commons(html_options, property, data_source)

	html_options[:id] = SecureRandom.uuid.underscore unless html_options[:id]
	html_options[:"control-type"] = "text-area"
	control_value = html_options[:value]
	html_options[:value] = nil
	html_options[:"property-value"] = nil

	("textarea", control_value, html_options)
end

#text_field_tag(property, data_source, html_options = {}) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/helpers/kirgudu_base/gui_helper.rb', line 62

def text_field_tag(property, data_source, html_options = {})
	html_options ||= {}

	::KirguduBase::GuiHelper.html_options_prepare_commons(html_options, property, data_source)

	html_options[:id] = SecureRandom.uuid.underscore unless html_options[:id]
	html_options.merge!({
		                    type: "text",
		                    :"control-type" => "text-field"
	                    })
	("input", '', html_options)
end