handle ajax errors (closes foodcoops#300)

This commit is contained in:
wvengen 2014-07-02 13:55:05 +02:00
parent fa725dbf38
commit d8f4ac47dd
2 changed files with 10 additions and 12 deletions

View file

@ -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

View file

@ -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