Class: ProMotion::XLFormScreen
Instance Attribute Summary collapse
Instance Method Summary
collapse
included
#class_handles_delegates?, #didRotateFromInterfaceOrientation, #loadView, new, #shouldAutorotate, #shouldAutorotateToInterfaceOrientation, #viewDidAppear, #viewDidDisappear, #viewWillAppear, #viewWillDisappear, #willRotateToInterfaceOrientation
Instance Attribute Details
Returns the value of attribute form_object.
6
7
8
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 6
def form_object
@form_object
end
|
Instance Method Details
#add_cell(cell, opts = {}) ⇒ Object
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 139
def add_cell(cell, opts={})
if opts[:before]
row = opts[:before]
if row.is_a?(Symbol)
row = cell_with_tag(row)
end
self.form.addFormRow(cell, beforeRow: row)
elsif opts[:after]
row = opts[:after]
if row.is_a?(Symbol)
row = cell_with_tag(row)
end
self.form.addFormRow(cell, afterRow: row)
else
mp "Don't know where to add cell, please provides either :before or :after", force_color: :red
end
end
|
#add_section(section, opts = {}) ⇒ Object
157
158
159
160
161
162
163
164
165
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 157
def add_section(section, opts={})
if opts[:index]
self.form.addFormSection(section, atIndex: opts[:index])
elsif opts[:after]
self.form.addFormSection(section, afterSection: opts[:after])
else
self.form.addFormSection(section)
end
end
|
#cell_at_path(path) ⇒ Object
131
132
133
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 131
def cell_at_path(path)
self.form.formRowAtIndex(path)
end
|
#cell_with_tag(tag) ⇒ Object
124
125
126
127
128
129
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 124
def cell_with_tag(tag)
if tag.respond_to? :to_s
tag = tag.to_s
end
self.form.formRowWithTag(tag)
end
|
#dismiss_keyboard ⇒ Object
194
195
196
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 194
def dismiss_keyboard
self.view.endEditing true
end
|
#display_errors ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 91
def display_errors
return if valid?
errors = validation_errors.map do |error|
error.localizedDescription
end
if NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1
alert = UIAlertController.alertControllerWithTitle(NSLocalizedString('Error', nil),
message: errors.join(', '),
preferredStyle: UIAlertControllerStyleAlert)
action = UIAlertAction.actionWithTitle(NSLocalizedString('OK', nil),
style: UIAlertActionStyleDefault,
handler: nil)
alert.addAction(action)
presentViewController(alert, animated: true, completion: nil)
else
alert = UIAlertView.new
alert.title = NSLocalizedString('Error', nil)
alert.message = errors.join(', ')
alert.addButtonWithTitle(NSLocalizedString('OK', nil))
alert.show
end
end
|
#enabled=(value) ⇒ Object
185
186
187
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 185
def enabled=(value)
self.form.disabled = !value
end
|
#enabled? ⇒ Boolean
189
190
191
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 189
def enabled?
!self.form.isDisabled
end
|
49
50
51
52
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 49
def form_data
PM.logger.info "You need to implement a `form_data` method in #{self.class.to_s}."
[]
end
|
#reload(cell) ⇒ Object
135
136
137
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 135
def reload(cell)
reloadFormRow(cell)
end
|
#remove_cell!(cell) ⇒ Object
175
176
177
178
179
180
181
182
183
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 175
def remove_cell!(cell)
if cell.is_a?(Symbol)
self.form.removeFormRowWithTag(cell.to_s)
elsif cell.is_a?(String)
self.form.removeFormRowWithTag(cell)
else
self.form.removeFormRow(cell)
end
end
|
#remove_section!(section_or_index) ⇒ Object
167
168
169
170
171
172
173
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 167
def remove_section!(section_or_index)
if section_or_index.is_a?(XLFormSectionDescriptor)
self.form.removeFormSection(section_or_index)
else
self.form.removeFormSectionAtIndex(section_or_index)
end
end
|
#section_with_tag(tag) ⇒ Object
116
117
118
119
120
121
122
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 116
def section_with_tag(tag)
if tag.respond_to? :to_s
tag = tag.to_s
end
self.form.formSections.select { |section| section.multivaluedTag && section.multivaluedTag == tag }
.first
end
|
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 54
def update_form_data
form_options = self.class.get_form_options
title = self.class.title
required = form_options[:required]
auto_focus = form_options[:auto_focus]
@form_builder = PM::XLForm.new(self.form_data,
title: title,
required: required,
auto_focus: auto_focus
)
@form_object = @form_builder.build
self.form = @form_object
end
|
#valid? ⇒ Boolean
85
86
87
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 85
def valid?
validation_errors.empty?
end
|
#value_for_cell(tag) ⇒ Object
78
79
80
81
82
83
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 78
def value_for_cell(tag)
if tag.respond_to?(:to_s)
tag = tag.to_s
end
values.has_key?(tag) ? values[tag] : nil
end
|
#values ⇒ Object
69
70
71
72
73
74
75
76
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 69
def values
values = {}
formValues.each do |key, value|
values[key] = clean_value(value)
end
values
end
|
#viewDidLoad ⇒ Object
8
9
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
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 8
def viewDidLoad
super
update_form_data
form_options = self.class.get_form_options
if form_options[:on_cancel]
on_cancel = form_options[:on_cancel]
title = NSLocalizedString('Cancel', nil)
item = :cancel
if on_cancel.is_a? Hash
title = on_cancel[:title] if on_cancel[:title]
item = on_cancel[:item] if on_cancel[:item]
end
set_nav_bar_button :left, {
system_item: item,
title: title,
action: 'on_cancel:'
}
end
if form_options[:on_save]
on_cancel = form_options[:on_save]
title = NSLocalizedString('Save', nil)
item = :save
if on_cancel.is_a? Hash
title = on_cancel[:title] if on_cancel[:title]
item = on_cancel[:item] if on_cancel[:item]
end
set_nav_bar_button :right, {
system_item: item,
title: title,
action: 'on_save:'
}
end
self.form_added if self.respond_to?(:form_added)
end
|