motion-prime/sections/form.rb in motion-prime-0.3.0 vs motion-prime/sections/form.rb in motion-prime-0.3.1

- old
+ new

@@ -1,11 +1,9 @@ motion_require './table.rb' motion_require '../helpers/has_style_chain_builder' module MotionPrime class FormSection < TableSection - include HasStyleChainBuilder - # MotionPrime::FormSection is container for Field Sections. # Forms are located inside Screen and can contain multiple Field Sections. # On render, each field will be added to parent screen. # == Basic Sample @@ -39,61 +37,28 @@ result end end end - def form_styles - base_styles = [:base_form] - base_styles << :base_form_with_sections unless flat_data? - item_styles = [name.to_sym] - {common: base_styles, specific: item_styles} + def data + @data ||= table_data end - def field_styles(field) - suffixes = [:field] - if field.is_a?(BaseFieldSection) - suffixes << field.class_name_without_kvo.demodulize.underscore.gsub(/\_section$/, '') - end - - styles = { - common: build_styles_chain(form_styles[:common], suffixes), - specific: build_styles_chain(form_styles[:specific], suffixes) - } - - if field.respond_to?(:container_styles) && field.container_styles.present? - styles[:specific] += Array.wrap(field.container_styles) - end - styles - end - - def header_styles(header) - suffixes = [:header, :"#{header.name}_header"] - styles = { - common: build_styles_chain(form_styles[:common], suffixes), - specific: build_styles_chain(form_styles[:specific], suffixes) - } - - if header.respond_to?(:container_styles) && header.container_styles.present? - styles[:specific] += Array.wrap(header.container_styles) - end - styles - end - def render_table init_form_fields reset_data_stamps options = { - styles: form_styles.values.flatten, + styles: table_styles.values.flatten, delegate: self, dataSource: self, style: (UITableViewStyleGrouped unless flat_data?)} self.table_element = screen.table_view(options) end def render_cell(index, table) field = rows_for_section(index.section)[index.row] - screen.table_view_cell styles: field_styles(field).values.flatten, reuse_identifier: cell_name(table, index), parent_view: table_view do |cell_view| + screen.table_view_cell section: field, styles: cell_styles(field).values.flatten, reuse_identifier: cell_name(table, index), parent_view: table_view do |cell_view| field.cell_view = cell_view if field.respond_to?(:cell_view) field.render(to: screen) end end @@ -231,11 +196,11 @@ end end def load_field(field) klass = "MotionPrime::#{field[:type].classify}FieldSection".constantize - klass.new(field.merge(form: self)) + klass.new(field.merge(table: self)) end def render_field?(name, options) condition = options.delete(:if) if condition.nil? @@ -247,20 +212,20 @@ end end def render_header(section) return unless options = self.class.section_header_options.try(:[], section) - self.section_headers[section] ||= BaseHeaderSection.new(options.merge(form: self)) + self.section_headers[section] ||= BaseHeaderSection.new(options.merge(table: self)) end def header_for_section(section) self.section_headers ||= [] self.section_headers[section] || render_header(section) end def tableView(table, viewForHeaderInSection: section) return unless header = header_for_section(section) - wrapper = MotionPrime::BaseElement.factory(:view, styles: header_styles(header).values.flatten, parent_view: table_view) + wrapper = MotionPrime::BaseElement.factory(:view, styles: cell_styles(header).values.flatten, parent_view: table_view) wrapper.render(to: screen) do |cell_view| header.cell_view = cell_view if header.respond_to?(:cell_view) header.render(to: screen) end end \ No newline at end of file