dynamic_fields_for_rails 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -1
  3. data/lib/dynamic_fields_for_rails/version.rb +1 -1
  4. metadata +9 -184
  5. data/.gitignore +0 -18
  6. data/.rubocop.yml +0 -87
  7. data/.ruby-version +0 -1
  8. data/Gemfile +0 -6
  9. data/dynamic_fields_for_rails.gemspec +0 -28
  10. data/test/config/active_record.rb +0 -15
  11. data/test/dummy/Rakefile +0 -9
  12. data/test/dummy/app/controllers/application_controller.rb +0 -5
  13. data/test/dummy/app/helpers/application_helper.rb +0 -4
  14. data/test/dummy/app/models/application_record.rb +0 -5
  15. data/test/dummy/app/models/child.rb +0 -4
  16. data/test/dummy/app/models/parent.rb +0 -6
  17. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  18. data/test/dummy/app/views/parents/form.html.erb +0 -1
  19. data/test/dummy/config/application.rb +0 -45
  20. data/test/dummy/config/boot.rb +0 -12
  21. data/test/dummy/config/database.yml +0 -22
  22. data/test/dummy/config/environment.rb +0 -7
  23. data/test/dummy/config/environments/development.rb +0 -26
  24. data/test/dummy/config/environments/production.rb +0 -52
  25. data/test/dummy/config/environments/test.rb +0 -35
  26. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -9
  27. data/test/dummy/config/initializers/inflections.rb +0 -12
  28. data/test/dummy/config/initializers/mime_types.rb +0 -7
  29. data/test/dummy/config/initializers/secret_token.rb +0 -9
  30. data/test/dummy/config/initializers/session_store.rb +0 -10
  31. data/test/dummy/config/locales/en.yml +0 -5
  32. data/test/dummy/config/routes.rb +0 -61
  33. data/test/dummy/config.ru +0 -6
  34. data/test/dummy/db/development.sqlite3 +0 -0
  35. data/test/dummy/db/migrate/20130423140255_create_parents.rb +0 -7
  36. data/test/dummy/db/migrate/20130423140307_create_children.rb +0 -10
  37. data/test/dummy/db/schema.rb +0 -26
  38. data/test/dummy/db/test.sqlite3 +0 -0
  39. data/test/dummy/log/development.log +0 -8
  40. data/test/dummy/log/test.log +0 -2047
  41. data/test/dummy/public/404.html +0 -26
  42. data/test/dummy/public/422.html +0 -26
  43. data/test/dummy/public/500.html +0 -26
  44. data/test/dummy/public/javascripts/application.js +0 -2
  45. data/test/dummy/public/javascripts/controls.js +0 -965
  46. data/test/dummy/public/javascripts/dragdrop.js +0 -974
  47. data/test/dummy/public/javascripts/effects.js +0 -1123
  48. data/test/dummy/public/javascripts/prototype.js +0 -6001
  49. data/test/dummy/public/javascripts/rails.js +0 -202
  50. data/test/dummy/script/rails +0 -8
  51. data/test/dynamic_fields_for_helper_test.rb +0 -9
  52. data/test/link_to_add_fields_test.rb +0 -36
  53. data/test/link_to_delete_fields_test.rb +0 -42
  54. data/test/test_helper.rb +0 -19
