* fix: eslint operator-linebreak issue * fix: eslint quotes issue * fix: react jsx indent and props issues * fix: eslint trailing spaces issues * fix: eslint line around directives issue * fix: eslint semi rule * fix: eslint newline per chain rule * fix: eslint space infix ops rule * fix: eslint space-in-parens issue * fix: eslint space before function paren issue * fix: eslint space before blocks issue * fix: eslint arrow body style issue * fix: eslint dot-location issue * fix: eslint quotes issue * fix: eslint quote props issue * fix: eslint operator assignment issue * fix: eslint new line after import issue * fix: indent issues * fix: operator assignment issue * fix: all autofixable eslint issues * fix: all react related fixable issues * fix: autofixable eslint issues * chore: remove all template literals * fix: remaining autofixable issues * chore: apply amnesty on all existing issues * fix: failing xss-lint issues * refactor: apply amnesty on remaining issues * refactor: apply amnesty on new issues * fix: remove file level suppressions * refactor: apply amnesty on new issues
47 lines
1.7 KiB
JavaScript
47 lines
1.7 KiB
JavaScript
// eslint-disable-next-line no-shadow-restricted-names
|
|
(function($, undefined) {
|
|
var form_ext;
|
|
// eslint-disable-next-line no-multi-assign
|
|
$.form_ext = form_ext = {
|
|
ajax: function(options) {
|
|
return $.ajax(options);
|
|
},
|
|
handleRemote: function(element) {
|
|
var method = element.attr('method');
|
|
var url = element.attr('action');
|
|
var data = element.serializeArray();
|
|
var options = {
|
|
type: method || 'GET',
|
|
data: data,
|
|
dataType: 'text json',
|
|
// eslint-disable-next-line no-shadow
|
|
success: function(data, status, xhr) {
|
|
element.trigger('ajax:success', [data, status, xhr]);
|
|
},
|
|
complete: function(xhr, status) {
|
|
element.trigger('ajax:complete', [xhr, status]);
|
|
},
|
|
error: function(xhr, status, error) {
|
|
element.trigger('ajax:error', [xhr, status, error]);
|
|
}
|
|
};
|
|
if (url) { options.url = url; }
|
|
return form_ext.ajax(options);
|
|
},
|
|
CSRFProtection: function(xhr) {
|
|
var token = $.cookie('csrftoken');
|
|
if (token) { xhr.setRequestHeader('X-CSRFToken', token); }
|
|
}
|
|
};
|
|
$.ajaxPrefilter(function(options, originalOptions, xhr) { if (!options.crossDomain) { form_ext.CSRFProtection(xhr); } });
|
|
$(document).delegate('form', 'submit', function(e) {
|
|
var $form = $(this),
|
|
remote = $form.data('remote') !== undefined;
|
|
|
|
if (remote) {
|
|
form_ext.handleRemote($form);
|
|
return false;
|
|
}
|
|
});
|
|
}(jQuery));
|