Class: ProMotion::XLFormScreen
Instance Attribute Summary collapse
Instance Method Summary
collapse
included
#class_handles_delegates?, #didRotateFromInterfaceOrientation, #init, #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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 142
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
160
161
162
163
164
165
166
167
168
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 160
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
|
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 35
def button_config(user_config, opts = {})
button_config = { action: opts[:action] }
if user_config.is_a? Hash
title = user_config[:title]
item = user_config[:item] || user_config[:system_item]
end
if title
button_config[:title] = title
else
button_config[:system_item] = item || opts[:default_item]
end
set_nav_bar_button :right, button_config
end
|
#cell_at_path(path) ⇒ Object
134
135
136
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 134
def cell_at_path(path)
self.form.formRowAtIndex(path)
end
|
#cell_with_tag(tag) ⇒ Object
127
128
129
130
131
132
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 127
def cell_with_tag(tag)
if tag.respond_to? :to_s
tag = tag.to_s
end
self.form.formRowWithTag(tag)
end
|
#dismiss_keyboard ⇒ Object
197
198
199
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 197
def dismiss_keyboard
self.view.endEditing true
end
|
#display_errors ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 94
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
188
189
190
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 188
def enabled=(value)
self.form.disabled = !value
end
|
#enabled? ⇒ Boolean
192
193
194
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 192
def enabled?
!self.form.isDisabled
end
|
52
53
54
55
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 52
def form_data
PM.logger.info "You need to implement a `form_data` method in #{self.class.to_s}."
[]
end
|
#reload(cell) ⇒ Object
138
139
140
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 138
def reload(cell)
reloadFormRow(cell)
end
|
#remove_cell!(cell) ⇒ Object
178
179
180
181
182
183
184
185
186
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 178
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
170
171
172
173
174
175
176
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 170
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
119
120
121
122
123
124
125
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 119
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
|
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 57
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
88
89
90
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 88
def valid?
validation_errors.empty?
end
|
#value_for_cell(tag) ⇒ Object
81
82
83
84
85
86
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 81
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
72
73
74
75
76
77
78
79
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 72
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
|
# File 'lib/ProMotion/XLForm/xl_form_screen.rb', line 8
def viewDidLoad
super
update_form_data
form_options = self.class.get_form_options
on_cancel = form_options[:on_cancel]
on_save = form_options[:on_save]
if on_cancel
set_nav_bar_button :left, button_config(on_cancel, default_item: :cancel, action: 'on_cancel:')
end
if on_save
set_nav_bar_button :right, button_config(on_save, default_item: :save, action: 'on_save:')
end
if self.class.respond_to?(:rmq_style_sheet_class) && self.class.rmq_style_sheet_class
self.tableView.rmq.apply_style(:form_view) if self.rmq.stylesheet.respond_to?(:form_view)
end
self.form_added if self.respond_to?(:form_added)
end
|