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; return false;
}); });
// Show and hide loader on ajax callbacks // Handle ajax errors
$('*[data-remote]').bind('ajax:beforeSend', function() { // render json: {error: "can't except this!"}, status: :unprocessable_entity
$('#loader').show(); $(document).ajaxError(function(ev, xhr, settings, exception) {
}); try {
msg = xhr.responseJSON.error;
$('*[data-remote]').bind('ajax:complete', function() { } catch(err) {
$('#loader').hide(); msg = I18n.t('errors.general');
}); }
alert(msg);
// Disable submit button on ajax forms
$('form[data-remote]').bind('ajax:beforeSend', function() {
$(this).children('input[type="submit"]').attr('disabled', 'disabled');
}); });
// The autocomplete attribute is used for both autocompletion and storing // The autocomplete attribute is used for both autocompletion and storing

View file

@ -3,6 +3,7 @@ translations:
- file: 'app/assets/javascripts/i18n/translations.js' - file: 'app/assets/javascripts/i18n/translations.js'
only: [ only: [
'*.js.*', '*.js.*',
'*.errors.*',
'*.number.*', '*.number.*',
'*.date.formats.*', '*.date.formats.*',
# foodsoft-specific texts to keep js with normal translations # foodsoft-specific texts to keep js with normal translations