good_job 2.4.2 → 2.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +79 -0
  3. data/README.md +12 -4
  4. data/engine/app/assets/scripts.js +1 -0
  5. data/engine/app/assets/style.css +5 -0
  6. data/engine/app/assets/vendor/chartjs/chart.min.js +13 -0
  7. data/engine/app/assets/vendor/rails_ujs.js +747 -0
  8. data/engine/app/charts/good_job/scheduled_by_queue_chart.rb +69 -0
  9. data/engine/app/controllers/good_job/assets_controller.rb +8 -4
  10. data/engine/app/controllers/good_job/cron_entries_controller.rb +19 -0
  11. data/engine/app/controllers/good_job/jobs_controller.rb +36 -0
  12. data/engine/app/filters/good_job/base_filter.rb +18 -56
  13. data/engine/app/filters/good_job/executions_filter.rb +9 -8
  14. data/engine/app/filters/good_job/jobs_filter.rb +12 -9
  15. data/engine/app/views/good_job/cron_entries/index.html.erb +51 -0
  16. data/engine/app/views/good_job/cron_entries/show.html.erb +4 -0
  17. data/engine/app/views/good_job/{shared/_executions_table.erb → executions/_table.erb} +1 -1
  18. data/engine/app/views/good_job/executions/index.html.erb +2 -2
  19. data/engine/app/views/good_job/{shared/_jobs_table.erb → jobs/_table.erb} +18 -6
  20. data/engine/app/views/good_job/jobs/index.html.erb +15 -2
  21. data/engine/app/views/good_job/jobs/show.html.erb +2 -2
  22. data/engine/app/views/good_job/shared/_chart.erb +19 -46
  23. data/engine/app/views/good_job/shared/_filter.erb +27 -13
  24. data/engine/app/views/good_job/shared/icons/_arrow_clockwise.html.erb +5 -0
  25. data/engine/app/views/good_job/shared/icons/_play.html.erb +4 -0
  26. data/engine/app/views/good_job/shared/icons/_skip_forward.html.erb +4 -0
  27. data/engine/app/views/good_job/shared/icons/_stop.html.erb +4 -0
  28. data/engine/app/views/layouts/good_job/base.html.erb +6 -4
  29. data/engine/config/routes.rb +17 -4
  30. data/lib/generators/good_job/templates/install/migrations/create_good_jobs.rb.erb +2 -0
  31. data/lib/generators/good_job/templates/update/migrations/02_add_cron_at_to_good_jobs.rb.erb +14 -0
  32. data/lib/generators/good_job/templates/update/migrations/03_add_cron_key_cron_at_index_to_good_jobs.rb.erb +20 -0
  33. data/lib/good_job/active_job_job.rb +228 -0
  34. data/lib/good_job/configuration.rb +1 -1
  35. data/lib/good_job/cron_entry.rb +78 -5
  36. data/lib/good_job/cron_manager.rb +4 -6
  37. data/lib/good_job/current_thread.rb +38 -5
  38. data/lib/good_job/execution.rb +53 -39
  39. data/lib/good_job/filterable.rb +42 -0
  40. data/lib/good_job/notifier.rb +17 -7
  41. data/lib/good_job/version.rb +1 -1
  42. metadata +31 -21
  43. data/engine/app/assets/vendor/chartist/chartist.css +0 -613
  44. data/engine/app/assets/vendor/chartist/chartist.js +0 -4516
  45. data/engine/app/controllers/good_job/cron_schedules_controller.rb +0 -9
  46. data/engine/app/models/good_job/active_job_job.rb +0 -127
  47. data/engine/app/views/good_job/cron_schedules/index.html.erb +0 -72
