Class: ProMotion::XLForm
- Inherits:
-
Object
- Object
- ProMotion::XLForm
- Defined in:
- lib/ProMotion/XLForm/xl_form.rb
Instance Attribute Summary collapse
-
#form_data ⇒ Object
readonly
Returns the value of attribute form_data.
Instance Method Summary collapse
- #build ⇒ Object
- #get_callback(row, event) ⇒ Object
-
#initialize(form_data, opts = {}) ⇒ XLForm
constructor
A new instance of XLForm.
Constructor Details
#initialize(form_data, opts = {}) ⇒ XLForm
Returns a new instance of XLForm.
6 7 8 9 10 |
# File 'lib/ProMotion/XLForm/xl_form.rb', line 6 def initialize(form_data, opts={}) @form_data = form_data @title = opts[:title] || '' @required = opts[:required] end |
Instance Attribute Details
#form_data ⇒ Object (readonly)
Returns the value of attribute form_data.
4 5 6 |
# File 'lib/ProMotion/XLForm/xl_form.rb', line 4 def form_data @form_data end |
Instance Method Details
#build ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/ProMotion/XLForm/xl_form.rb', line 12 def build form = XLFormDescriptor.formDescriptorWithTitle(@title) form.addAsteriskToRequiredRowsTitle = (@required == :asterisks) form_data.each do |section_data| title = section_data[:title] = (section_data[:options]) insert_mode = section_insert_mode(section_data[:insert_mode]) section = XLFormSectionDescriptor.formSectionWithTitle(title, sectionOptions: , sectionInsertMode: insert_mode) if .nonzero? tag = section_data[:name] mp("MutliValued section with no :name option", force_color: :red) unless tag if tag.respond_to? :to_s tag = tag.to_s end section.multivaluedTag = tag end section. = section_data[:footer] if section_data[:footer] add_proc section, :on_add, section_data[:on_add] if section_data[:on_add] add_proc section, :on_remove, section_data[:on_remove] if section_data[:on_remove] form.addFormSection(section) section_data[:cells].each do |cell_data| tag = cell_data[:name] mp("Cell with no :name option", force_color: :red) unless tag if tag.respond_to? :to_s tag = tag.to_s end title = cell_data[:title] type = cell_data[:type] if type.nil? and cell_data[:cells] type = :selector_push end cell = XLFormRowDescriptor.formRowDescriptorWithTag(tag, rowType: row_type(type), title: title) cell.required = cell_data[:required] properties = cell_data[:properties] || {} # placeholder cell.cellConfigAtConfigure.setObject(cell_data[:placeholder], forKey: "textField.placeholder") if cell_data[:placeholder] # slider if cell_data[:type] == :slider min = properties[:min] max = properties[:max] step = properties[:step] cell.cellConfigAtConfigure.setObject(min, forKey: "slider.minimumValue") if min cell.cellConfigAtConfigure.setObject(max, forKey: "slider.maximumValue") if max cell.cellConfigAtConfigure.setObject(step, forKey: "steps") if step end # dates if [:date_inline, :datetime_inline, :time_inline, :date, :datetime, :time, :datepicker].include? cell_data[:type] min = properties[:min] max = properties[:max] cell.cellConfigAtConfigure.setObject(min, forKey: "minimumDate") if min cell.cellConfigAtConfigure.setObject(max, forKey: "maximumDate") if max end cell_class = cell_data[:cell_class] # image if cell_data[:type] == :image cell_class = XLFormImageSelectorCell if cell_class.nil? end cell.cellClass = cell_class if cell_class # subcells if cell_data[:cells] cell.action.viewControllerClass = ProMotion::XLSubFormScreen cell.action.cells = cell_data[:cells] cell.valueTransformer = ProMotion::ValueTransformer end # also accept default XLForm viewControllerClass cell.action.viewControllerClass = cell_data[:view_controller_class] if cell_data[:view_controller_class] cell.valueTransformer = cell_data[:value_transformer] if cell_data[:value_transformer] # callbacks add_proc cell, :on_change, cell_data[:on_change] if cell_data[:on_change] add_proc cell, :on_add, cell_data[:on_add] if cell_data[:on_add] add_proc cell, :on_remove, cell_data[:on_remove] if cell_data[:on_remove] cell.selectorTitle = cell_data[:selector_title] if cell_data[:selector_title] = (cell_data[:options]) cell.selectorOptions = value = cell_data[:value] if value and .each do |opt| if opt.formValue == value value = opt break end end end cell.value = value if value cell.disabled = !cell_data[:enabled] if cell_data[:enabled] section.addFormRow(cell) # multi sections if section.multivaluedTag cell.action.required = @required section.multivaluedRowTemplate = cell.copy end end end form end |
#get_callback(row, event) ⇒ Object
133 134 135 136 137 |
# File 'lib/ProMotion/XLForm/xl_form.rb', line 133 def get_callback(row, event) return if @blocks.nil? or @blocks[row].nil? or @blocks[row][event].nil? @blocks[row][event] end |