dynamic_fieldsets 0.1.4 → 0.1.5

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/CHANGELOG CHANGED
@@ -1,5 +1,14 @@
1
1
  == unreleased changes
2
2
 
3
+ == 0.1.5
4
+
5
+ * Fixed a missing association in the dependency model to the dependency clause model
6
+ * Fixed a major issue in the dependency code where only the first dependency on the form would load
7
+ * Added a new option to the model mixin called initialize_on_create. When set to true, it creates the fieldset associators when the model instance is created.
8
+ * Moved the fieldset header and footer to partials so they can be overridden
9
+
10
+ == 0.1.4
11
+
3
12
  * Removed unloadable from the controllers because they were causing an issue when the controller generator was run
4
13
  * Updated the fieldset children manager page to show any type of field
5
14
  * Updated dependency system model validations so that they trigger correctly on create
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -88,9 +88,8 @@ module DynamicFieldsetsHelper
88
88
  # @param [Hash] values Stored values for the fieldset
89
89
  # @return [Array] The HTML elements for the fieldset
90
90
  def fieldset_renderer(fsa, fieldset, values, form_type)
91
- lines = ["<div id='fieldset-#{fieldset.id}' class='inputs'>"]
92
- lines.push "<h3 class='name'>#{fieldset.name}</h3>"
93
- lines.push "<ol>"
91
+ lines = []
92
+ lines.push render(:partial => "/dynamic_fieldsets/shared/fieldset_header", :locals => {:fieldset => fieldset})
94
93
 
95
94
  # this returns field/fieldset objects rather than fieldset children
96
95
  # that is why this code looks like it is accessing odd objects
@@ -103,8 +102,7 @@ module DynamicFieldsetsHelper
103
102
  end
104
103
  end
105
104
 
106
- lines.push "</ol>"
107
- lines.push "</div>"
105
+ lines.push render(:partial => "/dynamic_fieldsets/shared/fieldset_footer", :locals => {:fieldset => fieldset})
108
106
 
109
107
  return lines
110
108
  end
@@ -11,6 +11,7 @@ module DynamicFieldsets
11
11
  # Relations
12
12
 
13
13
  belongs_to :fieldset_child
14
+ belongs_to :dependency_clause
14
15
 
15
16
  # Validations
16
17
  validates_presence_of :fieldset_child
@@ -72,46 +72,44 @@ module DynamicFieldsets
72
72
  end
73
73
 
74
74
 
75
- # OMG COMMENT
75
+ # Converts the list of fields with dependencies generated by the look_for_dependents method into a hash
76
+ # The hash contains the actual dependencies for the list of fields that have them
76
77
  #
77
- # TODO: Fill in actual comments
78
- #
79
- # @params - stuff
80
- # @returns - other stuff
78
+ # @return [Hash] dependent fields for fields in the fieldset
81
79
  def dependency_child_hash
82
- @fieldset_child_collection = []
83
- look_for_dependents(self.fieldset)
84
-
80
+ fieldset_child_collection = look_for_dependents(self.fieldset)
81
+
85
82
  output = {}
86
- for fieldset_child in @fieldset_child_collection
83
+ fieldset_child_collection.each do |fieldset_child|
87
84
  output[fieldset_child.id] = {}
88
- for dependency in fieldset_child.dependencies
85
+ fieldset_child.dependencies.each do |dependency|
89
86
  dependency_group = dependency.dependency_clause.dependency_group
90
87
  output[fieldset_child.id][dependency_group.id] = dependency_group.to_hash
91
88
  end
92
89
  end
93
- output
90
+ return output
94
91
  end
95
92
 
96
93
 
97
- # OMG COMMENT
94
+ # Gets a list of fields in the given fieldset that have dependencies
95
+ # I am not exactly sure why this method is necessary (JH 3-8-2012)
96
+ # It seems like we could just make the dependency_child_hash method run recursively
98
97
  #
99
- # TODO: Fill in actual comments
100
- #
101
- # @params - stuff
102
- # @returns - other stuff
98
+ # @param parent_fieldset [DynamicFieldsets::Fieldset] The fieldset to check inside of
99
+ # @return [Array] The list of fields with dependencies
103
100
  def look_for_dependents(parent_fieldset)
104
- for fieldset_child in parent_fieldset.fieldset_children
105
- if (fieldset_child.child_type == "DynamicFieldsets::Field") && (!fieldset_child.dependencies.empty?)
106
- @fieldset_child_collection.push(fieldset_child)
107
- return
108
- elsif (fieldset_child.child_type == "DynamicFieldsets::Field") && (fieldset_child.dependencies.empty?)
109
- return
110
- else
111
- look_for_dependents(fieldset_child.child)
101
+ output = []
102
+ parent_fieldset.fieldset_children.each do |fieldset_child|
103
+ if fieldset_child.child_type == "DynamicFieldsets::Field"
104
+ if !fieldset_child.dependencies.empty?
105
+ output.push fieldset_child
106
+ # else then next
107
+ end
108
+ else # if child type is a fieldset, then recurse
109
+ output += look_for_dependents(fieldset_child.child)
112
110
  end
113
111
  end
112
+ return output
114
113
  end
115
-
116
114
  end
117
115
  end