@@ -1,202 +0,0 @@
1
- (function() {
2
- Ajax.Responders.register({
3
- onCreate: function(request) {
4
- var token = $$('meta[name=csrf-token]')[0];
5
- if (token) {
6
- if (!request.options.requestHeaders) request.options.requestHeaders = {};
7
- request.options.requestHeaders['X-CSRF-Token'] = token.readAttribute('content');
8
- }
9
- }
10
- });
11
-
12
- // Technique from Juriy Zaytsev
13
- // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
14
- function isEventSupported(eventName) {
15
- var el = document.createElement('div');
16
- eventName = 'on' + eventName;
17
- var isSupported = (eventName in el);
18
- if (!isSupported) {
19
- el.setAttribute(eventName, 'return;');
20
- isSupported = typeof el[eventName] == 'function';
21
- }
22
- el = null;
23
- return isSupported;
24
- }
25
-
26
- function isForm(element) {
27
- return Object.isElement(element) && element.nodeName.toUpperCase() == 'FORM';
28
- }
29
-
30
- function isInput(element) {
31
- if (Object.isElement(element)) {
32
- var name = element.nodeName.toUpperCase();
33
- return name == 'INPUT' || name == 'SELECT' || name == 'TEXTAREA';
34
- }
35
- else return false;
36
- }
37
-
38
- var submitBubbles = isEventSupported('submit'),
39
- changeBubbles = isEventSupported('change');
40
-
41
- if (!submitBubbles || !changeBubbles) {
42
- // augment the Event.Handler class to observe custom events when needed
43
- Event.Handler.prototype.initialize = Event.Handler.prototype.initialize.wrap(
44
- function(init, element, eventName, selector, callback) {
45
- init(element, eventName, selector, callback);
46
- // is the handler being attached to an element that doesn't support this event?
47
- if ( (!submitBubbles && this.eventName == 'submit' && !isForm(this.element)) ||
48
- (!changeBubbles && this.eventName == 'change' && !isInput(this.element)) ) {
49
- // "submit" => "emulated:submit"
50
- this.eventName = 'emulated:' + this.eventName;
51
- }
52
- }
53
- );
54
- }
55
-
56
- if (!submitBubbles) {
57
- // discover forms on the page by observing focus events which always bubble
58
- document.on('focusin', 'form', function(focusEvent, form) {
59
- // special handler for the real "submit" event (one-time operation)
60
- if (!form.retrieve('emulated:submit')) {
61
- form.on('submit', function(submitEvent) {
62
- var emulated = form.fire('emulated:submit', submitEvent, true);
63
- // if custom event received preventDefault, cancel the real one too
64
- if (emulated.returnValue === false) submitEvent.preventDefault();
65
- });
66
- form.store('emulated:submit', true);
67
- }
68
- });
69
- }
70
-
71
- if (!changeBubbles) {
72
- // discover form inputs on the page
73
- document.on('focusin', 'input, select, textarea', function(focusEvent, input) {
74
- // special handler for real "change" events
75
- if (!input.retrieve('emulated:change')) {
76
- input.on('change', function(changeEvent) {
77
- input.fire('emulated:change', changeEvent, true);
78
- });
79
- input.store('emulated:change', true);
80
- }
81
- });
82
- }
83
-
84
- function handleRemote(element) {
85
- var method, url, params;
86
-
87
- var event = element.fire("ajax:before");
88
- if (event.stopped) return false;
89
-
90
- if (element.tagName.toLowerCase() === 'form') {
91
- method = element.readAttribute('method') || 'post';
92
- url = element.readAttribute('action');
93
- // serialize the form with respect to the submit button that was pressed
94
- params = element.serialize({ submit: element.retrieve('rails:submit-button') });
95
- // clear the pressed submit button information
96
- element.store('rails:submit-button', null);
97
- } else {
98
- method = element.readAttribute('data-method') || 'get';
99
- url = element.readAttribute('href');
100
- params = {};
101
- }
102
-
103
- new Ajax.Request(url, {
104
- method: method,
105
- parameters: params,
106
- evalScripts: true,
107
-
108
- onCreate: function(response) { element.fire("ajax:create", response); },
109
- onComplete: function(response) { element.fire("ajax:complete", response); },
110
- onSuccess: function(response) { element.fire("ajax:success", response); },
111
- onFailure: function(response) { element.fire("ajax:failure", response); }
112
- });
113
-
114
- element.fire("ajax:after");
115
- }
116
-
117
- function insertHiddenField(form, name, value) {
118
- form.insert(new Element('input', { type: 'hidden', name: name, value: value }));
119
- }
120
-
121
- function handleMethod(element) {
122
- var method = element.readAttribute('data-method'),
123
- url = element.readAttribute('href'),
124
- csrf_param = $$('meta[name=csrf-param]')[0],
125
- csrf_token = $$('meta[name=csrf-token]')[0];
126
-
127
- var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
128
- $(element.parentNode).insert(form);
129
-
130
- if (method !== 'post') {
131
- insertHiddenField(form, '_method', method);
132
- }
133
-
134
- if (csrf_param) {
135
- insertHiddenField(form, csrf_param.readAttribute('content'), csrf_token.readAttribute('content'));
136
- }
137
-
138
- form.submit();
139
- }
140
-
141
- function disableFormElements(form) {
142
- form.select('input[type=submit][data-disable-with]').each(function(input) {
143
- input.store('rails:original-value', input.getValue());
144
- input.setValue(input.readAttribute('data-disable-with')).disable();
145
- });
146
- }
147
-
148
- function enableFormElements(form) {
149
- form.select('input[type=submit][data-disable-with]').each(function(input) {
150
- input.setValue(input.retrieve('rails:original-value')).enable();
151
- });
152
- }
153
-
154
- function allowAction(element) {
155
- var message = element.readAttribute('data-confirm');
156
- return !message || confirm(message);
157
- }
158
-
159
- document.on('click', 'a[data-confirm], a[data-remote], a[data-method]', function(event, link) {
160
- if (!allowAction(link)) {
161
- event.stop();
162
- return false;
163
- }
164
-
165
- if (link.readAttribute('data-remote')) {
166
- handleRemote(link);
167
- event.stop();
168
- } else if (link.readAttribute('data-method')) {
169
- handleMethod(link);
170
- event.stop();
171
- }
172
- });
173
-
174
- document.on("click", "form input[type=submit], form button[type=submit], form button:not([type])", function(event, button) {
175
- // register the pressed submit button
176
- event.findElement('form').store('rails:submit-button', button.name || false);
177
- });
178
-
179
- document.on("submit", function(event) {
180
- var form = event.findElement();
181
-
182
- if (!allowAction(form)) {
183
- event.stop();
184
- return false;
185
- }
186
-
187
- if (form.readAttribute('data-remote')) {
188
- handleRemote(form);
189
- event.stop();
190
- } else {
191
- disableFormElements(form);
192
- }
193
- });
194
-
195
- document.on('ajax:create', 'form', function(event, form) {
196
- if (form == event.findElement()) disableFormElements(form);
197
- });
198
-
199
- document.on('ajax:complete', 'form', function(event, form) {
200
- if (form == event.findElement()) enableFormElements(form);
201
- });
202
- })();
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
5
-
6
- APP_PATH = File.expand_path('../config/application', __dir__)
7
- require File.expand_path('../config/boot', __dir__)
8
- require 'rails/commands'
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class DynamicFieldsForHelperTest < ActiveSupport::TestCase
6
- test 'truth' do
7
- assert_kind_of Module, DynamicFieldsForHelper
8
- end
9
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class LinkToAddFieldsTest < ActionView::TestCase
6
- tests ActionView::Helpers::FormHelper
7
-
8
- include DynamicFieldsForHelper
9
-
10
- def form_for(*)
11
- @output_buffer = super
12
- end
13
-
14
- def setup
15
- @parent = Parent.create
16
- @parent.children.build
17
- end
18
-
19
- test 'generates a add fields link' do
20
- form_for(@parent, url: '/') do |form|
21
- link_to_add_fields(form, 'children', name: 'Test')
22
- end
23
-
24
- assert_match(%r{<a(.*)class=\"add_fields(.*)\"(.*)>Test<\/a>}, @output_buffer)
25
- end
26
-
27
- test 'generates a add fields link with block if it is given' do
28
- form_for(@parent, url: '/') do |form|
29
- link_to_add_fields form, 'children' do
30
- content_tag 'div', 'Test'
31
- end
32
- end
33
-
34
- assert_match(%r{<a(.*)class=\"add_fields(.*)\"(.*)><div>Test<\/div><\/a>}, @output_buffer)
35
- end
36
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class LinkToDeleteFieldsTest < ActionView::TestCase
6
- tests ActionView::Helpers::FormHelper
7
-
8
- include DynamicFieldsForHelper
9
-
10
- def form_for(*)
11
- @output_buffer = super
12
- end
13
-
14
- def setup
15
- @parent = Parent.create
16
- @parent.children.create
17
- end
18
-
19
- test 'generates a delete fields link' do
20
- form_for(@parent, url: '/') do |form|
21
- form.fields_for :children, @parent.children do |fields|
22
- link_to_delete_fields(fields, name: 'Test')
23
- end
24
- end
25
-
26
- assert_match(%r{<input(.*)value=\"false\"(.*)name=\"parent\[children_attributes\](.*)\[_destroy\]\"(.*)\/>}, @output_buffer)
27
- assert_match(%r{<a(.*)class=\"remove_fields(.*)\"(.*)>Test<\/a>}, @output_buffer)
28
- end
29
-
30
- test 'generates a deletes fields link with block if it is given' do
31
- form_for(@parent, url: '/') do |form|
32
- form.fields_for :children, @parent.children do |fields|
33
- link_to_delete_fields fields do
34
- content_tag 'div', 'Test'
35
- end
36
- end
37
- end
38
-
39
- assert_match(%r{<input(.*)value=\"false\"(.*)name=\"parent\[children_attributes\](.*)\[_destroy\]\"(.*)\/>}, @output_buffer)
40
- assert_match(%r{<a(.*)class=\"remove_fields(.*)\"(.*)><div>Test<\/div><\/a>}, @output_buffer)
41
- end
42
- end
data/test/test_helper.rb DELETED
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rubygems'
4
- require 'bundler/setup'
5
-
6
- ENV['RAILS_ENV'] = 'test'
7
- require File.expand_path('dummy/config/environment.rb', __dir__)
8
- require 'rails/test_help'
9
- require 'mocha/setup'
10
- require 'active_support/test_case'
11
- require 'active_support/inflector'
12
-
13
- Rails.backtrace_cleaner.remove_silencers!
14
-
15
- ENGINE_RAILS_ROOT = File.join(File.dirname(__FILE__), '../')
16
-
17
- # Load support files
18
- Dir[File.join(ENGINE_RAILS_ROOT, 'test/support/**/*.rb')].each { |f| require f }
19
- Dir[File.join(ENGINE_RAILS_ROOT, 'test/config/**/*.rb')].each { |f| require f }