Class: Para::Inputs::NestedManyInput
- Inherits:
-
SimpleForm::Inputs::Base
- Object
- SimpleForm::Inputs::Base
- Para::Inputs::NestedManyInput
- Defined in:
- lib/para/inputs/nested_many_input.rb
Instance Attribute Summary collapse
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #dom_identifier ⇒ Object
- #input(wrapper_options = nil) ⇒ Object
- #inset? ⇒ Boolean
- #model ⇒ Object
- #parent_model ⇒ Object
- #subclass ⇒ Object
- #subclasses ⇒ Object
Instance Attribute Details
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
4 5 6 |
# File 'lib/para/inputs/nested_many_input.rb', line 4 def resource @resource end |
Instance Method Details
#dom_identifier ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/para/inputs/nested_many_input.rb', line 44 def dom_identifier @dom_identifier ||= begin name = attribute_name time = (Time.now.to_f * 1000).to_i random = (rand * 1000).to_i [name, time, random].join('-') end end |
#input(wrapper_options = nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/para/inputs/nested_many_input.rb', line 6 def input( = nil) [:class] << "nested-many" orderable = .fetch(:orderable, model.orderable?) = .fetch(:add_button, true) # Load existing resources resources = object.send(attribute_name) # Order them if the list should be orderable resources = resources.sort_by(&:position) if orderable locals = .fetch(:locals, {}) template.render( partial: 'para/inputs/nested_many', locals: { form: @builder, model: model, attribute_name: attribute_name, orderable: orderable, add_button: , dom_identifier: dom_identifier, resources: resources, nested_locals: locals, subclass: subclass, subclasses: subclasses, inset: inset? } ) end |
#inset? ⇒ Boolean
64 65 66 |
# File 'lib/para/inputs/nested_many_input.rb', line 64 def inset? .fetch(:inset, false) end |
#model ⇒ Object
40 41 42 |
# File 'lib/para/inputs/nested_many_input.rb', line 40 def model @model ||= parent_model.reflect_on_association(attribute_name).klass end |
#parent_model ⇒ Object
36 37 38 |
# File 'lib/para/inputs/nested_many_input.rb', line 36 def parent_model @parent_model ||= @builder.object.class end |
#subclass ⇒ Object
53 54 55 |
# File 'lib/para/inputs/nested_many_input.rb', line 53 def subclass @subclass ||= .fetch(:subclass, subclasses.presence) end |
#subclasses ⇒ Object
57 58 59 60 61 62 |
# File 'lib/para/inputs/nested_many_input.rb', line 57 def subclasses .fetch( :subclasses, (model.try(:descendants) || []).sort_by { |m| m.model_name.human } ) end |