Class: Lolita::Configuration::NestedForm
- Includes:
- Builder
- Defined in:
- lib/lolita/configuration/nested_form.rb
Overview
Accept those attributes
-
:name
- Name of nested relation, like :comments. -
:field_style
- Is fields rendered with as normal (with lable and staff) or like in table (:simple). Default :simple -
:expandable
- Show or not “Add new” and “Delete” links in form,
by default, it is expandable if association macro is :many
-
:field_rejection_proc
- Proc, that contains condition of how to reject field.
By default form rejects all fields from parent tab that doesn’t have current form as field nested_form
Example
form = Lolita::Configuration::NestedForm.new(Lolita::Configuration::Tab::Content.new,:comments)
form.field_rejection_proc = Proc.new{|field|
field.name.to_s.match(/_id$/)
}
# form exclude all fields that ends with _id
Constant Summary collapse
- @@last_nested_form =
0
Instance Attribute Summary collapse
- #build_method ⇒ Object
-
#expandable ⇒ Object
Returns the value of attribute expandable.
-
#field_rejection_proc ⇒ Object
Returns the value of attribute field_rejection_proc.
-
#field_style ⇒ Object
Returns the value of attribute field_style.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #allow_destroy? ⇒ Boolean
-
#as_field ⇒ Object
Create field, that is not real field, but represents nested attributes as one.
-
#dbi ⇒ Object
Parent (a.k.a tab) dbi.
-
#expandable? ⇒ Boolean
Detect if it’s possible to add more than one field group, like if model has many other objects.
-
#fields ⇒ Object
Return all fields.
-
#fields=(new_fields) ⇒ Object
Fields setter.
-
#initialize(parent, name = nil, options = {}) ⇒ NestedForm
constructor
A new instance of NestedForm.
-
#klass ⇒ Object
Parent (tab) dbi klass.
-
#macro ⇒ Object
Parent (tab) dbi klass reflection with #name and macros of that.
- #update_only? ⇒ Boolean
Methods included from Builder
#build, #builder, #builder=, #builder_default_name, #builder_default_options, #builder_default_state
Constructor Details
#initialize(parent, name = nil, options = {}) ⇒ NestedForm
Returns a new instance of NestedForm.
24 25 26 27 28 29 |
# File 'lib/lolita/configuration/nested_form.rb', line 24 def initialize parent,name=nil, ={} @parent=parent @options = self.name=name || "nested_form_#{next_nested_form}" set_attributes_from() end |
Instance Attribute Details
#build_method ⇒ Object
39 40 41 |
# File 'lib/lolita/configuration/nested_form.rb', line 39 def build_method @build_method || self.name end |
#expandable ⇒ Object
Returns the value of attribute expandable.
21 22 23 |
# File 'lib/lolita/configuration/nested_form.rb', line 21 def @expandable end |
#field_rejection_proc ⇒ Object
Returns the value of attribute field_rejection_proc.
21 22 23 |
# File 'lib/lolita/configuration/nested_form.rb', line 21 def field_rejection_proc @field_rejection_proc end |
#field_style ⇒ Object
Returns the value of attribute field_style.
20 21 22 |
# File 'lib/lolita/configuration/nested_form.rb', line 20 def field_style @field_style end |
#name ⇒ Object
Returns the value of attribute name.
21 22 23 |
# File 'lib/lolita/configuration/nested_form.rb', line 21 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
20 21 22 |
# File 'lib/lolita/configuration/nested_form.rb', line 20 def @options end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
20 21 22 |
# File 'lib/lolita/configuration/nested_form.rb', line 20 def parent @parent end |
Instance Method Details
#allow_destroy? ⇒ Boolean
31 32 33 |
# File 'lib/lolita/configuration/nested_form.rb', line 31 def allow_destroy? dbi.klass.[name][:allow_destroy] end |
#as_field ⇒ Object
Create field, that is not real field, but represents nested attributes as one. It is used to create label.
56 57 58 |
# File 'lib/lolita/configuration/nested_form.rb', line 56 def as_field Lolita::Configuration::Factory::Field.add(dbi,self.name, :string) end |
#dbi ⇒ Object
Parent (a.k.a tab) dbi
61 62 63 |
# File 'lib/lolita/configuration/nested_form.rb', line 61 def dbi @parent.dbi end |
#expandable? ⇒ Boolean
Detect if it’s possible to add more than one field group, like if model has many other objects.
50 51 52 |
# File 'lib/lolita/configuration/nested_form.rb', line 50 def @expandable == true || (@expandable == nil && macro == :many) end |
#fields ⇒ Object
Return all fields. Each time fields ar returned from @fields if its defined or calculated by using #field_rejection_proc or collected from parent (tab) where fields nested form is same with self.
72 73 74 75 76 77 78 79 80 |
# File 'lib/lolita/configuration/nested_form.rb', line 72 def fields if @fields @fields elsif field_rejection_proc self.parent.fields.reject(&field_rejection_proc) else self.parent.fields.reject{|f| f.nested_form!=self} end end |
#fields=(new_fields) ⇒ Object
Fields setter. Fields should be array and each element should be Lolita::Configuration::Field object.
66 67 68 |
# File 'lib/lolita/configuration/nested_form.rb', line 66 def fields=(new_fields) @fields = new_fields end |
#klass ⇒ Object
Parent (tab) dbi klass
83 84 85 |
# File 'lib/lolita/configuration/nested_form.rb', line 83 def klass dbi.reflect_on_association(name).klass end |
#macro ⇒ Object
Parent (tab) dbi klass reflection with #name and macros of that.
88 89 90 |
# File 'lib/lolita/configuration/nested_form.rb', line 88 def macro dbi.reflect_on_association(name).macro end |
#update_only? ⇒ Boolean
35 36 37 |
# File 'lib/lolita/configuration/nested_form.rb', line 35 def update_only? dbi.klass.[name][:update_only] end |