Class: Formotion::FormController

Inherits:
UITableViewController
  • Object
show all
Defined in:
lib/formotion/controller/form_controller.rb

Direct Known Subclasses

FormableController

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#formObject

Returns the value of attribute form.



12
13
14
# File 'lib/formotion/controller/form_controller.rb', line 12

def form
  @form
end

Instance Method Details

#initWithForm(form) ⇒ Object

Initializes controller with a form PARAMS form.is_a? [Hash, Formotion::Form] RETURNS An instance of Formotion::FormController



17
18
19
20
21
22
23
24
# File 'lib/formotion/controller/form_controller.rb', line 17

def initWithForm(form)
  self.initWithStyle(UITableViewStyleGrouped)
  self.form = form
  #self.view.setEditing true, animated: true
  self.tableView.allowsSelectionDuringEditing = true

  self
end

#pop_subformObject



72
73
74
75
76
77
78
# File 'lib/formotion/controller/form_controller.rb', line 72

def pop_subform
  if self.navigationController
    self.navigationController.popViewControllerAnimated true
  else
    self.dismissModalViewControllerAnimated true
  end
end

#push_subform(form) ⇒ Object

Subview Methods



62
63
64
65
66
67
68
69
70
# File 'lib/formotion/controller/form_controller.rb', line 62

def push_subform(form)
  @subform_controller = self.class.alloc.initWithForm(form)

  if self.navigationController
    self.navigationController.pushViewController(@subform_controller, animated: true)
  else
    self.presentModalViewController(@subform_controller, animated: true)
  end
end

#viewDidLoadObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/formotion/controller/form_controller.rb', line 37

def viewDidLoad
  super

  # Triggers this block when the enter key is pressed
  # while editing the last text field.
  @form.sections[-1] && @form.sections[-1].rows && @form.sections[-1].rows[-1] && @form.sections[-1].rows[-1].on_enter do |row|
    if row.text_field
      @form.submit
      row.text_field.resignFirstResponder
    end
  end

  # Setting @form.controller assigns
  # @form as the datasource and delegate
  # and reloads the data.
  @form.controller = WeakRef.new(self)
end

#viewWillAppear(animated) ⇒ Object



55
56
57
58
59
# File 'lib/formotion/controller/form_controller.rb', line 55

def viewWillAppear(animated)
  super

  self.tableView.reloadData
end