para 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/views/para/inputs/_nested_one.html.haml +6 -8
- data/app/views/para/inputs/nested_one/_add_with_subclasses.html.haml +10 -0
- data/app/views/para/inputs/nested_one/_container.html.haml +9 -0
- data/lib/para/inputs/nested_base_input.rb +29 -0
- data/lib/para/inputs/nested_many_input.rb +2 -31
- data/lib/para/inputs/nested_one_input.rb +9 -2
- data/lib/para/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70788bd2854ce638f71aa879f8d511eda524bd13
|
4
|
+
data.tar.gz: fbd1da0da3c7e6f20cfd2972fb4c65e5a66b057c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa5d051fe408fabd83d66d3e28aa5d22820f5227f047ac2a7097f721dd66ef928ee4bbc88b996211dfb9e682ef755bce6ead4aac74f513a56e107251411b06fe
|
7
|
+
data.tar.gz: 2d71c0e5bab1e298f6a25b99192b828f866898e4e6b5a3e84c02e5c39e2ae9393995937baf775a8a7602f05b69821a5f1beb9a46f0ed10adc63417d12fe14ab4
|
@@ -1,14 +1,12 @@
|
|
1
1
|
.nested-one-field
|
2
2
|
= form.simple_fields_for attribute_name, resource, nested_attribute_name: attribute_name do |nested_form|
|
3
3
|
- if defined?(collapsible) && collapsible
|
4
|
-
|
5
|
-
.
|
6
|
-
|
7
|
-
= link_to "##{ nested_form.nested_resource_dom_id }", class: "nested-input-title collapsed#{ (' has-error' if nested_form.object.errors.any?) }", data: { toggle: 'collapse', :'open-on-insert' => true } do
|
8
|
-
= nested_form.nested_resource_name
|
9
|
-
%i.fa.fa-angle-up
|
4
|
+
- if resource
|
5
|
+
.nested-one-container{ id: dom_identifier }
|
6
|
+
= render partial: find_partial_for(model, 'nested_one/container', partial_dir: 'inputs'), locals: { nested_form: nested_form, form: form, model: nested_form.object.class, subclass: subclass, nested_locals: nested_locals }
|
10
7
|
|
11
|
-
.panel-body.panel-collapse.form-inputs.collapse{ id: nested_form.nested_resource_dom_id }
|
12
|
-
= render partial: find_partial_for(model, :fields), locals: { form: nested_form, parent: form.object }.merge(nested_locals)
|
13
8
|
- else
|
14
9
|
= render partial: find_partial_for(model, :fields), locals: { form: nested_form, parent: form.object }.merge(nested_locals)
|
10
|
+
|
11
|
+
- if defined?(subclass) && subclass
|
12
|
+
= render partial: 'para/inputs/nested_one/add_with_subclasses', locals: { form: form, model: model, dom_identifier: dom_identifier, nested_locals: nested_locals, attribute_name: attribute_name, subclasses: subclasses, add_button_label: add_button_label, add_button_class: add_button_class, subclass: subclass }
|
@@ -0,0 +1,10 @@
|
|
1
|
+
.add-button.nested-one-inset-add-button.dropdown
|
2
|
+
%button.btn.btn-shadow.dropdown-toggle{ class: add_button_class, type: 'button', data: { toggle: 'dropdown' } }
|
3
|
+
= add_button_label
|
4
|
+
%i.fa.fa-angle-down
|
5
|
+
|
6
|
+
%ul.dropdown-menu
|
7
|
+
- subclasses.each do |submodel|
|
8
|
+
%li
|
9
|
+
= link_to_add_association form, attribute_name, wrap_object: proc { submodel.new }, partial: find_partial_for(submodel, 'nested_one/container', partial_dir: 'inputs'), form_name: 'form', class: 'dropdown-link', data: { :'association-insertion-node' => "##{ dom_identifier }", :'association-insertion-method' => 'append' }, render_options: { nested_attribute_name: attribute_name, locals: { form: form, model: submodel, subclass: subclass, nested_locals: nested_locals } } do
|
10
|
+
= submodel.model_name.human
|
@@ -0,0 +1,9 @@
|
|
1
|
+
.panel.panel-default.form-fields
|
2
|
+
.panel-heading
|
3
|
+
%h3.panel-title
|
4
|
+
= link_to "##{ form.nested_resource_dom_id }", class: "nested-input-title collapsed#{ (' has-error' if form.object.errors.any?) }", data: { toggle: 'collapse', :'open-on-insert' => true } do
|
5
|
+
= form.nested_resource_name
|
6
|
+
%i.fa.fa-angle-up
|
7
|
+
|
8
|
+
.panel-body.panel-collapse.form-inputs.collapse{ id: form.nested_resource_dom_id }
|
9
|
+
= render partial: find_partial_for(model, :fields), locals: { form: form, parent: form.object }.merge(nested_locals)
|
@@ -5,6 +5,35 @@ module Para
|
|
5
5
|
|
6
6
|
private
|
7
7
|
|
8
|
+
def dom_identifier
|
9
|
+
@dom_identifier ||= begin
|
10
|
+
name = attribute_name
|
11
|
+
id = @builder.object.id || "_new_#{ parent_nested_field&.attribute_name }_"
|
12
|
+
time = (Time.now.to_f * 1000).to_i
|
13
|
+
random = (rand * 1000).to_i
|
14
|
+
[name, id, time, random].join('-')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def subclass
|
19
|
+
@subclass ||= options.fetch(:subclass, subclasses.presence)
|
20
|
+
end
|
21
|
+
|
22
|
+
def subclasses
|
23
|
+
options.fetch(
|
24
|
+
:subclasses,
|
25
|
+
(model.try(:descendants) || []).sort_by { |m| m.model_name.human }
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_button_label
|
30
|
+
options.fetch(:add_button_label) { I18n.t('para.form.nested.add') }
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_button_class
|
34
|
+
options.fetch(:add_button_class) { 'btn-primary' }
|
35
|
+
end
|
36
|
+
|
8
37
|
# This allows to access the parent nested field from a child nested field
|
9
38
|
# and fetch some of its data. This is useful for deeply nested cocoon
|
10
39
|
# fields.
|
@@ -29,9 +29,9 @@ module Para
|
|
29
29
|
nested_locals: locals,
|
30
30
|
subclass: subclass,
|
31
31
|
subclasses: subclasses,
|
32
|
-
inset: inset?,
|
33
32
|
add_button_label: add_button_label,
|
34
33
|
add_button_class: add_button_class,
|
34
|
+
inset: inset?,
|
35
35
|
render_partial: render_partial?,
|
36
36
|
remote_partial_params: remote_partial_params
|
37
37
|
}
|
@@ -47,39 +47,10 @@ module Para
|
|
47
47
|
@model ||= parent_model.reflect_on_association(attribute_name).klass
|
48
48
|
end
|
49
49
|
|
50
|
-
def dom_identifier
|
51
|
-
@dom_identifier ||= begin
|
52
|
-
name = attribute_name
|
53
|
-
id = @builder.object.id || "_new_#{ parent_nested_field&.attribute_name }_"
|
54
|
-
time = (Time.now.to_f * 1000).to_i
|
55
|
-
random = (rand * 1000).to_i
|
56
|
-
[name, id, time, random].join('-')
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def subclass
|
61
|
-
@subclass ||= options.fetch(:subclass, subclasses.presence)
|
62
|
-
end
|
63
|
-
|
64
|
-
def subclasses
|
65
|
-
options.fetch(
|
66
|
-
:subclasses,
|
67
|
-
(model.try(:descendants) || []).sort_by { |m| m.model_name.human }
|
68
|
-
)
|
69
|
-
end
|
70
|
-
|
71
50
|
def inset?
|
72
51
|
options.fetch(:inset, false)
|
73
52
|
end
|
74
|
-
|
75
|
-
def add_button_label
|
76
|
-
options.fetch(:add_button_label) { I18n.t('para.form.nested.add') }
|
77
|
-
end
|
78
|
-
|
79
|
-
def add_button_class
|
80
|
-
options.fetch(:add_button_class) { 'btn-primary' }
|
81
|
-
end
|
82
|
-
|
53
|
+
|
83
54
|
def render_partial?
|
84
55
|
options[:render_partial] || object.errors.any? || (object.persisted? && inset?)
|
85
56
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Para
|
2
2
|
module Inputs
|
3
3
|
class NestedOneInput < NestedBaseInput
|
4
|
+
attr_reader :model
|
5
|
+
|
4
6
|
def input(wrapper_options = nil)
|
5
7
|
input_html_options[:class] << "nested-one"
|
6
8
|
|
@@ -9,7 +11,7 @@ module Para
|
|
9
11
|
relation = parent_model.reflect_on_association(attribute_name)
|
10
12
|
|
11
13
|
resource = object.send(attribute_name)
|
12
|
-
model = (resource && resource.class) || relation.klass
|
14
|
+
@model = (resource && resource.class) || relation.klass
|
13
15
|
|
14
16
|
unless resource
|
15
17
|
# Build association without trying to save the new record
|
@@ -33,7 +35,12 @@ module Para
|
|
33
35
|
resource: resource,
|
34
36
|
attribute_name: attribute_name,
|
35
37
|
nested_locals: locals,
|
36
|
-
collapsible: collapsible
|
38
|
+
collapsible: collapsible || subclass,
|
39
|
+
dom_identifier: dom_identifier,
|
40
|
+
subclass: subclass,
|
41
|
+
subclasses: subclasses,
|
42
|
+
add_button_label: add_button_label,
|
43
|
+
add_button_class: add_button_class
|
37
44
|
}
|
38
45
|
)
|
39
46
|
end
|
data/lib/para/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: para
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Valentin Ballestrino
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -651,6 +651,8 @@ files:
|
|
651
651
|
- app/views/para/inputs/nested_many/_add.html.haml
|
652
652
|
- app/views/para/inputs/nested_many/_add_with_subclasses.html.haml
|
653
653
|
- app/views/para/inputs/nested_many/_container.html.haml
|
654
|
+
- app/views/para/inputs/nested_one/_add_with_subclasses.html.haml
|
655
|
+
- app/views/para/inputs/nested_one/_container.html.haml
|
654
656
|
- app/views/shared/_breadcrumbs.html.haml
|
655
657
|
- config/locales/en.yml
|
656
658
|
- config/locales/fr.yml
|