anaf_habtm 0.0.85 → 0.0.86

Sign up to get free protection for your applications and to get access to all the features.
data/anaf_habtm.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{anaf_habtm}
8
- s.version = "0.0.85"
8
+ s.version = "0.0.86"
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"]
@@ -3,15 +3,15 @@ module AnafHabtm
3
3
  def remove_child_link(name, form_builder)
4
4
  value = form_builder.object.new_record? ? "1" : "false"
5
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"})
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"})
8
8
  end
9
9
 
10
10
  def add_child_link(name, child, form_builder)
11
11
  # puts "||#{form_builder}||"
12
12
  new_form = new_child_fields(child, form_builder)
13
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})
14
+ link_to(name, options={}, html_options={"href"=>"#", "class"=>"add-child-link", "data-class-name"=>child})
15
15
  end
16
16
 
17
17
  def new_child_fields(child, form_builder)
@@ -20,13 +20,19 @@ module AnafHabtm
20
20
  output += render(:partial => child.underscore, :locals => { :f => f })
21
21
  end
22
22
  output
23
- end
23
+ end
24
24
 
25
25
  def tfwac(f, field, controller, opts={})
26
- opts["data-auto-complete"]=true
26
+ opts["data-auto-complete"]='tf'
27
27
  opts["data-auto-complete-url"]=eval("#{controller.to_s.underscore.tableize}_path(:format=>:json)")
28
28
  f.text_field field, opts
29
29
  end
30
+
31
+ def text_area_with_auto_complete(f, field, controller, opts={})
32
+ opts["data-auto-complete"]='ta'
33
+ opts["data-auto-complete-url"]=eval("#{controller.to_s.underscore.tableize}_path(:format=>:json)")
34
+ f.text_area field, opts
35
+ end
30
36
  end
31
37
  end
32
38
 
@@ -1,11 +1,14 @@
1
1
 
2
2
  function setUpDocument($jq) {
3
-
4
- $jq.find("input[type|=text][data-auto-complete|=true]").each( function(idx, el){
3
+ $jq.find("input[data-auto-complete|=tf]").each( function(idx, el){
5
4
  $(el).autocomplete({
6
5
  source: $(el).attr('data-auto-complete-url'),
7
6
  minLength: 2
8
- });
7
+ });
8
+ });
9
+
10
+ $jq.find("textarea[data-auto-complete|=ta]").each( function(idx, el){
11
+ setTextAreaAutoComplete($(el));
9
12
  });
10
13
 
11
14
  $jq.find("a.add-child-link").click( function() {
@@ -19,17 +22,53 @@ function setUpDocument($jq) {
19
22
  setUpDocument($el);
20
23
  return false;
21
24
  });
22
-
25
+
23
26
  $jq.find('a.remove-child-link').click( function() {
24
27
  $(this).prev('input[type|=hidden]').val('1');
25
28
  $(this).closest('.child').hide();
26
- return false;
29
+ return false;
27
30
  });
28
31
  }
29
32
 
30
- $(function () {
33
+ $(function () {
31
34
  setUpDocument($("body"));
32
-
33
- });
34
35
 
36
+ });
37
+ var text_area_delimiter = '\n';
38
+ function split(val) {
39
+ return val.split(new RegExp(text_area_delimiter+'\s*'));
40
+ }
41
+ function extractLast(term) {
42
+ return split(term).pop();
43
+ }
44
+ function setTextAreaAutoComplete($el) {
45
+ $el.autocomplete({
46
+ source: function(request, response) {
47
+ $.getJSON($el.attr('data-auto-complete-url'), {
48
+ term: extractLast(request.term)
49
+ }, response);
50
+ },
51
+ search: function() {
52
+ // custom minLength
53
+ var term = extractLast(this.value);
54
+ if (term.length < 2) {
55
+ return false;
56
+ }
57
+ },
58
+ focus: function() {
59
+ // prevent value inserted on focus
60
+ return false;
61
+ },
62
+ select: function(event, ui) {
63
+ var terms = split( this.value );
64
+ terms.pop(); // remove the current input
65
+ terms.push( ui.item.value ); // add the selected item
66
+ // add placeholder to get the comma-and-space at the end
67
+ terms.push("");
68
+ this.value = terms.join(text_area_delimiter);
69
+ return false;
70
+ }
71
+ });
72
+
73
+ }
35
74
 
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: 181
4
+ hash: 179
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 85
10
- version: 0.0.85
9
+ - 86
10
+ version: 0.0.86
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tyler Gannon