Class: Para::Inputs::NestedManyInput

Inherits:
NestedBaseInput
  • Object
show all
Defined in:
lib/para/inputs/nested_many_input.rb

Constant Summary

Constants inherited from NestedBaseInput

Para::Inputs::NestedBaseInput::GLOBAL_NESTED_FIELD_KEY

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#resourceObject (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

#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
35
36
37
38
39
40
41
# File 'lib/para/inputs/nested_many_input.rb', line 6

def input(wrapper_options = nil)
  input_html_options[:class] << "nested-many"

  orderable = options.fetch(:orderable, model.orderable?)
  add_button = options.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 = options.fetch(:locals, {})

  with_global_nested_field do
    template.render(
      partial: 'para/inputs/nested_many',
      locals: {
        form: @builder,
        model: model,
        attribute_name: attribute_name,
        orderable: orderable,
        add_button: add_button,
        dom_identifier: dom_identifier,
        resources: resources,
        nested_locals: locals,
        subclass: subclass,
        subclasses: subclasses,
        add_button_label: add_button_label,
        add_button_class: add_button_class,
        inset: inset?,
        uncollapsed: uncollapsed?,
        render_partial: render_partial?,
        remote_partial_params: remote_partial_params
      }
    )
  end
end

#inset?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/para/inputs/nested_many_input.rb', line 51

def inset?
  options.fetch(:inset, false)
end

#modelObject



47
48
49
# File 'lib/para/inputs/nested_many_input.rb', line 47

def model
  @model ||= parent_model.reflect_on_association(attribute_name).klass
end

#parent_modelObject



43
44
45
# File 'lib/para/inputs/nested_many_input.rb', line 43

def parent_model
  @parent_model ||= @builder.object.class
end

#remote_partial_paramsObject



63
64
65
66
67
# File 'lib/para/inputs/nested_many_input.rb', line 63

def remote_partial_params
  @remote_partial_params ||= options.fetch(:remote_partial_params, {}).merge(
    namespace: :nested_form
  )
end

#render_partial?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/para/inputs/nested_many_input.rb', line 59

def render_partial?
  options[:render_partial] || object.errors.any? || (object.persisted? && uncollapsed?)
end

#uncollapsed?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/para/inputs/nested_many_input.rb', line 55

def uncollapsed?
  inset? && Para.config.uncollapse_inset_nested_fields
end