sql-jarvis 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/CHANGELOG.md +228 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +775 -0
- data/Rakefile +1 -0
- data/app/assets/fonts/blazer/glyphicons-halflings-regular.eot +0 -0
- data/app/assets/fonts/blazer/glyphicons-halflings-regular.svg +288 -0
- data/app/assets/fonts/blazer/glyphicons-halflings-regular.ttf +0 -0
- data/app/assets/fonts/blazer/glyphicons-halflings-regular.woff +0 -0
- data/app/assets/fonts/blazer/glyphicons-halflings-regular.woff2 +0 -0
- data/app/assets/javascripts/blazer/Chart.js +14145 -0
- data/app/assets/javascripts/blazer/Sortable.js +1144 -0
- data/app/assets/javascripts/blazer/ace.js +6 -0
- data/app/assets/javascripts/blazer/ace/ace.js +11 -0
- data/app/assets/javascripts/blazer/ace/ext-language_tools.js +5 -0
- data/app/assets/javascripts/blazer/ace/mode-sql.js +1 -0
- data/app/assets/javascripts/blazer/ace/snippets/sql.js +1 -0
- data/app/assets/javascripts/blazer/ace/snippets/text.js +1 -0
- data/app/assets/javascripts/blazer/ace/theme-twilight.js +1 -0
- data/app/assets/javascripts/blazer/application.js +79 -0
- data/app/assets/javascripts/blazer/bootstrap.js +2366 -0
- data/app/assets/javascripts/blazer/chartkick.js +1693 -0
- data/app/assets/javascripts/blazer/daterangepicker.js +1505 -0
- data/app/assets/javascripts/blazer/fuzzysearch.js +24 -0
- data/app/assets/javascripts/blazer/highlight.pack.js +1 -0
- data/app/assets/javascripts/blazer/jquery.js +10308 -0
- data/app/assets/javascripts/blazer/jquery.stickytableheaders.js +263 -0
- data/app/assets/javascripts/blazer/jquery_ujs.js +469 -0
- data/app/assets/javascripts/blazer/moment-timezone.js +1007 -0
- data/app/assets/javascripts/blazer/moment.js +3043 -0
- data/app/assets/javascripts/blazer/queries.js +110 -0
- data/app/assets/javascripts/blazer/routes.js +23 -0
- data/app/assets/javascripts/blazer/selectize.js +3667 -0
- data/app/assets/javascripts/blazer/stupidtable.js +114 -0
- data/app/assets/javascripts/blazer/vue.js +7515 -0
- data/app/assets/stylesheets/blazer/application.css +198 -0
- data/app/assets/stylesheets/blazer/bootstrap.css.erb +6202 -0
- data/app/assets/stylesheets/blazer/daterangepicker-bs3.css +375 -0
- data/app/assets/stylesheets/blazer/github.css +125 -0
- data/app/assets/stylesheets/blazer/selectize.default.css +387 -0
- data/app/controllers/blazer/base_controller.rb +103 -0
- data/app/controllers/blazer/checks_controller.rb +56 -0
- data/app/controllers/blazer/dashboards_controller.rb +105 -0
- data/app/controllers/blazer/queries_controller.rb +325 -0
- data/app/helpers/blazer/base_helper.rb +57 -0
- data/app/mailers/blazer/check_mailer.rb +27 -0
- data/app/models/blazer/audit.rb +6 -0
- data/app/models/blazer/check.rb +95 -0
- data/app/models/blazer/connection.rb +5 -0
- data/app/models/blazer/dashboard.rb +13 -0
- data/app/models/blazer/dashboard_query.rb +9 -0
- data/app/models/blazer/query.rb +31 -0
- data/app/models/blazer/record.rb +5 -0
- data/app/views/blazer/_nav.html.erb +16 -0
- data/app/views/blazer/_variables.html.erb +102 -0
- data/app/views/blazer/check_mailer/failing_checks.html.erb +6 -0
- data/app/views/blazer/check_mailer/state_change.html.erb +47 -0
- data/app/views/blazer/checks/_form.html.erb +71 -0
- data/app/views/blazer/checks/edit.html.erb +1 -0
- data/app/views/blazer/checks/index.html.erb +40 -0
- data/app/views/blazer/checks/new.html.erb +1 -0
- data/app/views/blazer/dashboards/_form.html.erb +76 -0
- data/app/views/blazer/dashboards/edit.html.erb +1 -0
- data/app/views/blazer/dashboards/new.html.erb +1 -0
- data/app/views/blazer/dashboards/show.html.erb +47 -0
- data/app/views/blazer/queries/_form.html.erb +240 -0
- data/app/views/blazer/queries/edit.html.erb +2 -0
- data/app/views/blazer/queries/home.html.erb +152 -0
- data/app/views/blazer/queries/new.html.erb +2 -0
- data/app/views/blazer/queries/run.html.erb +163 -0
- data/app/views/blazer/queries/schema.html.erb +18 -0
- data/app/views/blazer/queries/show.html.erb +73 -0
- data/app/views/layouts/blazer/application.html.erb +24 -0
- data/blazer.gemspec +26 -0
- data/config/routes.rb +16 -0
- data/lib/blazer.rb +185 -0
- data/lib/blazer/adapters/athena_adapter.rb +128 -0
- data/lib/blazer/adapters/base_adapter.rb +53 -0
- data/lib/blazer/adapters/bigquery_adapter.rb +67 -0
- data/lib/blazer/adapters/drill_adapter.rb +28 -0
- data/lib/blazer/adapters/elasticsearch_adapter.rb +49 -0
- data/lib/blazer/adapters/mongodb_adapter.rb +39 -0
- data/lib/blazer/adapters/presto_adapter.rb +45 -0
- data/lib/blazer/adapters/sql_adapter.rb +182 -0
- data/lib/blazer/data_source.rb +193 -0
- data/lib/blazer/detect_anomalies.R +19 -0
- data/lib/blazer/engine.rb +47 -0
- data/lib/blazer/result.rb +170 -0
- data/lib/blazer/run_statement.rb +40 -0
- data/lib/blazer/run_statement_job.rb +21 -0
- data/lib/blazer/version.rb +3 -0
- data/lib/generators/blazer/install_generator.rb +39 -0
- data/lib/generators/blazer/templates/config.yml +62 -0
- data/lib/generators/blazer/templates/install.rb +45 -0
- data/lib/tasks/blazer.rake +10 -0
- metadata +211 -0
@@ -0,0 +1,263 @@
|
|
1
|
+
/*! Copyright (c) 2011 by Jonas Mosbech - https://github.com/jmosbech/StickyTableHeaders
|
2
|
+
MIT license info: https://github.com/jmosbech/StickyTableHeaders/blob/master/license.txt */
|
3
|
+
|
4
|
+
;(function ($, window, undefined) {
|
5
|
+
'use strict';
|
6
|
+
|
7
|
+
var name = 'stickyTableHeaders',
|
8
|
+
id = 0,
|
9
|
+
defaults = {
|
10
|
+
fixedOffset: 0,
|
11
|
+
leftOffset: 0,
|
12
|
+
scrollableArea: window
|
13
|
+
};
|
14
|
+
|
15
|
+
function Plugin (el, options) {
|
16
|
+
// To avoid scope issues, use 'base' instead of 'this'
|
17
|
+
// to reference this class from internal events and functions.
|
18
|
+
var base = this;
|
19
|
+
|
20
|
+
// Access to jQuery and DOM versions of element
|
21
|
+
base.$el = $(el);
|
22
|
+
base.el = el;
|
23
|
+
base.id = id++;
|
24
|
+
|
25
|
+
// Listen for destroyed, call teardown
|
26
|
+
base.$el.bind('destroyed',
|
27
|
+
$.proxy(base.teardown, base));
|
28
|
+
|
29
|
+
// Cache DOM refs for performance reasons
|
30
|
+
base.$clonedHeader = null;
|
31
|
+
base.$originalHeader = null;
|
32
|
+
|
33
|
+
// Keep track of state
|
34
|
+
base.isSticky = false;
|
35
|
+
base.hasBeenSticky = false;
|
36
|
+
base.leftOffset = null;
|
37
|
+
base.topOffset = null;
|
38
|
+
|
39
|
+
base.init = function () {
|
40
|
+
base.options = $.extend({}, defaults, options);
|
41
|
+
|
42
|
+
base.$el.each(function () {
|
43
|
+
var $this = $(this);
|
44
|
+
|
45
|
+
// remove padding on <table> to fix issue #7
|
46
|
+
$this.css('padding', 0);
|
47
|
+
|
48
|
+
base.$scrollableArea = $(base.options.scrollableArea);
|
49
|
+
|
50
|
+
base.$originalHeader = $('thead:first', this);
|
51
|
+
base.$clonedHeader = base.$originalHeader.clone();
|
52
|
+
$this.trigger('clonedHeader.' + name, [base.$clonedHeader]);
|
53
|
+
|
54
|
+
base.$clonedHeader.addClass('tableFloatingHeader');
|
55
|
+
base.$clonedHeader.css('display', 'none');
|
56
|
+
|
57
|
+
base.$originalHeader.addClass('tableFloatingHeaderOriginal');
|
58
|
+
|
59
|
+
base.$originalHeader.after(base.$clonedHeader);
|
60
|
+
|
61
|
+
base.$printStyle = $('<style type="text/css" media="print">' +
|
62
|
+
'.tableFloatingHeader{display:none !important;}' +
|
63
|
+
'.tableFloatingHeaderOriginal{position:static !important;}' +
|
64
|
+
'</style>');
|
65
|
+
$('head').append(base.$printStyle);
|
66
|
+
});
|
67
|
+
|
68
|
+
base.updateWidth();
|
69
|
+
base.toggleHeaders();
|
70
|
+
|
71
|
+
base.bind();
|
72
|
+
};
|
73
|
+
|
74
|
+
base.destroy = function (){
|
75
|
+
base.$el.unbind('destroyed', base.teardown);
|
76
|
+
base.teardown();
|
77
|
+
};
|
78
|
+
|
79
|
+
base.teardown = function(){
|
80
|
+
if (base.isSticky) {
|
81
|
+
base.$originalHeader.css('position', 'static');
|
82
|
+
}
|
83
|
+
$.removeData(base.el, 'plugin_' + name);
|
84
|
+
base.unbind();
|
85
|
+
|
86
|
+
base.$clonedHeader.remove();
|
87
|
+
base.$originalHeader.removeClass('tableFloatingHeaderOriginal');
|
88
|
+
base.$originalHeader.css('visibility', 'visible');
|
89
|
+
base.$printStyle.remove();
|
90
|
+
|
91
|
+
base.el = null;
|
92
|
+
base.$el = null;
|
93
|
+
};
|
94
|
+
|
95
|
+
base.bind = function(){
|
96
|
+
base.$scrollableArea.on('scroll.' + name, base.toggleHeaders);
|
97
|
+
if (!base.isWindowScrolling()) {
|
98
|
+
$(window).on('scroll.' + name + base.id, base.setPositionValues);
|
99
|
+
$(window).on('resize.' + name + base.id, base.toggleHeaders);
|
100
|
+
}
|
101
|
+
base.$scrollableArea.on('resize.' + name, base.toggleHeaders);
|
102
|
+
base.$scrollableArea.on('resize.' + name, base.updateWidth);
|
103
|
+
};
|
104
|
+
|
105
|
+
base.unbind = function(){
|
106
|
+
// unbind window events by specifying handle so we don't remove too much
|
107
|
+
base.$scrollableArea.off('.' + name, base.toggleHeaders);
|
108
|
+
if (!base.isWindowScrolling()) {
|
109
|
+
$(window).off('.' + name + base.id, base.setPositionValues);
|
110
|
+
$(window).off('.' + name + base.id, base.toggleHeaders);
|
111
|
+
}
|
112
|
+
base.$scrollableArea.off('.' + name, base.updateWidth);
|
113
|
+
base.$el.off('.' + name);
|
114
|
+
base.$el.find('*').off('.' + name);
|
115
|
+
};
|
116
|
+
|
117
|
+
base.toggleHeaders = function () {
|
118
|
+
if (base.$el) {
|
119
|
+
base.$el.each(function () {
|
120
|
+
var $this = $(this),
|
121
|
+
newLeft,
|
122
|
+
newTopOffset = base.isWindowScrolling() ? (
|
123
|
+
isNaN(base.options.fixedOffset) ?
|
124
|
+
base.options.fixedOffset.outerHeight() :
|
125
|
+
base.options.fixedOffset
|
126
|
+
) :
|
127
|
+
base.$scrollableArea.offset().top + (!isNaN(base.options.fixedOffset) ? base.options.fixedOffset : 0),
|
128
|
+
offset = $this.offset(),
|
129
|
+
|
130
|
+
scrollTop = base.$scrollableArea.scrollTop() + newTopOffset,
|
131
|
+
scrollLeft = base.$scrollableArea.scrollLeft(),
|
132
|
+
|
133
|
+
scrolledPastTop = base.isWindowScrolling() ?
|
134
|
+
scrollTop > offset.top :
|
135
|
+
newTopOffset > offset.top,
|
136
|
+
notScrolledPastBottom = (base.isWindowScrolling() ? scrollTop : 0) <
|
137
|
+
(offset.top + $this.height() - base.$clonedHeader.height() - (base.isWindowScrolling() ? 0 : newTopOffset));
|
138
|
+
|
139
|
+
if (scrolledPastTop && notScrolledPastBottom) {
|
140
|
+
newLeft = offset.left - scrollLeft + base.options.leftOffset;
|
141
|
+
base.$originalHeader.css({
|
142
|
+
'position': 'fixed',
|
143
|
+
'margin-top': 0,
|
144
|
+
'left': newLeft,
|
145
|
+
'z-index': 1 // #18: opacity bug
|
146
|
+
});
|
147
|
+
base.isSticky = true;
|
148
|
+
base.leftOffset = newLeft;
|
149
|
+
base.topOffset = newTopOffset;
|
150
|
+
base.$clonedHeader.css('display', '');
|
151
|
+
base.setPositionValues();
|
152
|
+
// make sure the width is correct: the user might have resized the browser while in static mode
|
153
|
+
base.updateWidth();
|
154
|
+
} else if (base.isSticky) {
|
155
|
+
base.$originalHeader.css('position', 'static');
|
156
|
+
base.$clonedHeader.css('display', 'none');
|
157
|
+
base.isSticky = false;
|
158
|
+
base.resetWidth($("td,th", base.$clonedHeader), $("td,th", base.$originalHeader));
|
159
|
+
}
|
160
|
+
});
|
161
|
+
}
|
162
|
+
};
|
163
|
+
|
164
|
+
base.isWindowScrolling = function() {
|
165
|
+
return base.$scrollableArea[0] === window;
|
166
|
+
};
|
167
|
+
|
168
|
+
base.setPositionValues = function () {
|
169
|
+
var winScrollTop = $(window).scrollTop(),
|
170
|
+
winScrollLeft = $(window).scrollLeft();
|
171
|
+
if (!base.isSticky ||
|
172
|
+
winScrollTop < 0 || winScrollTop + $(window).height() > $(document).height() ||
|
173
|
+
winScrollLeft < 0 || winScrollLeft + $(window).width() > $(document).width()) {
|
174
|
+
return;
|
175
|
+
}
|
176
|
+
base.$originalHeader.css({
|
177
|
+
'top': base.topOffset - (base.isWindowScrolling() ? 0 : winScrollTop),
|
178
|
+
'left': base.leftOffset - (base.isWindowScrolling() ? 0 : winScrollLeft)
|
179
|
+
});
|
180
|
+
};
|
181
|
+
|
182
|
+
base.updateWidth = function () {
|
183
|
+
if (!base.isSticky) {
|
184
|
+
return;
|
185
|
+
}
|
186
|
+
// Copy cell widths from clone
|
187
|
+
if (!base.$originalHeaderCells) {
|
188
|
+
base.$originalHeaderCells = $('th,td', base.$originalHeader);
|
189
|
+
}
|
190
|
+
if (!base.$clonedHeaderCells) {
|
191
|
+
base.$clonedHeaderCells = $('th,td', base.$clonedHeader);
|
192
|
+
}
|
193
|
+
var cellWidths = base.getWidth(base.$clonedHeaderCells);
|
194
|
+
base.setWidth(cellWidths, base.$clonedHeaderCells, base.$originalHeaderCells);
|
195
|
+
|
196
|
+
// Copy row width from whole table
|
197
|
+
base.$originalHeader.css('width', base.$clonedHeader.width());
|
198
|
+
};
|
199
|
+
|
200
|
+
base.getWidth = function ($clonedHeaders) {
|
201
|
+
var widths = [];
|
202
|
+
$clonedHeaders.each(function (index) {
|
203
|
+
var width, $this = $(this);
|
204
|
+
|
205
|
+
if ($this.css('box-sizing') === 'border-box') {
|
206
|
+
width = $this.outerWidth(); // #39: border-box bug
|
207
|
+
} else {
|
208
|
+
width = $this.width();
|
209
|
+
}
|
210
|
+
|
211
|
+
widths[index] = width;
|
212
|
+
});
|
213
|
+
return widths;
|
214
|
+
};
|
215
|
+
|
216
|
+
base.setWidth = function (widths, $clonedHeaders, $origHeaders) {
|
217
|
+
$clonedHeaders.each(function (index) {
|
218
|
+
var width = widths[index];
|
219
|
+
$origHeaders.eq(index).css({
|
220
|
+
'min-width': width,
|
221
|
+
'max-width': width
|
222
|
+
});
|
223
|
+
});
|
224
|
+
};
|
225
|
+
|
226
|
+
base.resetWidth = function ($clonedHeaders, $origHeaders) {
|
227
|
+
$clonedHeaders.each(function (index) {
|
228
|
+
var $this = $(this);
|
229
|
+
$origHeaders.eq(index).css({
|
230
|
+
'min-width': $this.css("min-width"),
|
231
|
+
'max-width': $this.css("max-width")
|
232
|
+
});
|
233
|
+
});
|
234
|
+
};
|
235
|
+
|
236
|
+
base.updateOptions = function(options) {
|
237
|
+
base.options = $.extend({}, defaults, options);
|
238
|
+
base.updateWidth();
|
239
|
+
base.toggleHeaders();
|
240
|
+
};
|
241
|
+
|
242
|
+
// Run initializer
|
243
|
+
base.init();
|
244
|
+
}
|
245
|
+
|
246
|
+
// A plugin wrapper around the constructor,
|
247
|
+
// preventing against multiple instantiations
|
248
|
+
$.fn[name] = function ( options ) {
|
249
|
+
return this.each(function () {
|
250
|
+
var instance = $.data(this, 'plugin_' + name);
|
251
|
+
if (instance) {
|
252
|
+
if (typeof options === "string") {
|
253
|
+
instance[options].apply(instance);
|
254
|
+
} else {
|
255
|
+
instance.updateOptions(options);
|
256
|
+
}
|
257
|
+
} else if(options !== 'destroy') {
|
258
|
+
$.data(this, 'plugin_' + name, new Plugin( this, options ));
|
259
|
+
}
|
260
|
+
});
|
261
|
+
};
|
262
|
+
|
263
|
+
})(jQuery, window);
|
@@ -0,0 +1,469 @@
|
|
1
|
+
(function($, undefined) {
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Unobtrusive scripting adapter for jQuery
|
5
|
+
* https://github.com/rails/jquery-ujs
|
6
|
+
*
|
7
|
+
* Requires jQuery 1.8.0 or later.
|
8
|
+
*
|
9
|
+
* Released under the MIT license
|
10
|
+
*
|
11
|
+
*/
|
12
|
+
|
13
|
+
// Cut down on the number of issues from people inadvertently including jquery_ujs twice
|
14
|
+
// by detecting and raising an error when it happens.
|
15
|
+
if ( $.rails !== undefined ) {
|
16
|
+
$.error('jquery-ujs has already been loaded!');
|
17
|
+
}
|
18
|
+
|
19
|
+
// Shorthand to make it a little easier to call public rails functions from within rails.js
|
20
|
+
var rails;
|
21
|
+
var $document = $(document);
|
22
|
+
|
23
|
+
$.rails = rails = {
|
24
|
+
// Link elements bound by jquery-ujs
|
25
|
+
linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote], a[data-disable-with], a[data-disable]',
|
26
|
+
|
27
|
+
// Button elements bound by jquery-ujs
|
28
|
+
buttonClickSelector: 'button[data-remote]:not(form button), button[data-confirm]:not(form button)',
|
29
|
+
|
30
|
+
// Select elements bound by jquery-ujs
|
31
|
+
inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]',
|
32
|
+
|
33
|
+
// Form elements bound by jquery-ujs
|
34
|
+
formSubmitSelector: 'form',
|
35
|
+
|
36
|
+
// Form input elements bound by jquery-ujs
|
37
|
+
formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not([type]), input[type=submit][form], input[type=image][form], button[type=submit][form], button[form]:not([type])',
|
38
|
+
|
39
|
+
// Form input elements disabled during form submission
|
40
|
+
disableSelector: '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',
|
41
|
+
|
42
|
+
// Form input elements re-enabled after form submission
|
43
|
+
enableSelector: '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',
|
44
|
+
|
45
|
+
// Form required input elements
|
46
|
+
requiredInputSelector: 'input[name][required]:not([disabled]),textarea[name][required]:not([disabled])',
|
47
|
+
|
48
|
+
// Form file input elements
|
49
|
+
fileInputSelector: 'input[type=file]',
|
50
|
+
|
51
|
+
// Link onClick disable selector with possible reenable after remote submission
|
52
|
+
linkDisableSelector: 'a[data-disable-with], a[data-disable]',
|
53
|
+
|
54
|
+
// Button onClick disable selector with possible reenable after remote submission
|
55
|
+
buttonDisableSelector: 'button[data-remote][data-disable-with], button[data-remote][data-disable]',
|
56
|
+
|
57
|
+
// Make sure that every Ajax request sends the CSRF token
|
58
|
+
CSRFProtection: function(xhr) {
|
59
|
+
var token = $('meta[name="csrf-token"]').attr('content');
|
60
|
+
if (token) xhr.setRequestHeader('X-CSRF-Token', token);
|
61
|
+
},
|
62
|
+
|
63
|
+
// making sure that all forms have actual up-to-date token(cached forms contain old one)
|
64
|
+
refreshCSRFTokens: function(){
|
65
|
+
var csrfToken = $('meta[name=csrf-token]').attr('content');
|
66
|
+
var csrfParam = $('meta[name=csrf-param]').attr('content');
|
67
|
+
$('form input[name="' + csrfParam + '"]').val(csrfToken);
|
68
|
+
},
|
69
|
+
|
70
|
+
// Triggers an event on an element and returns false if the event result is false
|
71
|
+
fire: function(obj, name, data) {
|
72
|
+
var event = $.Event(name);
|
73
|
+
obj.trigger(event, data);
|
74
|
+
return event.result !== false;
|
75
|
+
},
|
76
|
+
|
77
|
+
// Default confirm dialog, may be overridden with custom confirm dialog in $.rails.confirm
|
78
|
+
confirm: function(message) {
|
79
|
+
return confirm(message);
|
80
|
+
},
|
81
|
+
|
82
|
+
// Default ajax function, may be overridden with custom function in $.rails.ajax
|
83
|
+
ajax: function(options) {
|
84
|
+
return $.ajax(options);
|
85
|
+
},
|
86
|
+
|
87
|
+
// Default way to get an element's href. May be overridden at $.rails.href.
|
88
|
+
href: function(element) {
|
89
|
+
return element.attr('href');
|
90
|
+
},
|
91
|
+
|
92
|
+
// Submits "remote" forms and links with ajax
|
93
|
+
handleRemote: function(element) {
|
94
|
+
var method, url, data, elCrossDomain, crossDomain, withCredentials, dataType, options;
|
95
|
+
|
96
|
+
if (rails.fire(element, 'ajax:before')) {
|
97
|
+
elCrossDomain = element.data('cross-domain');
|
98
|
+
crossDomain = elCrossDomain === undefined ? null : elCrossDomain;
|
99
|
+
withCredentials = element.data('with-credentials') || null;
|
100
|
+
dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType);
|
101
|
+
|
102
|
+
if (element.is('form')) {
|
103
|
+
method = element.attr('method');
|
104
|
+
url = element.attr('action');
|
105
|
+
data = element.serializeArray();
|
106
|
+
// memoized value from clicked submit button
|
107
|
+
var button = element.data('ujs:submit-button');
|
108
|
+
if (button) {
|
109
|
+
data.push(button);
|
110
|
+
element.data('ujs:submit-button', null);
|
111
|
+
}
|
112
|
+
} else if (element.is(rails.inputChangeSelector)) {
|
113
|
+
method = element.data('method');
|
114
|
+
url = element.data('url');
|
115
|
+
data = element.serialize();
|
116
|
+
if (element.data('params')) data = data + "&" + element.data('params');
|
117
|
+
} else if (element.is(rails.buttonClickSelector)) {
|
118
|
+
method = element.data('method') || 'get';
|
119
|
+
url = element.data('url');
|
120
|
+
data = element.serialize();
|
121
|
+
if (element.data('params')) data = data + "&" + element.data('params');
|
122
|
+
} else {
|
123
|
+
method = element.data('method');
|
124
|
+
url = rails.href(element);
|
125
|
+
data = element.data('params') || null;
|
126
|
+
}
|
127
|
+
|
128
|
+
options = {
|
129
|
+
type: method || 'GET', data: data, dataType: dataType,
|
130
|
+
// stopping the "ajax:beforeSend" event will cancel the ajax request
|
131
|
+
beforeSend: function(xhr, settings) {
|
132
|
+
if (settings.dataType === undefined) {
|
133
|
+
xhr.setRequestHeader('accept', '*/*;q=0.5, ' + settings.accepts.script);
|
134
|
+
}
|
135
|
+
if (rails.fire(element, 'ajax:beforeSend', [xhr, settings])) {
|
136
|
+
element.trigger('ajax:send', xhr);
|
137
|
+
} else {
|
138
|
+
return false;
|
139
|
+
}
|
140
|
+
},
|
141
|
+
success: function(data, status, xhr) {
|
142
|
+
element.trigger('ajax:success', [data, status, xhr]);
|
143
|
+
},
|
144
|
+
complete: function(xhr, status) {
|
145
|
+
element.trigger('ajax:complete', [xhr, status]);
|
146
|
+
},
|
147
|
+
error: function(xhr, status, error) {
|
148
|
+
element.trigger('ajax:error', [xhr, status, error]);
|
149
|
+
},
|
150
|
+
crossDomain: crossDomain
|
151
|
+
};
|
152
|
+
|
153
|
+
// There is no withCredentials for IE6-8 when
|
154
|
+
// "Enable native XMLHTTP support" is disabled
|
155
|
+
if (withCredentials) {
|
156
|
+
options.xhrFields = {
|
157
|
+
withCredentials: withCredentials
|
158
|
+
};
|
159
|
+
}
|
160
|
+
|
161
|
+
// Only pass url to `ajax` options if not blank
|
162
|
+
if (url) { options.url = url; }
|
163
|
+
|
164
|
+
return rails.ajax(options);
|
165
|
+
} else {
|
166
|
+
return false;
|
167
|
+
}
|
168
|
+
},
|
169
|
+
|
170
|
+
// Handles "data-method" on links such as:
|
171
|
+
// <a href="/users/5" data-method="delete" rel="nofollow" data-confirm="Are you sure?">Delete</a>
|
172
|
+
handleMethod: function(link) {
|
173
|
+
var href = rails.href(link),
|
174
|
+
method = link.data('method'),
|
175
|
+
target = link.attr('target'),
|
176
|
+
csrfToken = $('meta[name=csrf-token]').attr('content'),
|
177
|
+
csrfParam = $('meta[name=csrf-param]').attr('content'),
|
178
|
+
form = $('<form method="post" action="' + href + '"></form>'),
|
179
|
+
metadataInput = '<input name="_method" value="' + method + '" type="hidden" />';
|
180
|
+
|
181
|
+
if (csrfParam !== undefined && csrfToken !== undefined) {
|
182
|
+
metadataInput += '<input name="' + csrfParam + '" value="' + csrfToken + '" type="hidden" />';
|
183
|
+
}
|
184
|
+
|
185
|
+
if (target) { form.attr('target', target); }
|
186
|
+
|
187
|
+
form.hide().append(metadataInput).appendTo('body');
|
188
|
+
form.submit();
|
189
|
+
},
|
190
|
+
|
191
|
+
// Helper function that returns form elements that match the specified CSS selector
|
192
|
+
// If form is actually a "form" element this will return associated elements outside the from that have
|
193
|
+
// the html form attribute set
|
194
|
+
formElements: function(form, selector) {
|
195
|
+
return form.is('form') ? $(form[0].elements).filter(selector) : form.find(selector);
|
196
|
+
},
|
197
|
+
|
198
|
+
/* Disables form elements:
|
199
|
+
- Caches element value in 'ujs:enable-with' data store
|
200
|
+
- Replaces element text with value of 'data-disable-with' attribute
|
201
|
+
- Sets disabled property to true
|
202
|
+
*/
|
203
|
+
disableFormElements: function(form) {
|
204
|
+
rails.formElements(form, rails.disableSelector).each(function() {
|
205
|
+
rails.disableFormElement($(this));
|
206
|
+
});
|
207
|
+
},
|
208
|
+
|
209
|
+
disableFormElement: function(element) {
|
210
|
+
var method, replacement;
|
211
|
+
|
212
|
+
method = element.is('button') ? 'html' : 'val';
|
213
|
+
replacement = element.data('disable-with');
|
214
|
+
|
215
|
+
element.data('ujs:enable-with', element[method]());
|
216
|
+
if (replacement !== undefined) {
|
217
|
+
element[method](replacement);
|
218
|
+
}
|
219
|
+
|
220
|
+
element.prop('disabled', true);
|
221
|
+
},
|
222
|
+
|
223
|
+
/* Re-enables disabled form elements:
|
224
|
+
- Replaces element text with cached value from 'ujs:enable-with' data store (created in `disableFormElements`)
|
225
|
+
- Sets disabled property to false
|
226
|
+
*/
|
227
|
+
enableFormElements: function(form) {
|
228
|
+
rails.formElements(form, rails.enableSelector).each(function() {
|
229
|
+
rails.enableFormElement($(this));
|
230
|
+
});
|
231
|
+
},
|
232
|
+
|
233
|
+
enableFormElement: function(element) {
|
234
|
+
var method = element.is('button') ? 'html' : 'val';
|
235
|
+
if (element.data('ujs:enable-with')) element[method](element.data('ujs:enable-with'));
|
236
|
+
element.prop('disabled', false);
|
237
|
+
},
|
238
|
+
|
239
|
+
/* For 'data-confirm' attribute:
|
240
|
+
- Fires `confirm` event
|
241
|
+
- Shows the confirmation dialog
|
242
|
+
- Fires the `confirm:complete` event
|
243
|
+
|
244
|
+
Returns `true` if no function stops the chain and user chose yes; `false` otherwise.
|
245
|
+
Attaching a handler to the element's `confirm` event that returns a `falsy` value cancels the confirmation dialog.
|
246
|
+
Attaching a handler to the element's `confirm:complete` event that returns a `falsy` value makes this function
|
247
|
+
return false. The `confirm:complete` event is fired whether or not the user answered true or false to the dialog.
|
248
|
+
*/
|
249
|
+
allowAction: function(element) {
|
250
|
+
var message = element.data('confirm'),
|
251
|
+
answer = false, callback;
|
252
|
+
if (!message) { return true; }
|
253
|
+
|
254
|
+
if (rails.fire(element, 'confirm')) {
|
255
|
+
answer = rails.confirm(message);
|
256
|
+
callback = rails.fire(element, 'confirm:complete', [answer]);
|
257
|
+
}
|
258
|
+
return answer && callback;
|
259
|
+
},
|
260
|
+
|
261
|
+
// Helper function which checks for blank inputs in a form that match the specified CSS selector
|
262
|
+
blankInputs: function(form, specifiedSelector, nonBlank) {
|
263
|
+
var inputs = $(), input, valueToCheck,
|
264
|
+
selector = specifiedSelector || 'input,textarea',
|
265
|
+
allInputs = form.find(selector);
|
266
|
+
|
267
|
+
allInputs.each(function() {
|
268
|
+
input = $(this);
|
269
|
+
valueToCheck = input.is('input[type=checkbox],input[type=radio]') ? input.is(':checked') : input.val();
|
270
|
+
// If nonBlank and valueToCheck are both truthy, or nonBlank and valueToCheck are both falsey
|
271
|
+
if (!valueToCheck === !nonBlank) {
|
272
|
+
|
273
|
+
// Don't count unchecked required radio if other radio with same name is checked
|
274
|
+
if (input.is('input[type=radio]') && allInputs.filter('input[type=radio]:checked[name="' + input.attr('name') + '"]').length) {
|
275
|
+
return true; // Skip to next input
|
276
|
+
}
|
277
|
+
|
278
|
+
inputs = inputs.add(input);
|
279
|
+
}
|
280
|
+
});
|
281
|
+
return inputs.length ? inputs : false;
|
282
|
+
},
|
283
|
+
|
284
|
+
// Helper function which checks for non-blank inputs in a form that match the specified CSS selector
|
285
|
+
nonBlankInputs: function(form, specifiedSelector) {
|
286
|
+
return rails.blankInputs(form, specifiedSelector, true); // true specifies nonBlank
|
287
|
+
},
|
288
|
+
|
289
|
+
// Helper function, needed to provide consistent behavior in IE
|
290
|
+
stopEverything: function(e) {
|
291
|
+
$(e.target).trigger('ujs:everythingStopped');
|
292
|
+
e.stopImmediatePropagation();
|
293
|
+
return false;
|
294
|
+
},
|
295
|
+
|
296
|
+
// replace element's html with the 'data-disable-with' after storing original html
|
297
|
+
// and prevent clicking on it
|
298
|
+
disableElement: function(element) {
|
299
|
+
var replacement = element.data('disable-with');
|
300
|
+
|
301
|
+
element.data('ujs:enable-with', element.html()); // store enabled state
|
302
|
+
if (replacement !== undefined) {
|
303
|
+
element.html(replacement);
|
304
|
+
}
|
305
|
+
|
306
|
+
element.bind('click.railsDisable', function(e) { // prevent further clicking
|
307
|
+
return rails.stopEverything(e);
|
308
|
+
});
|
309
|
+
},
|
310
|
+
|
311
|
+
// restore element to its original state which was disabled by 'disableElement' above
|
312
|
+
enableElement: function(element) {
|
313
|
+
if (element.data('ujs:enable-with') !== undefined) {
|
314
|
+
element.html(element.data('ujs:enable-with')); // set to old enabled state
|
315
|
+
element.removeData('ujs:enable-with'); // clean up cache
|
316
|
+
}
|
317
|
+
element.unbind('click.railsDisable'); // enable element
|
318
|
+
}
|
319
|
+
};
|
320
|
+
|
321
|
+
if (rails.fire($document, 'rails:attachBindings')) {
|
322
|
+
|
323
|
+
$.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { rails.CSRFProtection(xhr); }});
|
324
|
+
|
325
|
+
// This event works the same as the load event, except that it fires every
|
326
|
+
// time the page is loaded.
|
327
|
+
//
|
328
|
+
// See https://github.com/rails/jquery-ujs/issues/357
|
329
|
+
// See https://developer.mozilla.org/en-US/docs/Using_Firefox_1.5_caching
|
330
|
+
$(window).on("pageshow.rails", function () {
|
331
|
+
$($.rails.enableSelector).each(function () {
|
332
|
+
var element = $(this);
|
333
|
+
|
334
|
+
if (element.data("ujs:enable-with")) {
|
335
|
+
$.rails.enableFormElement(element);
|
336
|
+
}
|
337
|
+
});
|
338
|
+
|
339
|
+
$($.rails.linkDisableSelector).each(function () {
|
340
|
+
var element = $(this);
|
341
|
+
|
342
|
+
if (element.data("ujs:enable-with")) {
|
343
|
+
$.rails.enableElement(element);
|
344
|
+
}
|
345
|
+
});
|
346
|
+
});
|
347
|
+
|
348
|
+
$document.delegate(rails.linkDisableSelector, 'ajax:complete', function() {
|
349
|
+
rails.enableElement($(this));
|
350
|
+
});
|
351
|
+
|
352
|
+
$document.delegate(rails.buttonDisableSelector, 'ajax:complete', function() {
|
353
|
+
rails.enableFormElement($(this));
|
354
|
+
});
|
355
|
+
|
356
|
+
$document.delegate(rails.linkClickSelector, 'click.rails', function(e) {
|
357
|
+
var link = $(this), method = link.data('method'), data = link.data('params'), metaClick = e.metaKey || e.ctrlKey;
|
358
|
+
if (!rails.allowAction(link)) return rails.stopEverything(e);
|
359
|
+
|
360
|
+
if (!metaClick && link.is(rails.linkDisableSelector)) rails.disableElement(link);
|
361
|
+
|
362
|
+
if (link.data('remote') !== undefined) {
|
363
|
+
if (metaClick && (!method || method === 'GET') && !data) { return true; }
|
364
|
+
|
365
|
+
var handleRemote = rails.handleRemote(link);
|
366
|
+
// response from rails.handleRemote() will either be false or a deferred object promise.
|
367
|
+
if (handleRemote === false) {
|
368
|
+
rails.enableElement(link);
|
369
|
+
} else {
|
370
|
+
handleRemote.error( function() { rails.enableElement(link); } );
|
371
|
+
}
|
372
|
+
return false;
|
373
|
+
|
374
|
+
} else if (link.data('method')) {
|
375
|
+
rails.handleMethod(link);
|
376
|
+
return false;
|
377
|
+
}
|
378
|
+
});
|
379
|
+
|
380
|
+
$document.delegate(rails.buttonClickSelector, 'click.rails', function(e) {
|
381
|
+
var button = $(this);
|
382
|
+
|
383
|
+
if (!rails.allowAction(button)) return rails.stopEverything(e);
|
384
|
+
|
385
|
+
if (button.is(rails.buttonDisableSelector)) rails.disableFormElement(button);
|
386
|
+
|
387
|
+
var handleRemote = rails.handleRemote(button);
|
388
|
+
// response from rails.handleRemote() will either be false or a deferred object promise.
|
389
|
+
if (handleRemote === false) {
|
390
|
+
rails.enableFormElement(button);
|
391
|
+
} else {
|
392
|
+
handleRemote.error( function() { rails.enableFormElement(button); } );
|
393
|
+
}
|
394
|
+
return false;
|
395
|
+
});
|
396
|
+
|
397
|
+
$document.delegate(rails.inputChangeSelector, 'change.rails', function(e) {
|
398
|
+
var link = $(this);
|
399
|
+
if (!rails.allowAction(link)) return rails.stopEverything(e);
|
400
|
+
|
401
|
+
rails.handleRemote(link);
|
402
|
+
return false;
|
403
|
+
});
|
404
|
+
|
405
|
+
$document.delegate(rails.formSubmitSelector, 'submit.rails', function(e) {
|
406
|
+
var form = $(this),
|
407
|
+
remote = form.data('remote') !== undefined,
|
408
|
+
blankRequiredInputs,
|
409
|
+
nonBlankFileInputs;
|
410
|
+
|
411
|
+
if (!rails.allowAction(form)) return rails.stopEverything(e);
|
412
|
+
|
413
|
+
// skip other logic when required values are missing or file upload is present
|
414
|
+
if (form.attr('novalidate') == undefined) {
|
415
|
+
blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector);
|
416
|
+
if (blankRequiredInputs && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) {
|
417
|
+
return rails.stopEverything(e);
|
418
|
+
}
|
419
|
+
}
|
420
|
+
|
421
|
+
if (remote) {
|
422
|
+
nonBlankFileInputs = rails.nonBlankInputs(form, rails.fileInputSelector);
|
423
|
+
if (nonBlankFileInputs) {
|
424
|
+
// slight timeout so that the submit button gets properly serialized
|
425
|
+
// (make it easy for event handler to serialize form without disabled values)
|
426
|
+
setTimeout(function(){ rails.disableFormElements(form); }, 13);
|
427
|
+
var aborted = rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]);
|
428
|
+
|
429
|
+
// re-enable form elements if event bindings return false (canceling normal form submission)
|
430
|
+
if (!aborted) { setTimeout(function(){ rails.enableFormElements(form); }, 13); }
|
431
|
+
|
432
|
+
return aborted;
|
433
|
+
}
|
434
|
+
|
435
|
+
rails.handleRemote(form);
|
436
|
+
return false;
|
437
|
+
|
438
|
+
} else {
|
439
|
+
// slight timeout so that the submit button gets properly serialized
|
440
|
+
setTimeout(function(){ rails.disableFormElements(form); }, 13);
|
441
|
+
}
|
442
|
+
});
|
443
|
+
|
444
|
+
$document.delegate(rails.formInputClickSelector, 'click.rails', function(event) {
|
445
|
+
var button = $(this);
|
446
|
+
|
447
|
+
if (!rails.allowAction(button)) return rails.stopEverything(event);
|
448
|
+
|
449
|
+
// register the pressed submit button
|
450
|
+
var name = button.attr('name'),
|
451
|
+
data = name ? {name:name, value:button.val()} : null;
|
452
|
+
|
453
|
+
button.closest('form').data('ujs:submit-button', data);
|
454
|
+
});
|
455
|
+
|
456
|
+
$document.delegate(rails.formSubmitSelector, 'ajax:send.rails', function(event) {
|
457
|
+
if (this == event.target) rails.disableFormElements($(this));
|
458
|
+
});
|
459
|
+
|
460
|
+
$document.delegate(rails.formSubmitSelector, 'ajax:complete.rails', function(event) {
|
461
|
+
if (this == event.target) rails.enableFormElements($(this));
|
462
|
+
});
|
463
|
+
|
464
|
+
$(function(){
|
465
|
+
rails.refreshCSRFTokens();
|
466
|
+
});
|
467
|
+
}
|
468
|
+
|
469
|
+
})( jQuery );
|