Class: ProMotion::XLForm

Inherits:
Object
  • Object
show all
Includes:
XLFormCellBuilder, XLFormHelper, XLFormSectionBuilder
Defined in:
lib/ProMotion/XLForm/xl_form.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from XLFormSectionBuilder

#create_section

Methods included from XLFormCellBuilder

#create_cell, #text_alignment

Methods included from XLFormHelper

#configure_hidden

Constructor Details

#initialize(form_data, opts = {}) ⇒ XLForm

Returns a new instance of XLForm.



10
11
12
13
14
15
# File 'lib/ProMotion/XLForm/xl_form.rb', line 10

def initialize(form_data, opts={})
  @form_data = form_data
  @title = opts[:title] || ''
  @required = opts[:required]
  @auto_focus = opts[:auto_focus]
end

Instance Attribute Details

#form_dataObject (readonly)

Returns the value of attribute form_data.



8
9
10
# File 'lib/ProMotion/XLForm/xl_form.rb', line 8

def form_data
  @form_data
end

Instance Method Details

#buildObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ProMotion/XLForm/xl_form.rb', line 17

def build
  form = XLFormDescriptor.formDescriptorWithTitle(@title)
  form.addAsteriskToRequiredRowsTitle = (@required == :asterisks)


  # focus on this cell
  if @auto_focus
    form.assignFirstResponderOnShow = true
  end

  form_data.each do |section_data|
    section = create_section(section_data)
    form.addFormSection(section)
  end

  form
end

#get_callback(descriptor, event) ⇒ Object



35
36
37
38
39
40
# File 'lib/ProMotion/XLForm/xl_form.rb', line 35

def get_callback(descriptor, event)
  tag = descriptor.respond_to?(:multivaluedTag) ? descriptor.multivaluedTag : descriptor.tag
  return if @blocks.nil? || @blocks[tag].nil? || @blocks[tag][event].nil?

  @blocks[tag][event]
end