JS: more robust error handling
Also, the upload form cannot be resent during processing
This commit is contained in:
parent
618f9e3d77
commit
7fccbd5e02
4 changed files with 32 additions and 6 deletions
|
@ -36,12 +36,15 @@ $(function()
|
||||||
aDom.addClass('inactive');
|
aDom.addClass('inactive');
|
||||||
|
|
||||||
var url = $(this).attr('href') + '?json';
|
var url = $(this).attr('href') + '?json';
|
||||||
$.get(url, function(data)
|
$.get(url).always(function(data)
|
||||||
{
|
{
|
||||||
if (data['success'])
|
if (data['success'])
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
else
|
else
|
||||||
alert(data['message']);
|
{
|
||||||
|
alert(data['message'] ? data['message'] : 'Fatal error');
|
||||||
|
aDom.removeClass('inactive');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -78,7 +81,7 @@ $(function()
|
||||||
aDom.addClass('inactive');
|
aDom.addClass('inactive');
|
||||||
|
|
||||||
var url = $(this).attr('href') + '?json';
|
var url = $(this).attr('href') + '?json';
|
||||||
$.get(url, {submit: 1}, function(data)
|
$.get(url, {submit: 1}).always(function(data)
|
||||||
{
|
{
|
||||||
if (data['success'])
|
if (data['success'])
|
||||||
{
|
{
|
||||||
|
@ -91,7 +94,7 @@ $(function()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
alert(data['message']);
|
alert(data['message'] ? data['message'] : 'Fatal error');
|
||||||
aDom.removeClass('inactive');
|
aDom.removeClass('inactive');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,7 +16,7 @@ $(function()
|
||||||
aDom.addClass('inactive');
|
aDom.addClass('inactive');
|
||||||
|
|
||||||
var url = $(this).attr('href') + '?json';
|
var url = $(this).attr('href') + '?json';
|
||||||
$.get(url, {submit: 1}, function(data)
|
$.get(url, {submit: 1}).always(function(data)
|
||||||
{
|
{
|
||||||
if (data['success'])
|
if (data['success'])
|
||||||
{
|
{
|
||||||
|
@ -28,7 +28,7 @@ $(function()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
alert(data['message']);
|
alert(data['message'] ? data['message'] : 'Fatal error');
|
||||||
aDom.removeClass('inactive');
|
aDom.removeClass('inactive');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -87,6 +87,12 @@ $(function()
|
||||||
formDom.find(':input').attr('readonly', false);
|
formDom.find(':input').attr('readonly', false);
|
||||||
formDom.removeClass('inactive');
|
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.find(':input').attr('readonly', false);
|
||||||
formDom.removeClass('inactive');
|
formDom.removeClass('inactive');
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
error: function()
|
||||||
|
{
|
||||||
|
alert('Fatal error');
|
||||||
|
formDom.find(':input').attr('readonly', false);
|
||||||
|
formDom.removeClass('inactive');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,8 @@ $(function()
|
||||||
|
|
||||||
$('.post .move-down-trigger, .post .move-up-trigger').on('click', 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 dir = $(this).hasClass('move-down-trigger') ? 'd' : 'u';
|
||||||
var post = $(this).parents('.post');
|
var post = $(this).parents('.post');
|
||||||
if (dir == 'u')
|
if (dir == 'u')
|
||||||
|
@ -69,6 +71,8 @@ $(function()
|
||||||
});
|
});
|
||||||
$('.post .remove-trigger').on('click', function()
|
$('.post .remove-trigger').on('click', function()
|
||||||
{
|
{
|
||||||
|
if ($('#the-submit').hasClass('inactive'))
|
||||||
|
return;
|
||||||
$(this).parents('.post').slideUp(function()
|
$(this).parents('.post').slideUp(function()
|
||||||
{
|
{
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
|
@ -119,6 +123,11 @@ $(function()
|
||||||
postDom.find('.alert').html(data['messageHtml']).slideDown();
|
postDom.find('.alert').html(data['messageHtml']).slideDown();
|
||||||
enableUpload();
|
enableUpload();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
error: function(data)
|
||||||
|
{
|
||||||
|
postDom.find('.alert').html('Fatal error').slideDown();
|
||||||
|
enableUpload();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -152,6 +161,8 @@ $(function()
|
||||||
{
|
{
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var theSubmit = $(this);
|
var theSubmit = $(this);
|
||||||
|
if (theSubmit.hasClass('inactive'))
|
||||||
|
return;
|
||||||
disableUpload();
|
disableUpload();
|
||||||
sendNextPost();
|
sendNextPost();
|
||||||
});
|
});
|
||||||
|
|
Reference in a new issue