nested_fields 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock CHANGED
@@ -2,7 +2,7 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  git (1.2.5)
5
- jeweler (1.5.1)
5
+ jeweler (1.5.2)
6
6
  bundler (~> 1.0.0)
7
7
  git (>= 1.2.5)
8
8
  rake
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -1,22 +1,20 @@
1
1
  module NestedFieldsHelper
2
- def nested_fields_for(f, association, nested_partial=nil)
2
+ def nested_fields_for(f, association, options={}, &block)
3
3
  reflection = f.object.class.reflect_on_association(association)
4
4
  is_has_one = reflection.macro == :has_one
5
- nested_partial ||= "#{is_has_one ? association.to_s.pluralize : association}/fields"
5
+ options[:nested_partial] ||= "#{is_has_one ? association.to_s.pluralize : association}/fields"
6
6
 
7
7
  add = add_nested_fields_path :association => association,
8
8
  :builder => f.class,
9
- :nested_partial => nested_partial,
9
+ :nested_partial => options[:nested_partial],
10
10
  :parent_class => f.object.class,
11
11
  :parent_form => f.object_name
12
12
 
13
-
14
13
  partial = "nested_fields/#{'singular_' if is_has_one}nested_fieldset"
15
14
 
16
- locals = {:add_url => add,
17
- :association => association,
18
- :f => f,
19
- :nested_partial => nested_partial}
15
+ locals = {:add_url => add, :association => association, :f => f}
16
+
17
+ locals.merge!(options)
20
18
 
21
19
  if is_has_one
22
20
  associate = f.object.send(association);
@@ -29,6 +27,10 @@ module NestedFieldsHelper
29
27
  end
30
28
  end
31
29
 
32
- render partial, locals
30
+ if block_given?
31
+ render :layout => partial, :locals => locals, &block
32
+ else
33
+ render partial, locals
34
+ end
33
35
  end
34
36
  end
@@ -1,8 +1,8 @@
1
- <div class="nested_fields">
1
+ <%= content_tag :div, :class => :nested_fields, :style => ('display:none' if f.object._destroy) do %>
2
2
  <a href="#" class="remove_nested_fields">Remove</a>
3
3
 
4
4
  <div class="nested_fields_inputs">
5
5
  <%= render nested_partial, :f => f %>
6
6
  <%= f.hidden_field :_destroy %>
7
7
  </div>
8
- </div>
8
+ <% end %>
@@ -1,5 +1,11 @@
1
- <fieldset id="<%= association %>" class="nested_fieldset">
2
- <legend><%= association.to_s.titleize %></legend>
1
+ <% if local_assigns[:positioned_by] %>
2
+ <fieldset class="nested_fieldset positioned" data-positioned-by="<%= positioned_by %>">
3
+ <% else %>
4
+ <fieldset class="nested_fieldset">
5
+ <% end %>
6
+ <legend><%= local_assigns[:legend] || association.to_s.titleize %></legend>
7
+
8
+ <%= yield %>
3
9
 
4
10
  <a href="#" class="add_nested_fields" data-url="<%= add_url %>">Add</a>
5
11
 
@@ -1,10 +1,12 @@
1
- <fieldset id="<%= association %>" class="nested_fieldset">
2
- <legend><%= association.to_s.titleize %></legend>
1
+ <fieldset class="nested_fieldset">
2
+ <legend><%= local_assigns[:legend] || association.to_s.titleize %></legend>
3
+
4
+ <%= yield %>
3
5
 
4
6
  <%= f.fields_for association, associate, :builder => f.class do |nested_f| %>
5
7
  <label class="nested_one_label">
6
8
  <%= check_box_tag "has_#{association}", nil, !local_assigns[:has_zero], :class => :nested_fields_has_one %>
7
- <%= "Has #{association.to_s.titleize}?" %>
9
+ Has <%= association.to_s.titleize %>?
8
10
  </label>
9
11
 
10
12
  <%= nested_f.hidden_field :_destroy, :class => :destroy_nested_one, :value => local_assigns[:has_zero] ? 'true' : 'false' %>
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{nested_fields}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jason Murad"]
12
- s.date = %q{2010-12-21}
12
+ s.date = %q{2011-01-22}
13
13
  s.description = %q{Unobtrusive dynamic nested forms}
14
14
  s.email = %q{jason@thriess.com}
15
15
  s.extra_rdoc_files = [
@@ -28,3 +28,21 @@ $('.nested_fields_has_one').live('change', function() {
28
28
  $(hidden_field).val($(hidden_field).val() == 'true' ? 'false' : 'true');
29
29
  $(this).closest('.nested_fieldset').find('.nested_one').toggle();
30
30
  });
31
+
32
+ function reposition(nested_fieldset, pos_fld) {
33
+ $(nested_fieldset).find('> .nested_fields').each(function(i, nested_fields) {
34
+ $(nested_fields).find('input[id$="' + pos_fld + '"]').val(i);
35
+ });
36
+ }
37
+
38
+ $('.nested_fieldset').live('nested_fields_ready', function() {
39
+ var pos_fld = this.getAttribute('data-positioned-by');
40
+
41
+ if (pos_fld) {
42
+ reposition(this, pos_fld);
43
+
44
+ if (!$(this).hasClass('ui-sortable')) {
45
+ $(this).sortable({update: function() { reposition(this, pos_fld); }});
46
+ }
47
+ }
48
+ });
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jason Murad
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-21 00:00:00 -05:00
17
+ date: 2011-01-22 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -115,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
115
  requirements:
116
116
  - - ">="
117
117
  - !ruby/object:Gem::Version
118
- hash: -1304071014241017198
118
+ hash: -3511116076311787627
119
119
  segments:
120
120
  - 0
121
121
  version: "0"