@@ -0,0 +1,747 @@
1
+ /*
2
+ Unobtrusive JavaScript v6.1.4-1
3
+ https://www.npmjs.com/package/@rails/ujs
4
+ https://github.com/rails/rails/blob/main/actionview/app/assets/javascripts
5
+ Released under the MIT license
6
+ */;
7
+
8
+ (function() {
9
+ var context = this;
10
+
11
+ (function() {
12
+ (function() {
13
+ this.Rails = {
14
+ linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote]:not([disabled]), a[data-disable-with], a[data-disable]',
15
+ buttonClickSelector: {
16
+ selector: 'button[data-remote]:not([form]), button[data-confirm]:not([form])',
17
+ exclude: 'form button'
18
+ },
19
+ inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]',
20
+ formSubmitSelector: 'form:not([data-turbo=true])',
21
+ formInputClickSelector: 'form:not([data-turbo=true]) input[type=submit], form:not([data-turbo=true]) input[type=image], form:not([data-turbo=true]) button[type=submit], form:not([data-turbo=true]) button:not([type]), input[type=submit][form], input[type=image][form], button[type=submit][form], button[form]:not([type])',
22
+ formDisableSelector: 'input[data-disable-with]:enabled, button[data-disable-with]:enabled, textarea[data-disable-with]:enabled, input[data-disable]:enabled, button[data-disable]:enabled, textarea[data-disable]:enabled',
23
+ formEnableSelector: 'input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled, input[data-disable]:disabled, button[data-disable]:disabled, textarea[data-disable]:disabled',
24
+ fileInputSelector: 'input[name][type=file]:not([disabled])',
25
+ linkDisableSelector: 'a[data-disable-with], a[data-disable]',
26
+ buttonDisableSelector: 'button[data-remote][data-disable-with], button[data-remote][data-disable]'
27
+ };
28
+
29
+ }).call(this);
30
+ }).call(context);
31
+
32
+ var Rails = context.Rails;
33
+
34
+ (function() {
35
+ (function() {
36
+ var nonce;
37
+
38
+ nonce = null;
39
+
40
+ Rails.loadCSPNonce = function() {
41
+ var ref;
42
+ return nonce = (ref = document.querySelector("meta[name=csp-nonce]")) != null ? ref.content : void 0;
43
+ };
44
+
45
+ Rails.cspNonce = function() {
46
+ return nonce != null ? nonce : Rails.loadCSPNonce();
47
+ };
48
+
49
+ }).call(this);
50
+ (function() {
51
+ var expando, m;
52
+
53
+ m = Element.prototype.matches || Element.prototype.matchesSelector || Element.prototype.mozMatchesSelector || Element.prototype.msMatchesSelector || Element.prototype.oMatchesSelector || Element.prototype.webkitMatchesSelector;
54
+
55
+ Rails.matches = function(element, selector) {
56
+ if (selector.exclude != null) {
57
+ return m.call(element, selector.selector) && !m.call(element, selector.exclude);
58
+ } else {
59
+ return m.call(element, selector);
60
+ }
61
+ };
62
+
63
+ expando = '_ujsData';
64
+
65
+ Rails.getData = function(element, key) {
66
+ var ref;
67
+ return (ref = element[expando]) != null ? ref[key] : void 0;
68
+ };
69
+
70
+ Rails.setData = function(element, key, value) {
71
+ if (element[expando] == null) {
72
+ element[expando] = {};
73
+ }
74
+ return element[expando][key] = value;
75
+ };
76
+
77
+ Rails.$ = function(selector) {
78
+ return Array.prototype.slice.call(document.querySelectorAll(selector));
79
+ };
80
+
81
+ }).call(this);
82
+ (function() {
83
+ var $, csrfParam, csrfToken;
84
+
85
+ $ = Rails.$;
86
+
87
+ csrfToken = Rails.csrfToken = function() {
88
+ var meta;
89
+ meta = document.querySelector('meta[name=csrf-token]');
90
+ return meta && meta.content;
91
+ };
92
+
93
+ csrfParam = Rails.csrfParam = function() {
94
+ var meta;
95
+ meta = document.querySelector('meta[name=csrf-param]');
96
+ return meta && meta.content;
97
+ };
98
+
99
+ Rails.CSRFProtection = function(xhr) {
100
+ var token;
101
+ token = csrfToken();
102
+ if (token != null) {
103
+ return xhr.setRequestHeader('X-CSRF-Token', token);
104
+ }
105
+ };
106
+
107
+ Rails.refreshCSRFTokens = function() {
108
+ var param, token;
109
+ token = csrfToken();
110
+ param = csrfParam();
111
+ if ((token != null) && (param != null)) {
112
+ return $('form input[name="' + param + '"]').forEach(function(input) {
113
+ return input.value = token;
114
+ });
115
+ }
116
+ };
117
+
118
+ }).call(this);
119
+ (function() {
120
+ var CustomEvent, fire, matches, preventDefault;
121
+
122
+ matches = Rails.matches;
123
+
124
+ CustomEvent = window.CustomEvent;
125
+
126
+ if (typeof CustomEvent !== 'function') {
127
+ CustomEvent = function(event, params) {
128
+ var evt;
129
+ evt = document.createEvent('CustomEvent');
130
+ evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
131
+ return evt;
132
+ };
133
+ CustomEvent.prototype = window.Event.prototype;
134
+ preventDefault = CustomEvent.prototype.preventDefault;
135
+ CustomEvent.prototype.preventDefault = function() {
136
+ var result;
137
+ result = preventDefault.call(this);
138
+ if (this.cancelable && !this.defaultPrevented) {
139
+ Object.defineProperty(this, 'defaultPrevented', {
140
+ get: function() {
141
+ return true;
142
+ }
143
+ });
144
+ }
145
+ return result;
146
+ };
147
+ }
148
+
149
+ fire = Rails.fire = function(obj, name, data) {
150
+ var event;
151
+ event = new CustomEvent(name, {
152
+ bubbles: true,
153
+ cancelable: true,
154
+ detail: data
155
+ });
156
+ obj.dispatchEvent(event);
157
+ return !event.defaultPrevented;
158
+ };
159
+
160
+ Rails.stopEverything = function(e) {
161
+ fire(e.target, 'ujs:everythingStopped');
162
+ e.preventDefault();
163
+ e.stopPropagation();
164
+ return e.stopImmediatePropagation();
165
+ };
166
+
167
+ Rails.delegate = function(element, selector, eventType, handler) {
168
+ return element.addEventListener(eventType, function(e) {
169
+ var target;
170
+ target = e.target;
171
+ while (!(!(target instanceof Element) || matches(target, selector))) {
172
+ target = target.parentNode;
173
+ }
174
+ if (target instanceof Element && handler.call(target, e) === false) {
175
+ e.preventDefault();
176
+ return e.stopPropagation();
177
+ }
178
+ });
179
+ };
180
+
181
+ }).call(this);
182
+ (function() {
183
+ var AcceptHeaders, CSRFProtection, createXHR, cspNonce, fire, prepareOptions, processResponse;
184
+
185
+ cspNonce = Rails.cspNonce, CSRFProtection = Rails.CSRFProtection, fire = Rails.fire;
186
+
187
+ AcceptHeaders = {
188
+ '*': '*/*',
189
+ text: 'text/plain',
190
+ html: 'text/html',
191
+ xml: 'application/xml, text/xml',
192
+ json: 'application/json, text/javascript',
193
+ script: 'text/javascript, application/javascript, application/ecmascript, application/x-ecmascript'
194
+ };
195
+
196
+ Rails.ajax = function(options) {
197
+ var xhr;
198
+ options = prepareOptions(options);
199
+ xhr = createXHR(options, function() {
200
+ var ref, response;
201
+ response = processResponse((ref = xhr.response) != null ? ref : xhr.responseText, xhr.getResponseHeader('Content-Type'));
202
+ if (Math.floor(xhr.status / 100) === 2) {
203
+ if (typeof options.success === "function") {
204
+ options.success(response, xhr.statusText, xhr);
205
+ }
206
+ } else {
207
+ if (typeof options.error === "function") {
208
+ options.error(response, xhr.statusText, xhr);
209
+ }
210
+ }
211
+ return typeof options.complete === "function" ? options.complete(xhr, xhr.statusText) : void 0;
212
+ });
213
+ if ((options.beforeSend != null) && !options.beforeSend(xhr, options)) {
214
+ return false;
215
+ }
216
+ if (xhr.readyState === XMLHttpRequest.OPENED) {
217
+ return xhr.send(options.data);
218
+ }
219
+ };
220
+
221
+ prepareOptions = function(options) {
222
+ options.url = options.url || location.href;
223
+ options.type = options.type.toUpperCase();
224
+ if (options.type === 'GET' && options.data) {
225
+ if (options.url.indexOf('?') < 0) {
226
+ options.url += '?' + options.data;
227
+ } else {
228
+ options.url += '&' + options.data;
229
+ }
230
+ }
231
+ if (AcceptHeaders[options.dataType] == null) {
232
+ options.dataType = '*';
233
+ }
234
+ options.accept = AcceptHeaders[options.dataType];
235
+ if (options.dataType !== '*') {
236
+ options.accept += ', */*; q=0.01';
237
+ }
238
+ return options;
239
+ };
240
+
241
+ createXHR = function(options, done) {
242
+ var xhr;
243
+ xhr = new XMLHttpRequest();
244
+ xhr.open(options.type, options.url, true);
245
+ xhr.setRequestHeader('Accept', options.accept);
246
+ if (typeof options.data === 'string') {
247
+ xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
248
+ }
249
+ if (!options.crossDomain) {
250
+ xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
251
+ CSRFProtection(xhr);
252
+ }
253
+ xhr.withCredentials = !!options.withCredentials;
254
+ xhr.onreadystatechange = function() {
255
+ if (xhr.readyState === XMLHttpRequest.DONE) {
256
+ return done(xhr);
257
+ }
258
+ };
259
+ return xhr;
260
+ };
261
+
262
+ processResponse = function(response, type) {
263
+ var parser, script;
264
+ if (typeof response === 'string' && typeof type === 'string') {
265
+ if (type.match(/\bjson\b/)) {
266
+ try {
267
+ response = JSON.parse(response);
268
+ } catch (error) {}
269
+ } else if (type.match(/\b(?:java|ecma)script\b/)) {
270
+ script = document.createElement('script');
271
+ script.setAttribute('nonce', cspNonce());
272
+ script.text = response;
273
+ document.head.appendChild(script).parentNode.removeChild(script);
274
+ } else if (type.match(/\b(xml|html|svg)\b/)) {
275
+ parser = new DOMParser();
276
+ type = type.replace(/;.+/, '');
277
+ try {
278
+ response = parser.parseFromString(response, type);
279
+ } catch (error) {}
280
+ }
281
+ }
282
+ return response;
283
+ };
284
+
285
+ Rails.href = function(element) {
286
+ return element.href;
287
+ };
288
+
289
+ Rails.isCrossDomain = function(url) {
290
+ var e, originAnchor, urlAnchor;
291
+ originAnchor = document.createElement('a');
292
+ originAnchor.href = location.href;
293
+ urlAnchor = document.createElement('a');
294
+ try {
295
+ urlAnchor.href = url;
296
+ return !(((!urlAnchor.protocol || urlAnchor.protocol === ':') && !urlAnchor.host) || (originAnchor.protocol + '//' + originAnchor.host === urlAnchor.protocol + '//' + urlAnchor.host));
297
+ } catch (error) {
298
+ e = error;
299
+ return true;
300
+ }
301
+ };
302
+
303
+ }).call(this);
304
+ (function() {
305
+ var matches, toArray;
306
+
307
+ matches = Rails.matches;
308
+
309
+ toArray = function(e) {
310
+ return Array.prototype.slice.call(e);
311
+ };
312
+
313
+ Rails.serializeElement = function(element, additionalParam) {
314
+ var inputs, params;
315
+ inputs = [element];
316
+ if (matches(element, 'form')) {
317
+ inputs = toArray(element.elements);
318
+ }
319
+ params = [];
320
+ inputs.forEach(function(input) {
321
+ if (!input.name || input.disabled) {
322
+ return;
323
+ }
324
+ if (matches(input, 'fieldset[disabled] *')) {
325
+ return;
326
+ }
327
+ if (matches(input, 'select')) {
328
+ return toArray(input.options).forEach(function(option) {
329
+ if (option.selected) {
330
+ return params.push({
331
+ name: input.name,
332
+ value: option.value
333
+ });
334
+ }
335
+ });
336
+ } else if (input.checked || ['radio', 'checkbox', 'submit'].indexOf(input.type) === -1) {
337
+ return params.push({
338
+ name: input.name,
339
+ value: input.value
340
+ });
341
+ }
342
+ });
343
+ if (additionalParam) {
344
+ params.push(additionalParam);
345
+ }
346
+ return params.map(function(param) {
347
+ if (param.name != null) {
348
+ return (encodeURIComponent(param.name)) + "=" + (encodeURIComponent(param.value));
349
+ } else {
350
+ return param;
351
+ }
352
+ }).join('&');
353
+ };
354
+
355
+ Rails.formElements = function(form, selector) {
356
+ if (matches(form, 'form')) {
357
+ return toArray(form.elements).filter(function(el) {
358
+ return matches(el, selector);
359
+ });
360
+ } else {
361
+ return toArray(form.querySelectorAll(selector));
362
+ }
363
+ };
364
+
365
+ }).call(this);
366
+ (function() {
367
+ var allowAction, fire, stopEverything;
368
+
369
+ fire = Rails.fire, stopEverything = Rails.stopEverything;
370
+
371
+ Rails.handleConfirm = function(e) {
372
+ if (!allowAction(this)) {
373
+ return stopEverything(e);
374
+ }
375
+ };
376
+
377
+ Rails.confirm = function(message, element) {
378
+ return confirm(message);
379
+ };
380
+
381
+ allowAction = function(element) {
382
+ var answer, callback, message;
383
+ message = element.getAttribute('data-confirm');
384
+ if (!message) {
385
+ return true;
386
+ }
387
+ answer = false;
388
+ if (fire(element, 'confirm')) {
389
+ try {
390
+ answer = Rails.confirm(message, element);
391
+ } catch (error) {}
392
+ callback = fire(element, 'confirm:complete', [answer]);
393
+ }
394
+ return answer && callback;
395
+ };
396
+
397
+ }).call(this);
398
+ (function() {
399
+ var disableFormElement, disableFormElements, disableLinkElement, enableFormElement, enableFormElements, enableLinkElement, formElements, getData, isXhrRedirect, matches, setData, stopEverything;
400
+
401
+ matches = Rails.matches, getData = Rails.getData, setData = Rails.setData, stopEverything = Rails.stopEverything, formElements = Rails.formElements;
402
+
403
+ Rails.handleDisabledElement = function(e) {
404
+ var element;
405
+ element = this;
406
+ if (element.disabled) {
407
+ return stopEverything(e);
408
+ }
409
+ };
410
+
411
+ Rails.enableElement = function(e) {
412
+ var element;
413
+ if (e instanceof Event) {
414
+ if (isXhrRedirect(e)) {
415
+ return;
416
+ }
417
+ element = e.target;
418
+ } else {
419
+ element = e;
420
+ }
421
+ if (matches(element, Rails.linkDisableSelector)) {
422
+ return enableLinkElement(element);
423
+ } else if (matches(element, Rails.buttonDisableSelector) || matches(element, Rails.formEnableSelector)) {
424
+ return enableFormElement(element);
425
+ } else if (matches(element, Rails.formSubmitSelector)) {
426
+ return enableFormElements(element);
427
+ }
428
+ };
429
+
430
+ Rails.disableElement = function(e) {
431
+ var element;
432
+ element = e instanceof Event ? e.target : e;
433
+ if (matches(element, Rails.linkDisableSelector)) {
434
+ return disableLinkElement(element);
435
+ } else if (matches(element, Rails.buttonDisableSelector) || matches(element, Rails.formDisableSelector)) {
436
+ return disableFormElement(element);
437
+ } else if (matches(element, Rails.formSubmitSelector)) {
438
+ return disableFormElements(element);
439
+ }
440
+ };
441
+
442
+ disableLinkElement = function(element) {
443
+ var replacement;
444
+ if (getData(element, 'ujs:disabled')) {
445
+ return;
446
+ }
447
+ replacement = element.getAttribute('data-disable-with');
448
+ if (replacement != null) {
449
+ setData(element, 'ujs:enable-with', element.innerHTML);
450
+ element.innerHTML = replacement;
451
+ }
452
+ element.addEventListener('click', stopEverything);
453
+ return setData(element, 'ujs:disabled', true);
454
+ };
455
+
456
+ enableLinkElement = function(element) {
457
+ var originalText;
458
+ originalText = getData(element, 'ujs:enable-with');
459
+ if (originalText != null) {
460
+ element.innerHTML = originalText;
461
+ setData(element, 'ujs:enable-with', null);
462
+ }
463
+ element.removeEventListener('click', stopEverything);
464
+ return setData(element, 'ujs:disabled', null);
465
+ };
466
+
467
+ disableFormElements = function(form) {
468
+ return formElements(form, Rails.formDisableSelector).forEach(disableFormElement);
469
+ };
470
+
471
+ disableFormElement = function(element) {
472
+ var replacement;
473
+ if (getData(element, 'ujs:disabled')) {
474
+ return;
475
+ }
476
+ replacement = element.getAttribute('data-disable-with');
477
+ if (replacement != null) {
478
+ if (matches(element, 'button')) {
479
+ setData(element, 'ujs:enable-with', element.innerHTML);
480
+ element.innerHTML = replacement;
481
+ } else {
482
+ setData(element, 'ujs:enable-with', element.value);
483
+ element.value = replacement;
484
+ }
485
+ }
486
+ element.disabled = true;
487
+ return setData(element, 'ujs:disabled', true);
488
+ };
489
+
490
+ enableFormElements = function(form) {
491
+ return formElements(form, Rails.formEnableSelector).forEach(enableFormElement);
492
+ };
493
+
494
+ enableFormElement = function(element) {
495
+ var originalText;
496
+ originalText = getData(element, 'ujs:enable-with');
497
+ if (originalText != null) {
498
+ if (matches(element, 'button')) {
499
+ element.innerHTML = originalText;
500
+ } else {
501
+ element.value = originalText;
502
+ }
503
+ setData(element, 'ujs:enable-with', null);
504
+ }
505
+ element.disabled = false;
506
+ return setData(element, 'ujs:disabled', null);
507
+ };
508
+
509
+ isXhrRedirect = function(event) {
510
+ var ref, xhr;
511
+ xhr = (ref = event.detail) != null ? ref[0] : void 0;
512
+ return (xhr != null ? xhr.getResponseHeader("X-Xhr-Redirect") : void 0) != null;
513
+ };
514
+
515
+ }).call(this);
516
+ (function() {
517
+ var stopEverything;
518
+
519
+ stopEverything = Rails.stopEverything;
520
+
521
+ Rails.handleMethod = function(e) {
522
+ var csrfParam, csrfToken, form, formContent, href, link, method;
523
+ link = this;
524
+ method = link.getAttribute('data-method');
525
+ if (!method) {
526
+ return;
527
+ }
528
+ href = Rails.href(link);
529
+ csrfToken = Rails.csrfToken();
530
+ csrfParam = Rails.csrfParam();
531
+ form = document.createElement('form');
532
+ formContent = "<input name='_method' value='" + method + "' type='hidden' />";
533
+ if ((csrfParam != null) && (csrfToken != null) && !Rails.isCrossDomain(href)) {
534
+ formContent += "<input name='" + csrfParam + "' value='" + csrfToken + "' type='hidden' />";
535
+ }
536
+ formContent += '<input type="submit" />';
537
+ form.method = 'post';
538
+ form.action = href;
539
+ form.target = link.target;
540
+ form.innerHTML = formContent;
541
+ form.style.display = 'none';
542
+ document.body.appendChild(form);
543
+ form.querySelector('[type="submit"]').click();
544
+ return stopEverything(e);
545
+ };
546
+
547
+ }).call(this);
548
+ (function() {
549
+ var ajax, fire, getData, isCrossDomain, isRemote, matches, serializeElement, setData, stopEverything,
550
+ slice = [].slice;
551
+
552
+ matches = Rails.matches, getData = Rails.getData, setData = Rails.setData, fire = Rails.fire, stopEverything = Rails.stopEverything, ajax = Rails.ajax, isCrossDomain = Rails.isCrossDomain, serializeElement = Rails.serializeElement;
553
+
554
+ isRemote = function(element) {
555
+ var value;
556
+ value = element.getAttribute('data-remote');
557
+ return (value != null) && value !== 'false';
558
+ };
559
+
560
+ Rails.handleRemote = function(e) {
561
+ var button, data, dataType, element, method, url, withCredentials;
562
+ element = this;
563
+ if (!isRemote(element)) {
564
+ return true;
565
+ }
566
+ if (!fire(element, 'ajax:before')) {
567
+ fire(element, 'ajax:stopped');
568
+ return false;
569
+ }
570
+ withCredentials = element.getAttribute('data-with-credentials');
571
+ dataType = element.getAttribute('data-type') || 'script';
572
+ if (matches(element, Rails.formSubmitSelector)) {
573
+ button = getData(element, 'ujs:submit-button');
574
+ method = getData(element, 'ujs:submit-button-formmethod') || element.method;
575
+ url = getData(element, 'ujs:submit-button-formaction') || element.getAttribute('action') || location.href;
576
+ if (method.toUpperCase() === 'GET') {
577
+ url = url.replace(/\?.*$/, '');
578
+ }
579
+ if (element.enctype === 'multipart/form-data') {
580
+ data = new FormData(element);
581
+ if (button != null) {
582
+ data.append(button.name, button.value);
583
+ }
584
+ } else {
585
+ data = serializeElement(element, button);
586
+ }
587
+ setData(element, 'ujs:submit-button', null);
588
+ setData(element, 'ujs:submit-button-formmethod', null);
589
+ setData(element, 'ujs:submit-button-formaction', null);
590
+ } else if (matches(element, Rails.buttonClickSelector) || matches(element, Rails.inputChangeSelector)) {
591
+ method = element.getAttribute('data-method');
592
+ url = element.getAttribute('data-url');
593
+ data = serializeElement(element, element.getAttribute('data-params'));
594
+ } else {
595
+ method = element.getAttribute('data-method');
596
+ url = Rails.href(element);
597
+ data = element.getAttribute('data-params');
598
+ }
599
+ ajax({
600
+ type: method || 'GET',
601
+ url: url,
602
+ data: data,
603
+ dataType: dataType,
604
+ beforeSend: function(xhr, options) {
605
+ if (fire(element, 'ajax:beforeSend', [xhr, options])) {
606
+ return fire(element, 'ajax:send', [xhr]);
607
+ } else {
608
+ fire(element, 'ajax:stopped');
609
+ return false;
610
+ }
611
+ },
612
+ success: function() {
613
+ var args;
614
+ args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
615
+ return fire(element, 'ajax:success', args);
616
+ },
617
+ error: function() {
618
+ var args;
619
+ args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
620
+ return fire(element, 'ajax:error', args);
621
+ },
622
+ complete: function() {
623
+ var args;
624
+ args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
625
+ return fire(element, 'ajax:complete', args);
626
+ },
627
+ crossDomain: isCrossDomain(url),
628
+ withCredentials: (withCredentials != null) && withCredentials !== 'false'
629
+ });
630
+ return stopEverything(e);
631
+ };
632
+
633
+ Rails.formSubmitButtonClick = function(e) {
634
+ var button, form;
635
+ button = this;
636
+ form = button.form;
637
+ if (!form) {
638
+ return;
639
+ }
640
+ if (button.name) {
641
+ setData(form, 'ujs:submit-button', {
642
+ name: button.name,
643
+ value: button.value
644
+ });
645
+ }
646
+ setData(form, 'ujs:formnovalidate-button', button.formNoValidate);
647
+ setData(form, 'ujs:submit-button-formaction', button.getAttribute('formaction'));
648
+ return setData(form, 'ujs:submit-button-formmethod', button.getAttribute('formmethod'));
649
+ };
650
+
651
+ Rails.preventInsignificantClick = function(e) {
652
+ var data, insignificantMetaClick, link, metaClick, method, nonPrimaryMouseClick;
653
+ link = this;
654
+ method = (link.getAttribute('data-method') || 'GET').toUpperCase();
655
+ data = link.getAttribute('data-params');
656
+ metaClick = e.metaKey || e.ctrlKey;
657
+ insignificantMetaClick = metaClick && method === 'GET' && !data;
658
+ nonPrimaryMouseClick = (e.button != null) && e.button !== 0;
659
+ if (nonPrimaryMouseClick || insignificantMetaClick) {
660
+ return e.stopImmediatePropagation();
661
+ }
662
+ };
663
+
664
+ }).call(this);
665
+ (function() {
666
+ var $, CSRFProtection, delegate, disableElement, enableElement, fire, formSubmitButtonClick, getData, handleConfirm, handleDisabledElement, handleMethod, handleRemote, loadCSPNonce, preventInsignificantClick, refreshCSRFTokens;
667
+
668
+ fire = Rails.fire, delegate = Rails.delegate, getData = Rails.getData, $ = Rails.$, refreshCSRFTokens = Rails.refreshCSRFTokens, CSRFProtection = Rails.CSRFProtection, loadCSPNonce = Rails.loadCSPNonce, enableElement = Rails.enableElement, disableElement = Rails.disableElement, handleDisabledElement = Rails.handleDisabledElement, handleConfirm = Rails.handleConfirm, preventInsignificantClick = Rails.preventInsignificantClick, handleRemote = Rails.handleRemote, formSubmitButtonClick = Rails.formSubmitButtonClick, handleMethod = Rails.handleMethod;
669
+
670
+ if ((typeof jQuery !== "undefined" && jQuery !== null) && (jQuery.ajax != null)) {
671
+ if (jQuery.rails) {
672
+ throw new Error('If you load both jquery_ujs and rails-ujs, use rails-ujs only.');
673
+ }
674
+ jQuery.rails = Rails;
675
+ jQuery.ajaxPrefilter(function(options, originalOptions, xhr) {
676
+ if (!options.crossDomain) {
677
+ return CSRFProtection(xhr);
678
+ }
679
+ });
680
+ }
681
+
682
+ Rails.start = function() {
683
+ if (window._rails_loaded) {
684
+ throw new Error('rails-ujs has already been loaded!');
685
+ }
686
+ window.addEventListener('pageshow', function() {
687
+ $(Rails.formEnableSelector).forEach(function(el) {
688
+ if (getData(el, 'ujs:disabled')) {
689
+ return enableElement(el);
690
+ }
691
+ });
692
+ return $(Rails.linkDisableSelector).forEach(function(el) {
693
+ if (getData(el, 'ujs:disabled')) {
694
+ return enableElement(el);
695
+ }
696
+ });
697
+ });
698
+ delegate(document, Rails.linkDisableSelector, 'ajax:complete', enableElement);
699
+ delegate(document, Rails.linkDisableSelector, 'ajax:stopped', enableElement);
700
+ delegate(document, Rails.buttonDisableSelector, 'ajax:complete', enableElement);
701
+ delegate(document, Rails.buttonDisableSelector, 'ajax:stopped', enableElement);
702
+ delegate(document, Rails.linkClickSelector, 'click', preventInsignificantClick);
703
+ delegate(document, Rails.linkClickSelector, 'click', handleDisabledElement);
704
+ delegate(document, Rails.linkClickSelector, 'click', handleConfirm);
705
+ delegate(document, Rails.linkClickSelector, 'click', disableElement);
706
+ delegate(document, Rails.linkClickSelector, 'click', handleRemote);
707
+ delegate(document, Rails.linkClickSelector, 'click', handleMethod);
708
+ delegate(document, Rails.buttonClickSelector, 'click', preventInsignificantClick);
709
+ delegate(document, Rails.buttonClickSelector, 'click', handleDisabledElement);
710
+ delegate(document, Rails.buttonClickSelector, 'click', handleConfirm);
711
+ delegate(document, Rails.buttonClickSelector, 'click', disableElement);
712
+ delegate(document, Rails.buttonClickSelector, 'click', handleRemote);
713
+ delegate(document, Rails.inputChangeSelector, 'change', handleDisabledElement);
714
+ delegate(document, Rails.inputChangeSelector, 'change', handleConfirm);
715
+ delegate(document, Rails.inputChangeSelector, 'change', handleRemote);
716
+ delegate(document, Rails.formSubmitSelector, 'submit', handleDisabledElement);
717
+ delegate(document, Rails.formSubmitSelector, 'submit', handleConfirm);
718
+ delegate(document, Rails.formSubmitSelector, 'submit', handleRemote);
719
+ delegate(document, Rails.formSubmitSelector, 'submit', function(e) {
720
+ return setTimeout((function() {
721
+ return disableElement(e);
722
+ }), 13);
723
+ });
724
+ delegate(document, Rails.formSubmitSelector, 'ajax:send', disableElement);
725
+ delegate(document, Rails.formSubmitSelector, 'ajax:complete', enableElement);
726
+ delegate(document, Rails.formInputClickSelector, 'click', preventInsignificantClick);
727
+ delegate(document, Rails.formInputClickSelector, 'click', handleDisabledElement);
728
+ delegate(document, Rails.formInputClickSelector, 'click', handleConfirm);
729
+ delegate(document, Rails.formInputClickSelector, 'click', formSubmitButtonClick);
730
+ document.addEventListener('DOMContentLoaded', refreshCSRFTokens);
731
+ document.addEventListener('DOMContentLoaded', loadCSPNonce);
732
+ return window._rails_loaded = true;
733
+ };
734
+
735
+ if (window.Rails === Rails && fire(document, 'rails:attachBindings')) {
736
+ Rails.start();
737
+ }
738
+
739
+ }).call(this);
740
+ }).call(this);
741
+
742
+ if (typeof module === "object" && module.exports) {
743
+ module.exports = Rails;
744
+ } else if (typeof define === "function" && define.amd) {
745
+ define(Rails);
746
+ }
747
+ }).call(this);