handle ajax errors (closes foodcoops#300)
This commit is contained in:
parent
fa725dbf38
commit
d8f4ac47dd
2 changed files with 10 additions and 12 deletions
|
@ -116,18 +116,15 @@ $(function() {
|
|||
return false;
|
||||
});
|
||||
|
||||
// Show and hide loader on ajax callbacks
|
||||
$('*[data-remote]').bind('ajax:beforeSend', function() {
|
||||
$('#loader').show();
|
||||
});
|
||||
|
||||
$('*[data-remote]').bind('ajax:complete', function() {
|
||||
$('#loader').hide();
|
||||
});
|
||||
|
||||
// Disable submit button on ajax forms
|
||||
$('form[data-remote]').bind('ajax:beforeSend', function() {
|
||||
$(this).children('input[type="submit"]').attr('disabled', 'disabled');
|
||||
// Handle ajax errors
|
||||
// render json: {error: "can't except this!"}, status: :unprocessable_entity
|
||||
$(document).ajaxError(function(ev, xhr, settings, exception) {
|
||||
try {
|
||||
msg = xhr.responseJSON.error;
|
||||
} catch(err) {
|
||||
msg = I18n.t('errors.general');
|
||||
}
|
||||
alert(msg);
|
||||
});
|
||||
|
||||
// The autocomplete attribute is used for both autocompletion and storing
|
||||
|
|
|
@ -3,6 +3,7 @@ translations:
|
|||
- file: 'app/assets/javascripts/i18n/translations.js'
|
||||
only: [
|
||||
'*.js.*',
|
||||
'*.errors.*',
|
||||
'*.number.*',
|
||||
'*.date.formats.*',
|
||||
# foodsoft-specific texts to keep js with normal translations
|
||||
|
|
Loading…
Reference in a new issue