rondo_form 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/rondo_form/templates/cocoon_controller.js +22 -16
- data/lib/rondo_form/version.rb +1 -1
- data/lib/rondo_form/view_helpers.rb +15 -18
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ee9d8f4d7737a47f8e756a02d3dab153a2f8e162b8b5141755976c381470114
|
4
|
+
data.tar.gz: 2d1b339d1a473c7336ecf5fe3182b23591ab409f5cffe580fabd62b1f0c3ed1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10b686a87cb7e4de4cd13616d9b85d875d36db630209989c5bb40ae19d23fa66ee0b6153b4220a42c6e4479289b0515f427917d0385ccea5a7f5c44741504d71
|
7
|
+
data.tar.gz: 76fcdce9be21925c0f1aba373fd19f996e7c9fbac7d4e3e952df969ebf4b3a6ed3eb232d47a8326161ad0f627f61267afbcc146c465f1e1dbbc2df6906e72e96
|
@@ -4,32 +4,38 @@ export default class extends Controller {
|
|
4
4
|
static targets = ["template"]
|
5
5
|
|
6
6
|
addField(e) {
|
7
|
-
e.preventDefault()
|
8
|
-
|
9
|
-
let
|
10
|
-
let
|
11
|
-
insertionNode.
|
7
|
+
e.preventDefault();
|
8
|
+
|
9
|
+
let assoc = e.target.dataset.association;
|
10
|
+
let newField = this.buildNewAssociation(assoc);
|
11
|
+
let insertionNode = this.templateTarget.parentElement;
|
12
|
+
insertionNode.insertAdjacentHTML("beforebegin", newField);
|
12
13
|
}
|
13
14
|
|
14
15
|
removeField(e) {
|
15
|
-
e.preventDefault()
|
16
|
-
|
16
|
+
e.preventDefault();
|
17
|
+
|
18
|
+
let wrapperClass = this.data.get("wrapperClass") || "nested-fields";
|
19
|
+
let wrapperField = e.target.closest("." + wrapperClass);
|
17
20
|
if(e.target.matches('.dynamic')) {
|
18
|
-
|
21
|
+
wrapperField.remove();
|
19
22
|
} else {
|
20
|
-
|
23
|
+
wrapperField.querySelector("input[name*='_destroy']").value = 1;
|
24
|
+
wrapperField.style.display = "none";
|
21
25
|
}
|
22
26
|
}
|
23
27
|
|
24
28
|
buildNewAssociation(assoc) {
|
25
29
|
let content = this.templateTarget.innerHTML;
|
26
|
-
let
|
27
|
-
let
|
28
|
-
let
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
let regexpBraced = new RegExp('\\[new_' + assoc + '\\]', 'g');
|
31
|
+
let newId = new Date().getTime();
|
32
|
+
let newContent = content.replace(regexpBraced, '[' + newId + ']');
|
33
|
+
|
34
|
+
if (newContent == content) {
|
35
|
+
// assoc can be singular or plural
|
36
|
+
regexpBraced = new RegExp('\\[new_' + assoc + 's\\]', 'g');
|
37
|
+
newContent = content.replace(regexpBraced, '[' + newId + ']');
|
32
38
|
}
|
33
|
-
return
|
39
|
+
return newContent;
|
34
40
|
}
|
35
41
|
}
|
data/lib/rondo_form/version.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module RondoForm
|
2
2
|
module ViewHelpers
|
3
|
+
|
3
4
|
# this will show a link to remove the current association. This should be placed inside the partial.
|
4
5
|
# either you give
|
5
6
|
# - *name* : the text of the link
|
@@ -18,9 +19,8 @@ module RondoForm
|
|
18
19
|
name = capture(&block)
|
19
20
|
link_to_remove_association(name, f, html_options)
|
20
21
|
else
|
21
|
-
name
|
22
|
-
|
23
|
-
html_options = args[2] || {}
|
22
|
+
name, f, html_options = *args
|
23
|
+
html_options ||= {}
|
24
24
|
|
25
25
|
is_dynamic = f.object.new_record?
|
26
26
|
html_options[:class] = [html_options[:class], "remove_fields #{is_dynamic ? 'dynamic' : 'existing'}"].compact.join(' ')
|
@@ -29,32 +29,22 @@ module RondoForm
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
# :nodoc:
|
33
|
-
def render_association(association, f, new_object)
|
34
|
-
f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
|
35
|
-
render(association.to_s.singularize + "_fields", :f => builder, :dynamic => true)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
32
|
# shows a link that will allow to dynamically add a new associated object.
|
40
33
|
#
|
41
34
|
# - *name* : the text to show in the link
|
42
|
-
# - *f* : the form this should come in
|
35
|
+
# - *f* : the form this should come in
|
43
36
|
# - *association* : the associated objects, e.g. :tasks, this should be the name of the <tt>has_many</tt> relation.
|
44
37
|
# - *html_options*: html options to be passed to <tt>link_to</tt> (see <tt>link_to</tt>)
|
45
38
|
# - *&block*: see <tt>link_to</tt>
|
46
39
|
|
47
40
|
def link_to_add_association(*args, &block)
|
48
41
|
if block_given?
|
49
|
-
f
|
50
|
-
|
51
|
-
html_options = args[2] || {}
|
42
|
+
f, association, html_options = *args
|
43
|
+
html_options ||= {}
|
52
44
|
link_to_add_association(capture(&block), f, association, html_options)
|
53
45
|
else
|
54
|
-
name
|
55
|
-
|
56
|
-
association = args[2]
|
57
|
-
html_options = args[3] || {}
|
46
|
+
name, f, association, html_options = *args
|
47
|
+
html_options ||= {}
|
58
48
|
|
59
49
|
html_options[:class] = [html_options[:class], "add_fields"].compact.join(' ')
|
60
50
|
html_options[:'data-association'] = association.to_s.singularize
|
@@ -68,5 +58,12 @@ module RondoForm
|
|
68
58
|
end
|
69
59
|
hidden_div.html_safe + link_to(name, '', html_options )
|
70
60
|
end
|
61
|
+
|
62
|
+
# :nodoc:
|
63
|
+
def render_association(association, f, new_object)
|
64
|
+
f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
|
65
|
+
render(association.to_s.singularize + "_fields", :f => builder, :dynamic => true)
|
66
|
+
end
|
67
|
+
end
|
71
68
|
end
|
72
69
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rondo_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hungle00
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-06-
|
11
|
+
date: 2023-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|