anaf_habtm 0.0.83 → 0.0.84
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/anaf_habtm.gemspec +4 -3
- data/lib/anaf_habtm/application_helper_methods.rb +13 -4
- data/lib/generators/anaf_habtm/anaf_habtm_generator.rb +1 -0
- data/lib/generators/anaf_habtm/assets/nested_attributes.css +3 -0
- data/lib/generators/anaf_habtm/assets/nested_attributes.js +31 -10
- metadata +5 -5
data/Rakefile
CHANGED
data/anaf_habtm.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{anaf_habtm}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.84"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Tyler Gannon"]
|
12
|
-
s.date = %q{2010-07-
|
12
|
+
s.date = %q{2010-07-13}
|
13
13
|
s.description = %q{accepts_nested_attributes_for habtm}
|
14
14
|
s.email = %q{t--g__a--nnon@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
"lib/anaf_habtm/hash.rb",
|
28
28
|
"lib/anaf_habtm/string_reader.rb",
|
29
29
|
"lib/generators/anaf_habtm/anaf_habtm_generator.rb",
|
30
|
+
"lib/generators/anaf_habtm/assets/nested_attributes.css",
|
30
31
|
"lib/generators/anaf_habtm/assets/nested_attributes.js",
|
31
32
|
"rails/init.rb",
|
32
33
|
"test/anaf_habtm_test.rb",
|
@@ -39,7 +40,7 @@ Gem::Specification.new do |s|
|
|
39
40
|
s.rubygems_version = %q{1.3.7}
|
40
41
|
s.summary = %q{accepts_nested_attributes_for habtm}
|
41
42
|
s.test_files = [
|
42
|
-
|
43
|
+
|
43
44
|
"test/test_helper.rb"
|
44
45
|
]
|
45
46
|
|
@@ -1,22 +1,31 @@
|
|
1
1
|
module AnafHabtm
|
2
2
|
module ApplicationHelperMethods
|
3
3
|
def remove_child_link(name, form_builder)
|
4
|
-
form_builder.
|
4
|
+
value = form_builder.object.new_record? ? "1" : "false"
|
5
|
+
klass = form_builder.object.class.name.underscore
|
6
|
+
form_builder.hidden_field(:_destroy, {:value=>value, "data-remove"=>klass}) +
|
7
|
+
link_to(name, options={}, html_options={"href"=>"#", "class"=>"remove-child-link", :tabindex=> "0"})
|
5
8
|
end
|
6
9
|
|
7
10
|
def add_child_link(name, child, form_builder)
|
8
11
|
# puts "||#{form_builder}||"
|
9
|
-
|
10
|
-
|
12
|
+
new_form = new_child_fields(child, form_builder)
|
13
|
+
raw(content_tag(:div, new_form, {:id=>"#{child}_template", :class=>"form-template"}, escape=false))+
|
14
|
+
link_to(name, options={}, html_options={"href"=>"#", "class"=>"add-child-link", "data-class-name"=>child})
|
11
15
|
end
|
12
16
|
|
13
17
|
def new_child_fields(child, form_builder)
|
14
18
|
output = ""
|
15
|
-
form_builder.fields_for(child.pluralize.to_sym, child.camelize.constantize.new, :child_index =>
|
19
|
+
form_builder.fields_for(child.pluralize.to_sym, child.camelize.constantize.new, :child_index => "__#{child}_id__") do |f|
|
16
20
|
output += render(:partial => child.underscore, :locals => { :f => f })
|
17
21
|
end
|
18
22
|
output
|
19
23
|
end
|
24
|
+
|
25
|
+
def tfwac(f, field, controller)
|
26
|
+
f.text_field field, "data-auto-complete"=>true,
|
27
|
+
"data-auto-complete-url"=> eval("#{controller.to_s.underscore.tableize}_path(:format=>:json)")
|
28
|
+
end
|
20
29
|
end
|
21
30
|
end
|
22
31
|
|
@@ -1,14 +1,35 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
|
2
|
+
function setUpDocument($jq) {
|
3
|
+
|
4
|
+
$jq.find("input[type|=text][data-auto-complete|=true]").each( function(idx, el){
|
5
|
+
$(el).autocomplete({
|
6
|
+
source: $(el).attr('data-auto-complete-url'),
|
7
|
+
minLength: 2
|
8
|
+
});
|
4
9
|
});
|
5
|
-
}
|
6
10
|
|
7
|
-
function
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
$jq.find("a.add-child-link").click( function() {
|
12
|
+
klass = $(this).attr('data-class-name');
|
13
|
+
$el = $(this).prev().children().first().clone();
|
14
|
+
new_id=new Date().getTime()
|
15
|
+
$el.html($el.html().replace(new RegExp('__'+klass+'_id__', 'g'), new_id));
|
16
|
+
$el.find('input[data-remove|='+klass+']').attr('value', 'false');
|
17
|
+
$(this).closest('.child').find('.'+klass+'_children').first()
|
18
|
+
.append($el).show();
|
19
|
+
setUpDocument($el);
|
20
|
+
return false;
|
21
|
+
});
|
22
|
+
|
23
|
+
$jq.find('a.remove-child-link').click( function() {
|
24
|
+
$(this).prev('input[type|=hidden]').val('1');
|
25
|
+
$(this).closest('.child').hide();
|
26
|
+
return false;
|
27
|
+
});
|
13
28
|
}
|
14
29
|
|
30
|
+
$(function () {
|
31
|
+
setUpDocument($("body"));
|
32
|
+
|
33
|
+
});
|
34
|
+
|
35
|
+
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anaf_habtm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 183
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 84
|
10
|
+
version: 0.0.84
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tyler Gannon
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-13 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- lib/anaf_habtm/hash.rb
|
40
40
|
- lib/anaf_habtm/string_reader.rb
|
41
41
|
- lib/generators/anaf_habtm/anaf_habtm_generator.rb
|
42
|
+
- lib/generators/anaf_habtm/assets/nested_attributes.css
|
42
43
|
- lib/generators/anaf_habtm/assets/nested_attributes.js
|
43
44
|
- rails/init.rb
|
44
45
|
- test/anaf_habtm_test.rb
|
@@ -79,5 +80,4 @@ signing_key:
|
|
79
80
|
specification_version: 3
|
80
81
|
summary: accepts_nested_attributes_for habtm
|
81
82
|
test_files:
|
82
|
-
- test/anaf_habtm_test.rb
|
83
83
|
- test/test_helper.rb
|