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.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 ]
- 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_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_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.
150 151 152 153 154 155 156 157 |
# File 'lib/formotion/row/row.rb', line 150 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
119 120 121 |
# File 'lib/formotion/row/row.rb', line 119 def index @index end |
#object ⇒ Object
RowType object
144 145 146 |
# File 'lib/formotion/row/row.rb', line 144 def object @object end |
#on_begin_callback ⇒ Object
callback for what happens when the user starts editing #text_field.
136 137 138 |
# File 'lib/formotion/row/row.rb', line 136 def on_begin_callback @on_begin_callback end |
#on_delete_callback ⇒ Object
callback for when a row is tapped
141 142 143 |
# File 'lib/formotion/row/row.rb', line 141 def on_delete_callback @on_delete_callback end |
#on_enter_callback ⇒ Object
callback for what happens when the user hits the enter key while editing #text_field
133 134 135 |
# File 'lib/formotion/row/row.rb', line 133 def on_enter_callback @on_enter_callback end |
#on_tap_callback ⇒ Object
callback for what happens when the user taps a ButtonRow
139 140 141 |
# File 'lib/formotion/row/row.rb', line 139 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.)
124 125 126 |
# File 'lib/formotion/row/row.rb', line 124 def reuse_identifier @reuse_identifier end |
#section ⇒ Object
Reference to the row’s section
116 117 118 |
# File 'lib/formotion/row/row.rb', line 116 def section @section end |
#template_children ⇒ Object
Returns the value of attribute template_children.
148 149 150 |
# File 'lib/formotion/row/row.rb', line 148 def template_children @template_children end |
#template_parent ⇒ Object
Owning template row, if applicable
147 148 149 |
# File 'lib/formotion/row/row.rb', line 147 def template_parent @template_parent end |
#text_field ⇒ Object (readonly)
reference to the row’s UITextField.
129 130 131 |
# File 'lib/formotion/row/row.rb', line 129 def text_field @text_field end |
Instance Method Details
#after_create ⇒ Object
called after section and index have been assigned
160 161 162 163 164 |
# File 'lib/formotion/row/row.rb', line 160 def after_create if self.type == :template self.object.update_template_rows end end |
#auto_capitalization=(value) ⇒ Object
258 259 260 |
# File 'lib/formotion/row/row.rb', line 258 def auto_capitalization=(value) @auto_capitalization = const_int_get("UITextAutocapitalizationType", value) end |
#auto_correction=(value) ⇒ Object
254 255 256 |
# File 'lib/formotion/row/row.rb', line 254 def auto_correction=(value) @auto_correction = const_int_get("UITextAutocorrectionType", value) end |
#button? ⇒ Boolean
208 209 210 |
# File 'lib/formotion/row/row.rb', line 208 def object. end |
#clear_button=(value) ⇒ Object
262 263 264 |
# File 'lib/formotion/row/row.rb', line 262 def (value) = const_int_get("UITextFieldViewMode", value) end |
#editable=(editable) ⇒ Object
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/formotion/row/row.rb', line 274 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
290 291 292 293 294 295 |
# File 'lib/formotion/row/row.rb', line 290 def editable? if !self.editable.nil? return self.editable end true end |
#form ⇒ Object
181 182 183 |
# File 'lib/formotion/row/row.rb', line 181 def form self.section.form end |
#index_path ⇒ Object
177 178 179 |
# File 'lib/formotion/row/row.rb', line 177 def index_path NSIndexPath.indexPathForRow(self.index, inSection:self.section.index) end |
#items ⇒ Object
getter overrides
222 223 224 225 226 227 |
# File 'lib/formotion/row/row.rb', line 222 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
333 334 335 336 337 338 339 340 341 |
# File 'lib/formotion/row/row.rb', line 333 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
189 190 191 192 193 194 195 196 197 |
# File 'lib/formotion/row/row.rb', line 189 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
304 305 306 |
# File 'lib/formotion/row/row.rb', line 304 def on_begin(&block) self.on_begin_callback = block end |
#on_delete(&block) ⇒ Object
319 320 321 322 323 324 325 326 327 |
# File 'lib/formotion/row/row.rb', line 319 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_enter(&block) ⇒ Object
setters for callbacks
300 301 302 |
# File 'lib/formotion/row/row.rb', line 300 def on_enter(&block) self.on_enter_callback = block end |
#on_tap(&block) ⇒ Object
Used in :button type rows
309 310 311 312 313 314 315 316 317 |
# File 'lib/formotion/row/row.rb', line 309 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
199 200 201 202 203 204 205 206 |
# File 'lib/formotion/row/row.rb', line 199 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
236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/formotion/row/row.rb', line 236 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
250 251 252 |
# File 'lib/formotion/row/row.rb', line 250 def return_key=(value) @return_key = const_int_get("UIReturnKey", value) end |
#selection_style=(style) ⇒ Object
270 271 272 |
# File 'lib/formotion/row/row.rb', line 270 def selection_style=(style) @selection_style = const_int_get("UITableViewCellSelectionStyle", style || :blue) end |
#subform=(subform) ⇒ Object
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
# File 'lib/formotion/row/row.rb', line 363 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
212 213 214 |
# File 'lib/formotion/row/row.rb', line 212 def subform? self.type.to_s == "subform" end |
#templated? ⇒ Boolean
216 217 218 |
# File 'lib/formotion/row/row.rb', line 216 def templated? !!self.template_parent end |
#text_alignment=(alignment) ⇒ Object
266 267 268 |
# File 'lib/formotion/row/row.rb', line 266 def text_alignment=(alignment) @text_alignment = const_int_get("UITextAlignment", alignment) end |
#to_hash ⇒ Object
Retreiving data
352 353 354 355 356 357 358 359 360 361 |
# File 'lib/formotion/row/row.rb', line 352 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
231 232 233 234 |
# File 'lib/formotion/row/row.rb', line 231 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
345 346 347 348 |
# File 'lib/formotion/row/row.rb', line 345 def update_cell(cell) self.object.update_cell(cell) cell end |
#value_for_save_hash ⇒ Object
pseudo-properties
169 170 171 172 173 174 175 |
# File 'lib/formotion/row/row.rb', line 169 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 |