@@ -0,0 +1,3 @@
1
+ <div id='fieldset-<%=fieldset.id%>' class='inputs'>
2
+ <h3 class='name'><%=fieldset.name%></h3>
3
+ <ol>
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "dynamic_fieldsets"
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jeremiah Hemphill", "Ethan Pemble", "John Carter"]
12
- s.date = "2012-03-06"
12
+ s.date = "2012-03-12"
13
13
  s.description = "Dynamic fieldsets for rails controllers"
14
14
  s.email = "jeremiah@cloudspace.com"
15
15
  s.extra_rdoc_files = [
@@ -90,6 +90,8 @@ Gem::Specification.new do |s|
90
90
  "app/views/dynamic_fieldsets/form_partials/_select_field.html.erb",
91
91
  "app/views/dynamic_fieldsets/form_partials/_text_field.html.erb",
92
92
  "app/views/dynamic_fieldsets/form_partials/_textarea_field.html.erb",
93
+ "app/views/dynamic_fieldsets/shared/_fieldset_footer.html.erb",
94
+ "app/views/dynamic_fieldsets/shared/_fieldset_header.html.erb",
93
95
  "app/views/dynamic_fieldsets/shared/_javascript_watcher.html.erb",
94
96
  "app/views/dynamic_fieldsets/shared/_nested_model_javascript.html.erb",
95
97
  "app/views/dynamic_fieldsets/show_partials/_show_incomplete.html.erb",
@@ -16,22 +16,32 @@ module DynamicFieldsets
16
16
  # fieldset as the key:
17
17
  # :child_form => {options}
18
18
  # Options:
19
- # Fieldset: The unique name of the fieldset the class is associated with
20
- # Multiple: Boolean value to allow multiple answer sets for the same fieldset in the class.
19
+ # fieldset (mandatory): The unique name of the fieldset the class is associated with
20
+ # multiple (optional): Boolean value to allow multiple answer sets for the same fieldset in the class.
21
21
  # Deafult to false. Not curently implemented (7-25-2011).
22
+ # initialize_on_create (optional): Create the fieldste associator after create
22
23
  #
23
24
  # @param [Hash] args A hash of arguments for the fieldsets.
24
25
  def acts_as_dynamic_fieldset(args)
25
26
  mattr_accessor :dynamic_fieldsets unless self.respond_to?(:dynamic_fieldsets)
26
27
  self.dynamic_fieldsets = {} unless self.dynamic_fieldsets.is_a?(Hash)
27
28
 
29
+ # default values for the arguments
30
+ # fieldset is mandatory
31
+ defaults = {
32
+ :multiple => false,
33
+ :initialize_on_create => false
34
+ }
35
+
28
36
  args.each_pair do |key, value|
29
- self.dynamic_fieldsets[key] = value
37
+ value_with_defaults = defaults.merge(value)
38
+ self.dynamic_fieldsets[key] = value_with_defaults
30
39
  end
31
40
 
32
41
  # hacky system to save fieldset values
33
42
  # needs to be refactored and tested
34
43
  mattr_accessor :dynamic_fieldset_values unless self.respond_to?(:dynamic_fieldset_values)
44
+ after_create :initialize_fieldset_associators
35
45
  after_save :save_dynamic_fieldsets
36
46
 
37
47
  include DynamicFieldsets::DynamicFieldsetsInModel::InstanceMethods
@@ -39,6 +49,16 @@ module DynamicFieldsets
39
49
  end
40
50
 
41
51
  module InstanceMethods
52
+
53
+ # If the fieldset is set to initialize_on_create, then attempt to create the fsa
54
+ def initialize_fieldset_associators
55
+ self.dynamic_fieldsets.each_pair do |key, options|
56
+ if options[:initialize_on_create]
57
+ fsa = fieldset_associator(key)
58
+ fsa.save if fsa.new_record?
59
+ end
60
+ end
61
+ end
42
62
 
43
63
  # Overrides the ActiveModel Validations run_validations! method
44
64
  # It additionally adds validations for the fields that are required
@@ -149,7 +169,7 @@ module DynamicFieldsets
149
169
  end
150
170
  return post
151
171
  end
152
-
172
+
153
173
  # Given the form values, finds the keys that correspond to fieldsets
154
174
  # then passes the value for the key to the fieldset associator object for saving into individual field records
155
175
  def save_dynamic_fieldsets
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: dynamic_fieldsets
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.4
5
+ version: 0.1.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jeremiah Hemphill
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2012-03-06 00:00:00 Z
15
+ date: 2012-03-12 00:00:00 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rails
@@ -295,6 +295,8 @@ files:
295
295
  - app/views/dynamic_fieldsets/form_partials/_select_field.html.erb
296
296
  - app/views/dynamic_fieldsets/form_partials/_text_field.html.erb
297
297
  - app/views/dynamic_fieldsets/form_partials/_textarea_field.html.erb
298
+ - app/views/dynamic_fieldsets/shared/_fieldset_footer.html.erb
299
+ - app/views/dynamic_fieldsets/shared/_fieldset_header.html.erb
298
300
  - app/views/dynamic_fieldsets/shared/_javascript_watcher.html.erb
299
301
  - app/views/dynamic_fieldsets/shared/_nested_model_javascript.html.erb
300
302
  - app/views/dynamic_fieldsets/show_partials/_show_incomplete.html.erb
@@ -429,7 +431,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
429
431
  requirements:
430
432
  - - ">="
431
433
  - !ruby/object:Gem::Version
432
- hash: -2714422766311375793
434
+ hash: -964161402791124361
433
435
  segments:
434
436
  - 0
435
437
  version: "0"