JS: more robust error handling

Also, the upload form cannot be resent during processing
This commit is contained in:
Marcin Kurczewski 2013-11-23 09:51:57 +01:00
parent 618f9e3d77
commit 7fccbd5e02
4 changed files with 32 additions and 6 deletions

View file

@ -36,12 +36,15 @@ $(function()
aDom.addClass('inactive');
var url = $(this).attr('href') + '?json';
$.get(url, function(data)
$.get(url).always(function(data)
{
if (data['success'])
window.location.reload();
else
alert(data['message']);
{
alert(data['message'] ? data['message'] : 'Fatal error');
aDom.removeClass('inactive');
}
});
});
});
@ -78,7 +81,7 @@ $(function()
aDom.addClass('inactive');
var url = $(this).attr('href') + '?json';
$.get(url, {submit: 1}, function(data)
$.get(url, {submit: 1}).always(function(data)
{
if (data['success'])
{
@ -91,7 +94,7 @@ $(function()
}
else
{
alert(data['message']);
alert(data['message'] ? data['message'] : 'Fatal error');
aDom.removeClass('inactive');
}
});

View file

@ -16,7 +16,7 @@ $(function()
aDom.addClass('inactive');
var url = $(this).attr('href') + '?json';
$.get(url, {submit: 1}, function(data)
$.get(url, {submit: 1}).always(function(data)
{
if (data['success'])
{
@ -28,7 +28,7 @@ $(function()
}
else
{
alert(data['message']);
alert(data['message'] ? data['message'] : 'Fatal error');
aDom.removeClass('inactive');
}
});

View file

@ -87,6 +87,12 @@ $(function()
formDom.find(':input').attr('readonly', false);
formDom.removeClass('inactive');
}
},
error: function()
{
alert('Fatal error');
formDom.find(':input').attr('readonly', false);
formDom.removeClass('inactive');
}
};
@ -147,6 +153,12 @@ $(function()
formDom.find(':input').attr('readonly', false);
formDom.removeClass('inactive');
}
},
error: function()
{
alert('Fatal error');
formDom.find(':input').attr('readonly', false);
formDom.removeClass('inactive');
}
};

View file

@ -60,6 +60,8 @@ $(function()
$('.post .move-down-trigger, .post .move-up-trigger').on('click', function()
{
if ($('#the-submit').hasClass('inactive'))
return;
var dir = $(this).hasClass('move-down-trigger') ? 'd' : 'u';
var post = $(this).parents('.post');
if (dir == 'u')
@ -69,6 +71,8 @@ $(function()
});
$('.post .remove-trigger').on('click', function()
{
if ($('#the-submit').hasClass('inactive'))
return;
$(this).parents('.post').slideUp(function()
{
$(this).remove();
@ -119,6 +123,11 @@ $(function()
postDom.find('.alert').html(data['messageHtml']).slideDown();
enableUpload();
}
},
error: function(data)
{
postDom.find('.alert').html('Fatal error').slideDown();
enableUpload();
}
};
@ -152,6 +161,8 @@ $(function()
{
e.preventDefault();
var theSubmit = $(this);
if (theSubmit.hasClass('inactive'))
return;
disableUpload();
sendNextPost();
});