Class: FormSubmission
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from KitIndexed
do_indexing, indexed_columns, paginate
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'app/models/form_submission.rb', line 76
def method_missing(meth, *args, &block)
if meth =~ /^(.+)\=$/
field_name = $1
setter = true
else
field_name = meth setter = false
end
field_name = field_name.to_s if field_name.instance_of?(Symbol)
field_name.gsub!('_','-') if field_name
field_name = field_name.to_sym if field_name.instance_of?(String)
self.fields.each do |field|
next unless field.form_field
if setter && field.form_field.code_name.to_sym == field_name.to_sym
field.value = args[0]
field.save
return field.value
end
if !setter && field.form_field.code_name.to_sym == field_name
return field.value
end
end
super
end
|
Instance Attribute Details
#kit_session_id ⇒ Object
Returns the value of attribute kit_session_id.
19
20
21
|
# File 'app/models/form_submission.rb', line 19
def kit_session_id
@kit_session_id
end
|
Instance Method Details
#can_delete?(user) ⇒ Boolean
60
61
62
|
# File 'app/models/form_submission.rb', line 60
def can_delete?(user)
can_edit?(user)
end
|
#can_edit?(user) ⇒ Boolean
56
57
58
|
# File 'app/models/form_submission.rb', line 56
def can_edit?(user)
return can?('editable', user)
end
|
#can_see?(user) ⇒ Boolean
52
53
54
|
# File 'app/models/form_submission.rb', line 52
def can_see?(user)
return can?('visible', user)
end
|
#create_engagement ⇒ Object
48
49
50
|
# File 'app/models/form_submission.rb', line 48
def create_engagement
KitEngagement.create(:kit_session_id=>self.kit_session_id, :system_id=>self.system_id, :engage_type=>"Form Submission", :value=>"/admin/forms/#{self.id}/list") if self.kit_session_id
end
|
#field_by_name(name) ⇒ Object
72
73
74
|
# File 'app/models/form_submission.rb', line 72
def field_by_name(name)
self.fields.joins(:form_field).where("form_fields.code_name = '#{name}'").first
end
|
#field_value_by_id(id) ⇒ Object
68
69
70
|
# File 'app/models/form_submission.rb', line 68
def field_value_by_id(id)
self.fields.where(:form_field_id=>id).first.value
end
|
#fields ⇒ Object
64
65
66
|
# File 'app/models/form_submission.rb', line 64
def fields
self.form_submission_fields
end
|
#geo_code ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'app/models/form_submission.rb', line 23
def geo_code
first = true
self.form.form_fields.where("geo_code_from_fields is not null and geo_code_from_fields <> ''").order(:display_order).each do |geo_field|
entered_location = []
geo_field.geo_code_from_fields.split('|').each do |field_id|
entered_location << field_value_by_id(field_id)
end
location = Geocoder.search(entered_location.join(', '))
if location.size>0
location_field = FormSubmissionField.new(:form_field_id=>geo_field.id, :form_submission_id=>self.id, :system_id=>self.system_id)
location_field.value = location[0].address
location_field.lat = location[0].latitude
location_field.lon = location[0].longitude
location_field.save
if first
self.lat = location[0].latitude
self.lon = location[0].longitude
self.save
end
end
end
end
|