dynamic_fieldsets 0.1.15 → 0.1.16

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.15
1
+ 0.1.16
@@ -186,7 +186,12 @@ module DynamicFieldsetsHelper
186
186
  # @return [String] The javascript variable that shows what fields have dependencies
187
187
  def javascript_renderer(fsa)
188
188
  unless fsa.id == nil
189
- rendered_javascript = "<script type='text/javascript'> var dynamic_fieldsets_dependencies = #{fsa.dependency_child_hash.to_json}; </script>"
189
+ rendered_javascript = "<script type='text/javascript'>
190
+ if ( typeof dynamic_fieldsets_dependencies == 'undefined' ){
191
+ var dynamic_fieldsets_dependencies = #{fsa.dependency_child_hash.to_json};
192
+ } else {
193
+ $.extend(dynamic_fieldsets_dependencies, #{fsa.dependency_child_hash.to_json});
194
+ }</script>"
190
195
  rendered_javascript += render "dynamic_fieldsets/shared/javascript_watcher"
191
196
  return rendered_javascript.html_safe
192
197
  else
@@ -84,7 +84,8 @@ module DynamicFieldsets
84
84
  output[fieldset_child.id] = {}
85
85
  fieldset_child.dependencies.each do |dependency|
86
86
  dependency_group = dependency.dependency_clause.dependency_group
87
- output[fieldset_child.id][dependency_group.id] = dependency_group.to_hash #if dependency_group.present?
87
+ output[fieldset_child.id][dependency_group.id] = dependency_group.to_hash
88
+ output[fieldset_child.id][dependency_group.id][:fieldset_associators] = dependency_group.fieldset_child.fieldset.fieldset_associators.collect(&:id)
88
89
  end
89
90
  end
90
91
  return output
@@ -1,7 +1,7 @@
1
1
  <script type='text/javascript'>
2
2
 
3
3
  // The only inputs we care about are visible... not hidden
4
- var all_inputs = $(":input:not(:hidden)").add("p[id^='fsa']");
4
+ var all_inputs = $(":input:not(:hidden)[id^=fsa]").add("p[id^='fsa']");
5
5
 
6
6
  //Return the fieldset child id for the input
7
7
  //This uniquely associated the fieldset child with the fieldset associator
@@ -103,7 +103,6 @@ all_inputs.change( function() {
103
103
  field = $(this);
104
104
  var type = get_field_type(field);
105
105
  var fieldset_child_id = get_fieldset_child_id(field, type)
106
- var fieldset_associator_id = get_fieldset_associator_id(field);
107
106
 
108
107
  var user_inputs = {}
109
108
  $.each(all_inputs, function(index, input){
@@ -111,10 +110,11 @@ all_inputs.change( function() {
111
110
  var all_fieldset_child_id = get_fieldset_child_id($(input), all_type)
112
111
  user_inputs[all_fieldset_child_id] = get_input_value($(input), all_type);
113
112
  });
114
-
113
+
115
114
  if (fieldset_child_id in dynamic_fieldsets_dependencies) {
116
115
  $.each(dynamic_fieldsets_dependencies[fieldset_child_id], function(index, group) {
117
- update_dependency_group_for_fieldset_child(fieldset_child_id, group, user_inputs, fieldset_associator_id);
116
+ fieldset_associator_ids = dynamic_fieldsets_dependencies[fieldset_child_id][index]["fieldset_associators"];
117
+ update_dependency_group_for_fieldset_child(fieldset_child_id, group, user_inputs, fieldset_associator_ids);
118
118
  });
119
119
  }
120
120
  });
@@ -122,12 +122,15 @@ all_inputs.change( function() {
122
122
  // checks the clauses for a dependency group and runs the action
123
123
  // group: the dependency group
124
124
  // user_input: the input from the form
125
- function update_dependency_group_for_fieldset_child(fieldset_child_id, group, user_inputs, fieldset_associator_id) {
125
+ function update_dependency_group_for_fieldset_child(fieldset_child_id, group, user_inputs, fieldset_associator_ids) {
126
126
  var action = group['action'];
127
127
  var group_fsc_id = group['fieldset_child_id'];
128
128
  var group_field_id = group['field_id'];
129
- var group_field = '<%= DynamicFieldsets.config.form_fieldset_associator_prefix %>' + fieldset_associator_id + '_' + '<%=DynamicFieldsets.config.form_field_prefix %>' + group_fsc_id;
130
- dependency_action(all_dependency_clauses_true(fieldset_child_id, group, user_inputs), action, group_field, 0 )
129
+ var group_fields = []
130
+ $.each(fieldset_associator_ids, function(index, fsa_id) {
131
+ group_fields[index] = '<%= DynamicFieldsets.config.form_fieldset_associator_prefix %>' + fsa_id + '_' + '<%=DynamicFieldsets.config.form_field_prefix %>' + group_fsc_id;
132
+ });
133
+ dependency_action(all_dependency_clauses_true(fieldset_child_id, group, user_inputs), action, group_fields, 0 )
131
134
  }
132
135
 
133
136
  //all dependencies clauses are ANDed
@@ -197,32 +200,34 @@ function evaluate_dependency(user_value, relationship, stored_value) {
197
200
  // success_flag: whether the dependency group returned true or false
198
201
  // action: the type of update to apply to the field
199
202
  // group_field: the field to update (generally not the field that triggered the change)
200
- function dependency_action(success_flag, action, group_field, counter) {
201
- if (success_flag){
202
- switch(action)
203
- {
204
- case 'show':
205
- $('[id$=' + group_field +']').show();
206
- case 'enable':
207
- $('#' + group_field + ' :input').removeAttr('disabled');
208
- }
209
- } else {
210
- switch(action)
211
- {
212
- case 'show':
213
- $('[id$=' + group_field +']').hide();
214
- case 'enable':
215
- $('#' + group_field + ' :input').attr('disabled', true);
216
- }
203
+ function dependency_action(success_flag, action, group_fields, counter) {
204
+ $.each(group_fields, function(index, group_field){
205
+ if (success_flag){
206
+ switch(action)
207
+ {
208
+ case 'show':
209
+ $('[id$=' + group_field +']').show();
210
+ case 'enable':
211
+ $('#' + group_field + ' :input').removeAttr('disabled');
212
+ }
217
213
 
218
- clear_unused_fields(group_field)
214
+ } else {
215
+ switch(action)
216
+ {
217
+ case 'show':
218
+ $('[id$=' + group_field +']').hide();
219
+ case 'enable':
220
+ $('#' + group_field + ' :input').attr('disabled', true);
221
+ }
222
+
223
+ clear_unused_fields(group_field)
219
224
 
220
- //save from infinite recursion, only goes as deep as there are dependency groups
221
- if( counter < Object.keys(dynamic_fieldsets_dependencies).length ) {
222
- nested_dependencies(success_flag, action, group_field, counter)
223
- }
224
- }
225
-
225
+ //save from infinite recursion, only goes as deep as there are dependency groups
226
+ if( counter < Object.keys(dynamic_fieldsets_dependencies).length ) {
227
+ nested_dependencies(success_flag, action, group_field, counter)
228
+ }
229
+ }
230
+ });
226
231
  };
227
232
 
228
233
  function clear_unused_fields(group_field) {
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "dynamic_fieldsets"
8
- s.version = "0.1.15"
8
+ s.version = "0.1.16"
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 = "2013-08-14"
12
+ s.date = "2013-08-15"
13
13
  s.description = "Dynamic fieldsets for rails controllers"
14
14
  s.email = "jeremiah@cloudspace.com"
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamic_fieldsets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.15
4
+ version: 0.1.16
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-08-14 00:00:00.000000000 Z
14
+ date: 2013-08-15 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -520,7 +520,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
520
520
  version: '0'
521
521
  segments:
522
522
  - 0
523
- hash: -4050550333899168397
523
+ hash: 433715359672350075
524
524
  required_rubygems_version: !ruby/object:Gem::Requirement
525
525
  none: false
526
526
  requirements: