Class: Formotion::Row
Constant Summary collapse
- PROPERTIES =
[ # @form.render will contain row's value as the value for this key. :key, # the user's (or configured) value for this row. :value, # set as cell.titleLabel.text :title, # set as cell.imageView.image :image, # an image placeholder for cell.imageView.image when using remote images :image_placeholder, # set as cell.detailLabel.text :subtitle, # configures the type of input this is (string, phone, switch, etc) # either Formotion::RowType or a string/symbol representation of one # see row_type.rb :type, # Stores possible date pickers mode; corresponds to UIDatePickerMode______ # OPTIONS: :time, :date, :date_time, :countdown # DEFAULT is :date :picker_mode, # Stores possible formatting information (used by date pickers, etc) # if :type == :date, accepts values in [:short, :medium, :long, :full] :format, # alternative title for row (only used in EditRow for now) :alt_title, # determines if the user can edit the row # OPTIONS: true, false # DEFAULT: true :editable, # The following apply only to text-input fields # text alignment of the input field # OPTIONS: :left, :right, :center # DEFAULT is :right :text_alignment, # placeholder text :placeholder, # accessibility label :accessibility, # whether or not the entry field is secure (like a password) :secure, # given by a UIReturnKey___ integer, string, or symbol # EX :default, :google :return_key, # given by a UITextAutocorrectionType___ integer, string, or symbol # EX :yes, :no, :default :auto_correction, # given by a UITextAutocapitalizationType___ integer, string, or symbol # EX :none, :words :auto_capitalization, # field.clearButtonMode; given by a UITextFieldViewMode__ integer, string, symbol # EX :never, :while_editing # DEFAULT is nil, which is used as :while_editing :clear_button, # row height as integer; used for heightForRowAtIndexPath # EX 200 # DEFAULT is nil, which is used as the tableView.row_height :row_height, # range used for slider min and max value # EX (1..100) # DEFAULT is (1..10) :range, # Array used for control row items # EX ['free', 'pro'] # DEFAULT is [] :items, # A hash for a Form used for subforms # DEFAULT is nil :subform, # Used in a subform row; when given, # will display the value of the matching key # of the subform's rendering. # DEFAULT is nil :display_key, # A hash for a Row used for templates # DEFAULT is nil :template, # Indents row when set to true # DEFAULT is false :indented, # Shows a delete sign next to the row # DEFAULT is false :deletable, # When a row is deleted, actually remove the row from UI # instead of just nil'ing the value. # DEFAULT is false EXCEPT for template-generated rows :remove_on_delete, # In a date/time or time picker, the minute interval can # be set. That allows picking by every 15 minutes, etc. :minute_interval, #-Resize image when needed (size as Array [1500,1500]) :max_image_size, # Font for String and Text rows :font, # Display an inputAccessoryView when editing a StringRow. # OPTIONS: :done (a black translucent toolbar with a right-aligned "Done" button) # DEFAULT is nil :input_accessory, # Cell selection style # OPTIONS: :blue, :gray, :none # DEFAULT is :blue :selection_style, # The following apply only to weblink rows # Whether or not to display a warning to the user before leaving the app. # DEFAULT is false :warn ]
- BOOLEAN_PROPERTIES =
[:secure, :indented, :deletable, :remove_on_delete]
- SERIALIZE_PROPERTIES =
PROPERTIES
Instance Attribute Summary collapse
-
#index ⇒ Object
Index of the row in the section.
-
#object ⇒ Object
RowType object.
-
#on_begin_callback ⇒ Object
callback for what happens when the user starts editing #text_field.
-
#on_delete_callback ⇒ Object
callback for when a row is tapped.
-
#on_end_callback ⇒ Object
callback for when a row is exited.
-
#on_enter_callback ⇒ Object
callback for what happens when the user hits the enter key while editing #text_field.
-
#on_tap_callback ⇒ Object
callback for what happens when the user taps a ButtonRow.
-
#reuse_identifier ⇒ Object
The reuse-identifier used in UITableViews By default is a stringification of section.index and row.index, thus is unique per row (bad for memory, to fix later.).
-
#section ⇒ Object
Reference to the row’s section.
-
#template_children ⇒ Object
Returns the value of attribute template_children.
-
#template_parent ⇒ Object
Owning template row, if applicable.
-
#text_field ⇒ Object
readonly
reference to the row’s UITextField.
Instance Method Summary collapse
-
#after_create ⇒ Object
called after section and index have been assigned.
- #auto_capitalization=(value) ⇒ Object
- #auto_correction=(value) ⇒ Object
- #button? ⇒ Boolean
- #clear_button=(value) ⇒ Object
- #editable=(editable) ⇒ Object
- #editable? ⇒ Boolean
- #form ⇒ Object
- #index_path ⇒ Object
-
#initialize(params = {}) ⇒ Row
constructor
A new instance of Row.
-
#items ⇒ Object
getter overrides.
-
#make_cell ⇒ Object
Methods for making cells Called in UITableViewDataSource methods in form_delegate.rb.
- #next_row ⇒ Object
- #on_begin(&block) ⇒ Object
- #on_delete(&block) ⇒ Object
- #on_end(&block) ⇒ Object
-
#on_enter(&block) ⇒ Object
setters for callbacks.
-
#on_tap(&block) ⇒ Object
Used in :button type rows.
- #previous_row ⇒ Object
- #range=(range) ⇒ Object
- #return_key=(value) ⇒ Object
- #selection_style=(style) ⇒ Object
- #subform=(subform) ⇒ Object
- #subform? ⇒ Boolean
- #templated? ⇒ Boolean
- #text_alignment=(alignment) ⇒ Object
-
#to_hash ⇒ Object
Retreiving data.
-
#type=(type) ⇒ Object
setter overrides.
-
#update_cell(cell) ⇒ Object
Called on every tableView:cellForRowAtIndexPath: so keep implementation details minimal.
-
#value_for_save_hash ⇒ Object
pseudo-properties.
Methods inherited from Base
#copyWithZone, #encodeWithCoder, #hash, #initWithCoder, #isEqual
Constructor Details
#initialize(params = {}) ⇒ Row
Returns a new instance of Row.
162 163 164 165 166 167 168 169 |
# File 'lib/formotion/row/row.rb', line 162 def initialize(params = {}) super BOOLEAN_PROPERTIES.each { |prop| Formotion::Conditions.assert_nil_or_boolean(self.send(prop)) } @template_children = [] end |
Instance Attribute Details
#index ⇒ Object
Index of the row in the section
129 130 131 |
# File 'lib/formotion/row/row.rb', line 129 def index @index end |
#object ⇒ Object
RowType object
156 157 158 |
# File 'lib/formotion/row/row.rb', line 156 def object @object end |
#on_begin_callback ⇒ Object
callback for what happens when the user starts editing #text_field.
146 147 148 |
# File 'lib/formotion/row/row.rb', line 146 def on_begin_callback @on_begin_callback end |
#on_delete_callback ⇒ Object
callback for when a row is tapped
151 152 153 |
# File 'lib/formotion/row/row.rb', line 151 def on_delete_callback @on_delete_callback end |
#on_end_callback ⇒ Object
callback for when a row is exited
153 154 155 |
# File 'lib/formotion/row/row.rb', line 153 def on_end_callback @on_end_callback end |
#on_enter_callback ⇒ Object
callback for what happens when the user hits the enter key while editing #text_field
143 144 145 |
# File 'lib/formotion/row/row.rb', line 143 def on_enter_callback @on_enter_callback end |
#on_tap_callback ⇒ Object
callback for what happens when the user taps a ButtonRow
149 150 151 |
# File 'lib/formotion/row/row.rb', line 149 def on_tap_callback @on_tap_callback end |
#reuse_identifier ⇒ Object
The reuse-identifier used in UITableViews By default is a stringification of section.index and row.index, thus is unique per row (bad for memory, to fix later.)
134 135 136 |
# File 'lib/formotion/row/row.rb', line 134 def reuse_identifier @reuse_identifier end |
#section ⇒ Object
Reference to the row’s section
126 127 128 |
# File 'lib/formotion/row/row.rb', line 126 def section @section end |
#template_children ⇒ Object
Returns the value of attribute template_children.
160 161 162 |
# File 'lib/formotion/row/row.rb', line 160 def template_children @template_children end |
#template_parent ⇒ Object
Owning template row, if applicable
159 160 161 |
# File 'lib/formotion/row/row.rb', line 159 def template_parent @template_parent end |
#text_field ⇒ Object (readonly)
reference to the row’s UITextField.
139 140 141 |
# File 'lib/formotion/row/row.rb', line 139 def text_field @text_field end |
Instance Method Details
#after_create ⇒ Object
called after section and index have been assigned
172 173 174 175 176 |
# File 'lib/formotion/row/row.rb', line 172 def after_create if self.type == :template self.object.update_template_rows end end |
#auto_capitalization=(value) ⇒ Object
270 271 272 |
# File 'lib/formotion/row/row.rb', line 270 def auto_capitalization=(value) @auto_capitalization = const_int_get("UITextAutocapitalizationType", value) end |
#auto_correction=(value) ⇒ Object
266 267 268 |
# File 'lib/formotion/row/row.rb', line 266 def auto_correction=(value) @auto_correction = const_int_get("UITextAutocorrectionType", value) end |
#button? ⇒ Boolean
220 221 222 |
# File 'lib/formotion/row/row.rb', line 220 def object. end |
#clear_button=(value) ⇒ Object
274 275 276 |
# File 'lib/formotion/row/row.rb', line 274 def (value) @clear_button = const_int_get("UITextFieldViewMode", value) end |
#editable=(editable) ⇒ Object
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/formotion/row/row.rb', line 286 def editable=(editable) case editable when TrueClass when FalseClass when NSNull editable = false when NilClass editable = false when NSString editable = (editable == "true") else raise Formotion::InvalidClassError, "Invalid class for `Row#editable`: #{editable.inspect}; should be TrueClass, FalseCLass, or NSString" end @editable = editable end |
#editable? ⇒ Boolean
302 303 304 305 306 307 |
# File 'lib/formotion/row/row.rb', line 302 def editable? if !self.editable.nil? return self.editable end true end |
#form ⇒ Object
193 194 195 |
# File 'lib/formotion/row/row.rb', line 193 def form self.section.form end |
#index_path ⇒ Object
189 190 191 |
# File 'lib/formotion/row/row.rb', line 189 def index_path NSIndexPath.indexPathForRow(self.index, inSection:self.section.index) end |
#items ⇒ Object
getter overrides
234 235 236 237 238 239 |
# File 'lib/formotion/row/row.rb', line 234 def items if @items.respond_to?(:call) @items = @items.call end @items end |
#make_cell ⇒ Object
Methods for making cells Called in UITableViewDataSource methods in form_delegate.rb
349 350 351 352 353 354 355 356 357 |
# File 'lib/formotion/row/row.rb', line 349 def make_cell if self.object.nil? raise Formotion::NoRowTypeError, "No row type specified for row #{self.index_path.row} in section #{self.index_path.section}; specify a :type" end cell, text_field = Formotion::RowCellBuilder.make_cell(self) @text_field = text_field self.object.after_build(cell) cell end |
#next_row ⇒ Object
201 202 203 204 205 206 207 208 209 |
# File 'lib/formotion/row/row.rb', line 201 def next_row # if there are more rows in this section, use that. return self.section.rows[self.index + 1] if self.index < (self.section.rows.count - 1) # if there are more sections, then use the first row of that section. return self.section.next_section.rows[0] if self.section.next_section nil end |
#on_begin(&block) ⇒ Object
316 317 318 |
# File 'lib/formotion/row/row.rb', line 316 def on_begin(&block) self.on_begin_callback = block end |
#on_delete(&block) ⇒ Object
335 336 337 338 339 340 341 342 343 |
# File 'lib/formotion/row/row.rb', line 335 def on_delete(&block) self.on_delete_callback = block # set on_tap for all template children if self.type == :template for templ in self.template_children do templ.on_delete_callback = block end end end |
#on_end(&block) ⇒ Object
320 321 322 |
# File 'lib/formotion/row/row.rb', line 320 def on_end(&block) self.on_end_callback = block end |
#on_enter(&block) ⇒ Object
setters for callbacks
312 313 314 |
# File 'lib/formotion/row/row.rb', line 312 def on_enter(&block) self.on_enter_callback = block end |
#on_tap(&block) ⇒ Object
Used in :button type rows
325 326 327 328 329 330 331 332 333 |
# File 'lib/formotion/row/row.rb', line 325 def on_tap(&block) self.on_tap_callback = block # set on_tap for all template children if self.type == :template for templ in self.template_children do templ.on_tap_callback = block end end end |
#previous_row ⇒ Object
211 212 213 214 215 216 217 218 |
# File 'lib/formotion/row/row.rb', line 211 def previous_row return self.section.rows[self.index - 1] if self.index > 0 # if there are more sections, then use the first row of that section. return self.section.previous_section.rows[-1] if self.section.previous_section nil end |
#range=(range) ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/formotion/row/row.rb', line 248 def range=(range) if range case range when Range # all good when Array range = Range.new(range[0], range[1]) else raise Formotion::InvalidClassError, "Attempted Row.range = #{range.inspect} should be of type Range or Array" end end @range = range end |
#return_key=(value) ⇒ Object
262 263 264 |
# File 'lib/formotion/row/row.rb', line 262 def return_key=(value) @return_key = const_int_get("UIReturnKey", value) end |
#selection_style=(style) ⇒ Object
282 283 284 |
# File 'lib/formotion/row/row.rb', line 282 def selection_style=(style) @selection_style = const_int_get("UITableViewCellSelectionStyle", style || :blue) end |
#subform=(subform) ⇒ Object
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File 'lib/formotion/row/row.rb', line 379 def subform=(subform) @subform = subform # enables you do to row.subform.to_form @subform.instance_eval do def to_form return @hash_subform if @hash_subform if self.is_a? Hash @hash_subform = Formotion::Form.new(self) elsif not self.is_a? Formotion::Form raise Formotion::InvalidClassError, "Attempted subform = '#{self.inspect}' should be of type Formotion::Form or Hash" end @hash_subform ||= self end end @subform end |
#subform? ⇒ Boolean
224 225 226 |
# File 'lib/formotion/row/row.rb', line 224 def subform? self.type.to_s == "subform" end |
#templated? ⇒ Boolean
228 229 230 |
# File 'lib/formotion/row/row.rb', line 228 def templated? !!self.template_parent end |
#text_alignment=(alignment) ⇒ Object
278 279 280 |
# File 'lib/formotion/row/row.rb', line 278 def text_alignment=(alignment) @text_alignment = const_int_get("NSTextAlignment", alignment) end |
#to_hash ⇒ Object
Retreiving data
368 369 370 371 372 373 374 375 376 377 |
# File 'lib/formotion/row/row.rb', line 368 def to_hash h = super if h[:range] && h[:range].is_a?(Range) h[:range] = [self.range.begin, self.range.end] end if subform? h[:subform] = self.subform.to_form.to_hash end h end |
#type=(type) ⇒ Object
setter overrides
243 244 245 246 |
# File 'lib/formotion/row/row.rb', line 243 def type=(type) @object = Formotion::RowType.for(type).new(self) @type = type end |
#update_cell(cell) ⇒ Object
Called on every tableView:cellForRowAtIndexPath: so keep implementation details minimal
361 362 363 364 |
# File 'lib/formotion/row/row.rb', line 361 def update_cell(cell) self.object.update_cell(cell) cell end |
#value_for_save_hash ⇒ Object
pseudo-properties
181 182 183 184 185 186 187 |
# File 'lib/formotion/row/row.rb', line 181 def value_for_save_hash if self.object.respond_to? :value_for_save_hash self.object.value_for_save_hash else self.value end end |