vanilla_nested 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vanilla_nested/view_helpers.rb +20 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a6640e42d6a7195a2266b57ce2c77d3edffb1a1de0662ede0b6d19aa4b126bf
|
4
|
+
data.tar.gz: 1b74a76aed703a1a2019f2b98d24ba6595f7faf72ac52acc22f8470b43204fc3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 536f8c0238182518afda5f82662a90a8695d0324f526d2666b69235c5e482275f3d95b4a77e8e519d523c208a81beb4fcfa776dceded510187052ce97f384b5d
|
7
|
+
data.tar.gz: 50775a3000f06c76bc2e99c53669ded2a26c7c92775438b4ef4400f905835c60028a947f47c74c7b6853474926efdf669e2ff724e08ac5e7049b203e427759de
|
@@ -9,8 +9,9 @@ module VanillaNested
|
|
9
9
|
# @param link_classes [String] space separated classes for the link tag
|
10
10
|
# @param insert_method [:append, :prepend] tells javascript if the new fields should be appended or prepended to the container
|
11
11
|
# @param partial_form_variable [String, Symbol] name of the variable that represents the form builder inside the fields partial
|
12
|
+
# @param link_content [Block] block of code for the link content
|
12
13
|
# @return [String] link tag
|
13
|
-
def link_to_add_nested(form, association, container_selector, link_text: nil, link_classes: '', insert_method: :append, partial: nil, partial_form_variable: :form)
|
14
|
+
def link_to_add_nested(form, association, container_selector, link_text: nil, link_classes: '', insert_method: :append, partial: nil, partial_form_variable: :form, &link_content)
|
14
15
|
association_class = form.object.class.reflections[association.to_s].klass
|
15
16
|
object = association_class.new
|
16
17
|
|
@@ -34,8 +35,11 @@ module VanillaNested
|
|
34
35
|
nested_options = form.object.class.nested_attributes_options[association.to_sym]
|
35
36
|
data['limit'] = nested_options[:limit] if nested_options[:limit]
|
36
37
|
|
37
|
-
|
38
|
-
|
38
|
+
if block_given?
|
39
|
+
link_to '#', class: classes, data: data, &link_content
|
40
|
+
else
|
41
|
+
text = link_text || "Add #{association_class.model_name}"
|
42
|
+
link_to text, '#', class: classes, data: data
|
39
43
|
end
|
40
44
|
end
|
41
45
|
|
@@ -44,9 +48,11 @@ module VanillaNested
|
|
44
48
|
# @param fields_wrapper_selector [String] selector for the wrapper of the fields, must be an ancestor
|
45
49
|
# @param undo_link_timeout [Integer] time until undo timeouts
|
46
50
|
# @param undo_link_text [String] text to show as "undo"
|
47
|
-
# @param undo_link_classes [String] space separated list of classes
|
51
|
+
# @param undo_link_classes [String] space separated list of classes for the "undo" link
|
52
|
+
# @param ulink_classes [String] space separated list of classes for the "x" link
|
53
|
+
# @param link_content [Block] block of code for the link content
|
48
54
|
# @return [String] hidden field and link tag
|
49
|
-
def link_to_remove_nested(form, link_text: 'X', fields_wrapper_selector: nil, undo_link_timeout: nil, undo_link_text: 'Undo', undo_link_classes: '')
|
55
|
+
def link_to_remove_nested(form, link_text: 'X', fields_wrapper_selector: nil, undo_link_timeout: nil, undo_link_text: 'Undo', undo_link_classes: '', link_classes: '', &link_content)
|
50
56
|
data = {
|
51
57
|
'fields-wrapper-selector': fields_wrapper_selector,
|
52
58
|
'undo-timeout': undo_link_timeout,
|
@@ -54,9 +60,17 @@ module VanillaNested
|
|
54
60
|
'undo-link-classes': undo_link_classes
|
55
61
|
}
|
56
62
|
|
63
|
+
classes = "vanilla-nested-remove #{link_classes}"
|
64
|
+
|
57
65
|
capture do
|
58
66
|
concat form.hidden_field(:_destroy, value: 0)
|
59
|
-
concat
|
67
|
+
concat(
|
68
|
+
if block_given?
|
69
|
+
link_to('#', class: classes, data: data, &link_content)
|
70
|
+
else
|
71
|
+
link_to(link_text.html_safe, '#', class: classes, data: data)
|
72
|
+
end
|
73
|
+
)
|
60
74
|
end
|
61
75
|
end
|
62
76
|
end
|