Class: Olivander::Resources::ResourceFields::ResourceFieldGroup

Inherits:
Object
  • Object
show all
Defined in:
app/controllers/concerns/olivander/resources/auto_form_attributes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, editable, on_show, on_form) ⇒ ResourceFieldGroup

Returns a new instance of ResourceFieldGroup.



175
176
177
178
179
180
181
182
# File 'app/controllers/concerns/olivander/resources/auto_form_attributes.rb', line 175

def initialize(key, editable, on_show, on_form)
  self.key = key
  self.editable = editable
  self.on_show = on_show
  self.on_form = on_form
  self.fields = []
  self.sections = []
end

Instance Attribute Details

#editableObject

Returns the value of attribute editable.



173
174
175
# File 'app/controllers/concerns/olivander/resources/auto_form_attributes.rb', line 173

def editable
  @editable
end

#fieldsObject

Returns the value of attribute fields.



173
174
175
# File 'app/controllers/concerns/olivander/resources/auto_form_attributes.rb', line 173

def fields
  @fields
end

#forced_sectionObject

Returns the value of attribute forced_section.



173
174
175
# File 'app/controllers/concerns/olivander/resources/auto_form_attributes.rb', line 173

def forced_section
  @forced_section
end

#keyObject

Returns the value of attribute key.



173
174
175
# File 'app/controllers/concerns/olivander/resources/auto_form_attributes.rb', line 173

def key
  @key
end

#on_formObject

Returns the value of attribute on_form.



173
174
175
# File 'app/controllers/concerns/olivander/resources/auto_form_attributes.rb', line 173

def on_form
  @on_form
end

#on_showObject

Returns the value of attribute on_show.



173
174
175
# File 'app/controllers/concerns/olivander/resources/auto_form_attributes.rb', line 173

def on_show
  @on_show
end

#sectionsObject

Returns the value of attribute sections.



173
174
175
# File 'app/controllers/concerns/olivander/resources/auto_form_attributes.rb', line 173

def sections
  @sections
end

Instance Method Details

#add_field(sym, type, editable, on_show, on_form) ⇒ Object



184
185
186
187
188
189
190
191
192
# File 'app/controllers/concerns/olivander/resources/auto_form_attributes.rb', line 184

def add_field(sym, type, editable, on_show, on_form)
  e = editable.nil? ? self.editable : editable
  s = on_show
  f = on_form
  section = forced_section || next_section
  field = ResourceField.new(sym, type, e, s, f, self)
  section.fields << field
  fields << field
end

#max_section_columnsObject



200
201
202
# File 'app/controllers/concerns/olivander/resources/auto_form_attributes.rb', line 200

def max_section_columns
  sections.collect { |x| x.columns }.max
end

#next_section(columns = 1) ⇒ Object



194
195
196
197
198
# File 'app/controllers/concerns/olivander/resources/auto_form_attributes.rb', line 194

def next_section(columns = 1)
  section = ResourceFieldSection.new(columns)
  sections << section
  section
end