Module: CommonLib::ActionViewExtension::FormBuilder

Defined in:
lib/common_lib/action_view_extension/form_builder.rb

Instance Method Summary collapse

Instance Method Details

#adna_select(method, options = {}, html_options = {}) ⇒ Object



103
104
105
106
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 103

def adna_select(method,options={},html_options={})
	@template.select(object_name, method, ADNA.selector_options,
		{:include_blank => true}.merge(objectify_options(options)), html_options)
end

#date_text_field(method, options = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 43

def date_text_field(method, options = {})
	format = options.delete(:format) || '%m/%d/%Y'
	tmp_value = if options[:value].blank? #and !options[:object].nil?
#			object = options[:object]
		tmp = self.object.send("#{method}") ||
		      self.object.send("#{method}_before_type_cast")
	else
		options[:value]
	end
	begin
		options[:value] = tmp_value.to_date.try(:strftime,format)
	rescue NoMethodError, ArgumentError
		options[:value] = tmp_value
	end
	options.update(:class => [options[:class],'datepicker'].compact.join(' '))
	@template.text_field( object_name, method, options )
end

#datetime_text_field(method, options = {}) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 61

def datetime_text_field(method, options = {})
	format = options.delete(:format) || '%m/%d/%Y %H:%M'
	tmp_value = if options[:value].blank?
		tmp = self.object.send("#{method}") ||
		      self.object.send("#{method}_before_type_cast")
	else
		options[:value]
	end
	begin
		options[:value] = tmp_value.to_datetime.try(:strftime,format)
	rescue NoMethodError, ArgumentError
		options[:value] = tmp_value
	end
	options.update(:class => [options[:class],'datetimepicker'].compact.join(' '))
	@template.text_field( object_name, method, options )
end

#error_messagesObject



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 3

def error_messages
	if self.object.errors.count > 0
		s  = '<div id="errorExplanation" class="errorExplanation">'
		s << "<h2>#{self.object.errors.count} #{"error".pluralize(self.object.errors.count)} prohibited this #{self.object.class} from being saved:</h2>"
		s << '<p>There were problems with the following fields:</p>'
		s << '<ul>'
		self.object.errors.full_messages.each do |msg|
			s << "<li>#{msg}</li>"
		end
		s << '</ul></div>'
		s.html_safe
	end
end

#hour_select(method, options = {}, html_options = {}) ⇒ Object



17
18
19
20
21
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 17

def hour_select(method,options={},html_options={})
	@template.select(object_name, method,
		(1..12),
		{:include_blank => 'Hour'}.merge(options), html_options)
end

#meridiem_select(method, options = {}, html_options = {}) ⇒ Object



30
31
32
33
34
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 30

def meridiem_select(method,options={},html_options={})
	@template.select(object_name, method,
		['AM','PM'], 
		{:include_blank => 'Meridiem'}.merge(options), html_options)
end

#minute_select(method, options = {}, html_options = {}) ⇒ Object



23
24
25
26
27
28
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 23

def minute_select(method,options={},html_options={})
	minutes = (0..59).to_a.collect{|m|[sprintf("%02d",m),m]}
	@template.select(object_name, method,
		minutes,
		{:include_blank => 'Minute'}.merge(options), html_options)
end

#padk_select(method, options = {}, html_options = {}) ⇒ Object



98
99
100
101
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 98

def padk_select(method,options={},html_options={})
	@template.select(object_name, method, PADK.selector_options,
		{:include_blank => true}.merge(objectify_options(options)), html_options)
end

#pos_neg_select(method, options = {}, html_options = {}) ⇒ Object



108
109
110
111
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 108

def pos_neg_select(method, options={}, html_options={})
	@template.select(object_name, method, POSNEG.selector_options,
		{:include_blank => true}.merge(objectify_options(options)), html_options)
end

#sex_select(method, options = {}, html_options = {}) ⇒ Object Also known as: gender_select



36
37
38
39
40
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 36

def sex_select(method,options={},html_options={})
	@template.select(object_name, method,
		[['-select-',''],['male','M'],['female','F'],["don't know",'DK']],
		options, html_options)
end

#wrapped_check_box(*args, &block) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 113

def wrapped_check_box(*args,&block)
	method      = args[0]
	content = @template.field_wrapper(method,:class => 'check_box') do
		options    = args.detect{|i| i.is_a?(Hash) }
		label_text = options.delete(:label_text) unless options.nil?
		post_text  = options.delete(:post_text) unless options.nil?
#	INVERTED ORDER SO NOT INCLUDED BELOW
		s  = check_box(*args,&block) <<
			self.label( method, label_text )
		s << (( block_given? )? @template.capture(&block) : '')
		s << (( post_text.blank? ) ? '' : "<span>#{post_text}</span>".html_safe )
	end
	content.html_safe
end

#yndk_select(method, options = {}, html_options = {}) ⇒ Object



78
79
80
81
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 78

def yndk_select(method,options={},html_options={})
	@template.select(object_name, method, YNDK.selector_options,
		{:include_blank => true}.merge(objectify_options(options)), html_options)
end

#ynodk_select(method, options = {}, html_options = {}) ⇒ Object



88
89
90
91
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 88

def ynodk_select(method,options={},html_options={})
	@template.select(object_name, method, YNODK.selector_options,
		{:include_blank => true}.merge(objectify_options(options)), html_options)
end

#ynordk_select(method, options = {}, html_options = {}) ⇒ Object



93
94
95
96
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 93

def ynordk_select(method,options={},html_options={})
	@template.select(object_name, method, YNORDK.selector_options,
		{:include_blank => true}.merge(objectify_options(options)), html_options)
end

#ynrdk_select(method, options = {}, html_options = {}) ⇒ Object



83
84
85
86
# File 'lib/common_lib/action_view_extension/form_builder.rb', line 83

def ynrdk_select(method,options={},html_options={})
	@template.select(object_name, method, YNRDK.selector_options,
		{:include_blank => true}.merge(objectify_options(options)), html_options)
end