saasaparilla 0.1.8 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -0
- data/Gemfile +5 -5
- data/app/controllers/saasaparilla/admin/subscriptions_controller.rb +1 -1
- data/app/controllers/saasaparilla/subscription_controller.rb +1 -2
- data/app/models/billing_activity.rb +2 -0
- data/app/models/contact_info.rb +2 -0
- data/app/models/credit_card.rb +2 -0
- data/app/models/invoice.rb +2 -0
- data/app/models/invoice_line_item.rb +2 -1
- data/app/models/plan.rb +2 -0
- data/app/models/subscription.rb +18 -6
- data/app/models/transaction.rb +1 -0
- data/app/views/saasaparilla/notifier/invoice_created.html.haml +1 -0
- data/app/views/saasaparilla/subscription/new.html.haml +2 -2
- data/config/routes.rb +11 -11
- data/lib/saasaparilla/engine.rb +1 -1
- data/lib/saasaparilla/version.rb +1 -1
- data/spec/dummy/config/saasaparilla.yml +2 -2
- data/spec/dummy/public/javascripts/jquery_ujs.js +373 -0
- data/spec/factories/factories.rb +1 -1
- data/spec/mailers/notifier_spec.rb +1 -1
- data/spec/models/credit_card_spec.rb +2 -2
- data/spec/models/plan_spec.rb +3 -1
- data/spec/models/subscription_spec.rb +3 -3
- data/spec/requests/admin_subscriptions_spec.rb +2 -1
- data/spec/requests/billing_history_spec.rb +1 -0
- data/spec/requests/credit_cards_spec.rb +1 -1
- data/spec/requests/subscriptions_spec.rb +5 -4
- data/spec/spec_helper.rb +4 -1
- metadata +160 -51
- data/spec/dummy/public/javascripts/rails.js +0 -159
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saasaparilla
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,12 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
14
|
-
default_executable:
|
13
|
+
date: 2012-11-05 00:00:00.000000000 Z
|
15
14
|
dependencies:
|
16
15
|
- !ruby/object:Gem::Dependency
|
17
16
|
name: bartt-ssl_requirement
|
18
|
-
requirement:
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
19
18
|
none: false
|
20
19
|
requirements:
|
21
20
|
- - ! '>='
|
@@ -23,10 +22,15 @@ dependencies:
|
|
23
22
|
version: '0'
|
24
23
|
type: :runtime
|
25
24
|
prerelease: false
|
26
|
-
version_requirements:
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
27
31
|
- !ruby/object:Gem::Dependency
|
28
32
|
name: will_paginate
|
29
|
-
requirement:
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
30
34
|
none: false
|
31
35
|
requirements:
|
32
36
|
- - ! '>='
|
@@ -34,10 +38,15 @@ dependencies:
|
|
34
38
|
version: '0'
|
35
39
|
type: :runtime
|
36
40
|
prerelease: false
|
37
|
-
version_requirements:
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
38
47
|
- !ruby/object:Gem::Dependency
|
39
48
|
name: haml
|
40
|
-
requirement:
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
41
50
|
none: false
|
42
51
|
requirements:
|
43
52
|
- - ! '>='
|
@@ -45,10 +54,15 @@ dependencies:
|
|
45
54
|
version: '0'
|
46
55
|
type: :runtime
|
47
56
|
prerelease: false
|
48
|
-
version_requirements:
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
49
63
|
- !ruby/object:Gem::Dependency
|
50
64
|
name: jquery-rails
|
51
|
-
requirement:
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
52
66
|
none: false
|
53
67
|
requirements:
|
54
68
|
- - ! '>='
|
@@ -56,10 +70,15 @@ dependencies:
|
|
56
70
|
version: '0'
|
57
71
|
type: :runtime
|
58
72
|
prerelease: false
|
59
|
-
version_requirements:
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
60
79
|
- !ruby/object:Gem::Dependency
|
61
80
|
name: dynamic_attributes
|
62
|
-
requirement:
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
63
82
|
none: false
|
64
83
|
requirements:
|
65
84
|
- - ! '>='
|
@@ -67,10 +86,15 @@ dependencies:
|
|
67
86
|
version: '0'
|
68
87
|
type: :runtime
|
69
88
|
prerelease: false
|
70
|
-
version_requirements:
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
71
95
|
- !ruby/object:Gem::Dependency
|
72
96
|
name: authlogic
|
73
|
-
requirement:
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
74
98
|
none: false
|
75
99
|
requirements:
|
76
100
|
- - ! '>='
|
@@ -78,10 +102,15 @@ dependencies:
|
|
78
102
|
version: '0'
|
79
103
|
type: :runtime
|
80
104
|
prerelease: false
|
81
|
-
version_requirements:
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
82
111
|
- !ruby/object:Gem::Dependency
|
83
112
|
name: activemerchant
|
84
|
-
requirement:
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
85
114
|
none: false
|
86
115
|
requirements:
|
87
116
|
- - ! '>='
|
@@ -89,10 +118,15 @@ dependencies:
|
|
89
118
|
version: '0'
|
90
119
|
type: :runtime
|
91
120
|
prerelease: false
|
92
|
-
version_requirements:
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
93
127
|
- !ruby/object:Gem::Dependency
|
94
128
|
name: simple_form
|
95
|
-
requirement:
|
129
|
+
requirement: !ruby/object:Gem::Requirement
|
96
130
|
none: false
|
97
131
|
requirements:
|
98
132
|
- - ! '>='
|
@@ -100,10 +134,15 @@ dependencies:
|
|
100
134
|
version: '0'
|
101
135
|
type: :runtime
|
102
136
|
prerelease: false
|
103
|
-
version_requirements:
|
137
|
+
version_requirements: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
104
143
|
- !ruby/object:Gem::Dependency
|
105
144
|
name: dynamic_form
|
106
|
-
requirement:
|
145
|
+
requirement: !ruby/object:Gem::Requirement
|
107
146
|
none: false
|
108
147
|
requirements:
|
109
148
|
- - ! '>='
|
@@ -111,10 +150,15 @@ dependencies:
|
|
111
150
|
version: '0'
|
112
151
|
type: :runtime
|
113
152
|
prerelease: false
|
114
|
-
version_requirements:
|
153
|
+
version_requirements: !ruby/object:Gem::Requirement
|
154
|
+
none: false
|
155
|
+
requirements:
|
156
|
+
- - ! '>='
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
115
159
|
- !ruby/object:Gem::Dependency
|
116
160
|
name: i18n
|
117
|
-
requirement:
|
161
|
+
requirement: !ruby/object:Gem::Requirement
|
118
162
|
none: false
|
119
163
|
requirements:
|
120
164
|
- - ! '>='
|
@@ -122,10 +166,15 @@ dependencies:
|
|
122
166
|
version: '0'
|
123
167
|
type: :runtime
|
124
168
|
prerelease: false
|
125
|
-
version_requirements:
|
169
|
+
version_requirements: !ruby/object:Gem::Requirement
|
170
|
+
none: false
|
171
|
+
requirements:
|
172
|
+
- - ! '>='
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
126
175
|
- !ruby/object:Gem::Dependency
|
127
176
|
name: activemerchant
|
128
|
-
requirement:
|
177
|
+
requirement: !ruby/object:Gem::Requirement
|
129
178
|
none: false
|
130
179
|
requirements:
|
131
180
|
- - ! '>='
|
@@ -133,10 +182,15 @@ dependencies:
|
|
133
182
|
version: 1.20.0
|
134
183
|
type: :runtime
|
135
184
|
prerelease: false
|
136
|
-
version_requirements:
|
185
|
+
version_requirements: !ruby/object:Gem::Requirement
|
186
|
+
none: false
|
187
|
+
requirements:
|
188
|
+
- - ! '>='
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: 1.20.0
|
137
191
|
- !ruby/object:Gem::Dependency
|
138
192
|
name: autotest-growl
|
139
|
-
requirement:
|
193
|
+
requirement: !ruby/object:Gem::Requirement
|
140
194
|
none: false
|
141
195
|
requirements:
|
142
196
|
- - ! '>='
|
@@ -144,10 +198,15 @@ dependencies:
|
|
144
198
|
version: '0'
|
145
199
|
type: :development
|
146
200
|
prerelease: false
|
147
|
-
version_requirements:
|
201
|
+
version_requirements: !ruby/object:Gem::Requirement
|
202
|
+
none: false
|
203
|
+
requirements:
|
204
|
+
- - ! '>='
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
version: '0'
|
148
207
|
- !ruby/object:Gem::Dependency
|
149
208
|
name: autotest-fsevent
|
150
|
-
requirement:
|
209
|
+
requirement: !ruby/object:Gem::Requirement
|
151
210
|
none: false
|
152
211
|
requirements:
|
153
212
|
- - ! '>='
|
@@ -155,10 +214,15 @@ dependencies:
|
|
155
214
|
version: '0'
|
156
215
|
type: :development
|
157
216
|
prerelease: false
|
158
|
-
version_requirements:
|
217
|
+
version_requirements: !ruby/object:Gem::Requirement
|
218
|
+
none: false
|
219
|
+
requirements:
|
220
|
+
- - ! '>='
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0'
|
159
223
|
- !ruby/object:Gem::Dependency
|
160
224
|
name: autotest-rails
|
161
|
-
requirement:
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
162
226
|
none: false
|
163
227
|
requirements:
|
164
228
|
- - ! '>='
|
@@ -166,10 +230,15 @@ dependencies:
|
|
166
230
|
version: '0'
|
167
231
|
type: :development
|
168
232
|
prerelease: false
|
169
|
-
version_requirements:
|
233
|
+
version_requirements: !ruby/object:Gem::Requirement
|
234
|
+
none: false
|
235
|
+
requirements:
|
236
|
+
- - ! '>='
|
237
|
+
- !ruby/object:Gem::Version
|
238
|
+
version: '0'
|
170
239
|
- !ruby/object:Gem::Dependency
|
171
240
|
name: factory_girl_rails
|
172
|
-
requirement:
|
241
|
+
requirement: !ruby/object:Gem::Requirement
|
173
242
|
none: false
|
174
243
|
requirements:
|
175
244
|
- - ! '>='
|
@@ -177,10 +246,15 @@ dependencies:
|
|
177
246
|
version: 1.0.1
|
178
247
|
type: :development
|
179
248
|
prerelease: false
|
180
|
-
version_requirements:
|
249
|
+
version_requirements: !ruby/object:Gem::Requirement
|
250
|
+
none: false
|
251
|
+
requirements:
|
252
|
+
- - ! '>='
|
253
|
+
- !ruby/object:Gem::Version
|
254
|
+
version: 1.0.1
|
181
255
|
- !ruby/object:Gem::Dependency
|
182
256
|
name: rspec-rails
|
183
|
-
requirement:
|
257
|
+
requirement: !ruby/object:Gem::Requirement
|
184
258
|
none: false
|
185
259
|
requirements:
|
186
260
|
- - ! '>='
|
@@ -188,10 +262,15 @@ dependencies:
|
|
188
262
|
version: '0'
|
189
263
|
type: :development
|
190
264
|
prerelease: false
|
191
|
-
version_requirements:
|
265
|
+
version_requirements: !ruby/object:Gem::Requirement
|
266
|
+
none: false
|
267
|
+
requirements:
|
268
|
+
- - ! '>='
|
269
|
+
- !ruby/object:Gem::Version
|
270
|
+
version: '0'
|
192
271
|
- !ruby/object:Gem::Dependency
|
193
272
|
name: database_cleaner
|
194
|
-
requirement:
|
273
|
+
requirement: !ruby/object:Gem::Requirement
|
195
274
|
none: false
|
196
275
|
requirements:
|
197
276
|
- - ! '>='
|
@@ -199,10 +278,15 @@ dependencies:
|
|
199
278
|
version: '0'
|
200
279
|
type: :development
|
201
280
|
prerelease: false
|
202
|
-
version_requirements:
|
281
|
+
version_requirements: !ruby/object:Gem::Requirement
|
282
|
+
none: false
|
283
|
+
requirements:
|
284
|
+
- - ! '>='
|
285
|
+
- !ruby/object:Gem::Version
|
286
|
+
version: '0'
|
203
287
|
- !ruby/object:Gem::Dependency
|
204
288
|
name: spork
|
205
|
-
requirement:
|
289
|
+
requirement: !ruby/object:Gem::Requirement
|
206
290
|
none: false
|
207
291
|
requirements:
|
208
292
|
- - ! '>='
|
@@ -210,10 +294,15 @@ dependencies:
|
|
210
294
|
version: '0'
|
211
295
|
type: :development
|
212
296
|
prerelease: false
|
213
|
-
version_requirements:
|
297
|
+
version_requirements: !ruby/object:Gem::Requirement
|
298
|
+
none: false
|
299
|
+
requirements:
|
300
|
+
- - ! '>='
|
301
|
+
- !ruby/object:Gem::Version
|
302
|
+
version: '0'
|
214
303
|
- !ruby/object:Gem::Dependency
|
215
304
|
name: launchy
|
216
|
-
requirement:
|
305
|
+
requirement: !ruby/object:Gem::Requirement
|
217
306
|
none: false
|
218
307
|
requirements:
|
219
308
|
- - ! '>='
|
@@ -221,10 +310,15 @@ dependencies:
|
|
221
310
|
version: '0'
|
222
311
|
type: :development
|
223
312
|
prerelease: false
|
224
|
-
version_requirements:
|
313
|
+
version_requirements: !ruby/object:Gem::Requirement
|
314
|
+
none: false
|
315
|
+
requirements:
|
316
|
+
- - ! '>='
|
317
|
+
- !ruby/object:Gem::Version
|
318
|
+
version: '0'
|
225
319
|
- !ruby/object:Gem::Dependency
|
226
320
|
name: shoulda
|
227
|
-
requirement:
|
321
|
+
requirement: !ruby/object:Gem::Requirement
|
228
322
|
none: false
|
229
323
|
requirements:
|
230
324
|
- - ! '>='
|
@@ -232,10 +326,15 @@ dependencies:
|
|
232
326
|
version: '0'
|
233
327
|
type: :development
|
234
328
|
prerelease: false
|
235
|
-
version_requirements:
|
329
|
+
version_requirements: !ruby/object:Gem::Requirement
|
330
|
+
none: false
|
331
|
+
requirements:
|
332
|
+
- - ! '>='
|
333
|
+
- !ruby/object:Gem::Version
|
334
|
+
version: '0'
|
236
335
|
- !ruby/object:Gem::Dependency
|
237
336
|
name: ZenTest
|
238
|
-
requirement:
|
337
|
+
requirement: !ruby/object:Gem::Requirement
|
239
338
|
none: false
|
240
339
|
requirements:
|
241
340
|
- - ! '>='
|
@@ -243,10 +342,15 @@ dependencies:
|
|
243
342
|
version: '0'
|
244
343
|
type: :development
|
245
344
|
prerelease: false
|
246
|
-
version_requirements:
|
345
|
+
version_requirements: !ruby/object:Gem::Requirement
|
346
|
+
none: false
|
347
|
+
requirements:
|
348
|
+
- - ! '>='
|
349
|
+
- !ruby/object:Gem::Version
|
350
|
+
version: '0'
|
247
351
|
- !ruby/object:Gem::Dependency
|
248
352
|
name: email_spec
|
249
|
-
requirement:
|
353
|
+
requirement: !ruby/object:Gem::Requirement
|
250
354
|
none: false
|
251
355
|
requirements:
|
252
356
|
- - ! '>='
|
@@ -254,7 +358,12 @@ dependencies:
|
|
254
358
|
version: '0'
|
255
359
|
type: :development
|
256
360
|
prerelease: false
|
257
|
-
version_requirements:
|
361
|
+
version_requirements: !ruby/object:Gem::Requirement
|
362
|
+
none: false
|
363
|
+
requirements:
|
364
|
+
- - ! '>='
|
365
|
+
- !ruby/object:Gem::Version
|
366
|
+
version: '0'
|
258
367
|
description: Simple SAAS through Authorize.net
|
259
368
|
email:
|
260
369
|
- jonohrt1@gmail.com
|
@@ -264,6 +373,7 @@ extra_rdoc_files: []
|
|
264
373
|
files:
|
265
374
|
- .gitignore
|
266
375
|
- .rspec
|
376
|
+
- .rvmrc
|
267
377
|
- Gemfile
|
268
378
|
- MIT-LICENSE
|
269
379
|
- README.rdoc
|
@@ -386,7 +496,7 @@ files:
|
|
386
496
|
- spec/dummy/public/javascripts/application.js
|
387
497
|
- spec/dummy/public/javascripts/jquery.js
|
388
498
|
- spec/dummy/public/javascripts/jquery.min.js
|
389
|
-
- spec/dummy/public/javascripts/
|
499
|
+
- spec/dummy/public/javascripts/jquery_ujs.js
|
390
500
|
- spec/dummy/public/stylesheets/.gitkeep
|
391
501
|
- spec/dummy/script/rails
|
392
502
|
- spec/dummy/vendor/plugins/active_merchant_testing/MIT-LICENSE
|
@@ -424,7 +534,6 @@ files:
|
|
424
534
|
- spec/requests/subscriptions_spec.rb
|
425
535
|
- spec/spec_helper.rb
|
426
536
|
- spec/spec_helpers/spec_helpers.rb
|
427
|
-
has_rdoc: true
|
428
537
|
homepage: ''
|
429
538
|
licenses: []
|
430
539
|
post_install_message:
|
@@ -445,7 +554,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
445
554
|
version: '0'
|
446
555
|
requirements: []
|
447
556
|
rubyforge_project: saasaparilla
|
448
|
-
rubygems_version: 1.
|
557
|
+
rubygems_version: 1.8.24
|
449
558
|
signing_key:
|
450
559
|
specification_version: 3
|
451
560
|
summary: Simple SAAS through Authorize.net
|
@@ -483,7 +592,7 @@ test_files:
|
|
483
592
|
- spec/dummy/public/javascripts/application.js
|
484
593
|
- spec/dummy/public/javascripts/jquery.js
|
485
594
|
- spec/dummy/public/javascripts/jquery.min.js
|
486
|
-
- spec/dummy/public/javascripts/
|
595
|
+
- spec/dummy/public/javascripts/jquery_ujs.js
|
487
596
|
- spec/dummy/public/stylesheets/.gitkeep
|
488
597
|
- spec/dummy/script/rails
|
489
598
|
- spec/dummy/vendor/plugins/active_merchant_testing/MIT-LICENSE
|
@@ -1,159 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Unobtrusive scripting adapter for jQuery
|
3
|
-
*
|
4
|
-
* Requires jQuery 1.4.3 or later.
|
5
|
-
* https://github.com/rails/jquery-ujs
|
6
|
-
*/
|
7
|
-
|
8
|
-
(function($) {
|
9
|
-
// Make sure that every Ajax request sends the CSRF token
|
10
|
-
function CSRFProtection(xhr) {
|
11
|
-
var token = $('meta[name="csrf-token"]').attr('content');
|
12
|
-
if (token) xhr.setRequestHeader('X-CSRF-Token', token);
|
13
|
-
}
|
14
|
-
if ('ajaxPrefilter' in $) $.ajaxPrefilter(function(options, originalOptions, xhr){ CSRFProtection(xhr) });
|
15
|
-
else $(document).ajaxSend(function(e, xhr){ CSRFProtection(xhr) });
|
16
|
-
|
17
|
-
// Triggers an event on an element and returns the event result
|
18
|
-
function fire(obj, name, data) {
|
19
|
-
var event = $.Event(name);
|
20
|
-
obj.trigger(event, data);
|
21
|
-
return event.result !== false;
|
22
|
-
}
|
23
|
-
|
24
|
-
// Submits "remote" forms and links with ajax
|
25
|
-
function handleRemote(element) {
|
26
|
-
var method, url, data,
|
27
|
-
dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType);
|
28
|
-
|
29
|
-
if (fire(element, 'ajax:before')) {
|
30
|
-
if (element.is('form')) {
|
31
|
-
method = element.attr('method');
|
32
|
-
url = element.attr('action');
|
33
|
-
data = element.serializeArray();
|
34
|
-
// memoized value from clicked submit button
|
35
|
-
var button = element.data('ujs:submit-button');
|
36
|
-
if (button) {
|
37
|
-
data.push(button);
|
38
|
-
element.data('ujs:submit-button', null);
|
39
|
-
}
|
40
|
-
} else {
|
41
|
-
method = element.data('method');
|
42
|
-
url = element.attr('href');
|
43
|
-
data = null;
|
44
|
-
}
|
45
|
-
$.ajax({
|
46
|
-
url: url, type: method || 'GET', data: data, dataType: dataType,
|
47
|
-
// stopping the "ajax:beforeSend" event will cancel the ajax request
|
48
|
-
beforeSend: function(xhr, settings) {
|
49
|
-
if (settings.dataType === undefined) {
|
50
|
-
xhr.setRequestHeader('accept', '*/*;q=0.5, ' + settings.accepts.script);
|
51
|
-
}
|
52
|
-
return fire(element, 'ajax:beforeSend', [xhr, settings]);
|
53
|
-
},
|
54
|
-
success: function(data, status, xhr) {
|
55
|
-
element.trigger('ajax:success', [data, status, xhr]);
|
56
|
-
},
|
57
|
-
complete: function(xhr, status) {
|
58
|
-
element.trigger('ajax:complete', [xhr, status]);
|
59
|
-
},
|
60
|
-
error: function(xhr, status, error) {
|
61
|
-
element.trigger('ajax:error', [xhr, status, error]);
|
62
|
-
}
|
63
|
-
});
|
64
|
-
}
|
65
|
-
}
|
66
|
-
|
67
|
-
// Handles "data-method" on links such as:
|
68
|
-
// <a href="/users/5" data-method="delete" rel="nofollow" data-confirm="Are you sure?">Delete</a>
|
69
|
-
function handleMethod(link) {
|
70
|
-
var href = link.attr('href'),
|
71
|
-
method = link.data('method'),
|
72
|
-
csrf_token = $('meta[name=csrf-token]').attr('content'),
|
73
|
-
csrf_param = $('meta[name=csrf-param]').attr('content'),
|
74
|
-
form = $('<form method="post" action="' + href + '"></form>'),
|
75
|
-
metadata_input = '<input name="_method" value="' + method + '" type="hidden" />';
|
76
|
-
|
77
|
-
if (csrf_param !== undefined && csrf_token !== undefined) {
|
78
|
-
metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />';
|
79
|
-
}
|
80
|
-
|
81
|
-
form.hide().append(metadata_input).appendTo('body');
|
82
|
-
form.submit();
|
83
|
-
}
|
84
|
-
|
85
|
-
function disableFormElements(form) {
|
86
|
-
form.find('input[data-disable-with], button[data-disable-with]').each(function() {
|
87
|
-
var element = $(this), method = element.is('button') ? 'html' : 'val';
|
88
|
-
element.data('ujs:enable-with', element[method]());
|
89
|
-
element[method](element.data('disable-with'));
|
90
|
-
element.attr('disabled', 'disabled');
|
91
|
-
});
|
92
|
-
}
|
93
|
-
|
94
|
-
function enableFormElements(form) {
|
95
|
-
form.find('input[data-disable-with]:disabled, button[data-disable-with]:disabled').each(function() {
|
96
|
-
var element = $(this), method = element.is('button') ? 'html' : 'val';
|
97
|
-
if (element.data('ujs:enable-with')) element[method](element.data('ujs:enable-with'));
|
98
|
-
element.removeAttr('disabled');
|
99
|
-
});
|
100
|
-
}
|
101
|
-
|
102
|
-
function allowAction(element) {
|
103
|
-
var message = element.data('confirm');
|
104
|
-
return !message || (fire(element, 'confirm') && confirm(message));
|
105
|
-
}
|
106
|
-
|
107
|
-
function requiredValuesMissing(form) {
|
108
|
-
var missing = false;
|
109
|
-
form.find('input[name][required]').each(function() {
|
110
|
-
if (!$(this).val()) missing = true;
|
111
|
-
});
|
112
|
-
return missing;
|
113
|
-
}
|
114
|
-
|
115
|
-
$('a[data-confirm], a[data-method], a[data-remote]').live('click.rails', function(e) {
|
116
|
-
var link = $(this);
|
117
|
-
if (!allowAction(link)) return false;
|
118
|
-
|
119
|
-
if (link.data('remote') != undefined) {
|
120
|
-
handleRemote(link);
|
121
|
-
return false;
|
122
|
-
} else if (link.data('method')) {
|
123
|
-
handleMethod(link);
|
124
|
-
return false;
|
125
|
-
}
|
126
|
-
});
|
127
|
-
|
128
|
-
$('form').live('submit.rails', function(e) {
|
129
|
-
var form = $(this), remote = form.data('remote') != undefined;
|
130
|
-
if (!allowAction(form)) return false;
|
131
|
-
|
132
|
-
// skip other logic when required values are missing
|
133
|
-
if (requiredValuesMissing(form)) return !remote;
|
134
|
-
|
135
|
-
if (remote) {
|
136
|
-
handleRemote(form);
|
137
|
-
return false;
|
138
|
-
} else {
|
139
|
-
// slight timeout so that the submit button gets properly serialized
|
140
|
-
setTimeout(function(){ disableFormElements(form) }, 13);
|
141
|
-
}
|
142
|
-
});
|
143
|
-
|
144
|
-
$('form input[type=submit], form input[type=image], form button[type=submit], form button:not([type])').live('click.rails', function() {
|
145
|
-
var button = $(this);
|
146
|
-
if (!allowAction(button)) return false;
|
147
|
-
// register the pressed submit button
|
148
|
-
var name = button.attr('name'), data = name ? {name:name, value:button.val()} : null;
|
149
|
-
button.closest('form').data('ujs:submit-button', data);
|
150
|
-
});
|
151
|
-
|
152
|
-
$('form').live('ajax:beforeSend.rails', function(event) {
|
153
|
-
if (this == event.target) disableFormElements($(this));
|
154
|
-
});
|
155
|
-
|
156
|
-
$('form').live('ajax:complete.rails', function(event) {
|
157
|
-
if (this == event.target) enableFormElements($(this));
|
158
|
-
});
|
159
|
-
})( jQuery );
|