Adding handling of HTTP 401 status codes in Ajax requests. Fixes #504
This commit is contained in:
parent
69ea614d78
commit
c6529b6832
|
@ -66,12 +66,26 @@
|
|||
<script>
|
||||
var refreshProjectData = function()
|
||||
{
|
||||
$('#latest-builds').load('<?php echo PHPCI_URL ?>home/latest', function () {
|
||||
$('#latest-builds').trigger('latest-builds:reload');
|
||||
$.ajax({
|
||||
url: '<?php echo PHPCI_URL ?>home/latest',
|
||||
|
||||
success: function (data) {
|
||||
$('#latest-builds').html(data);
|
||||
$('#latest-builds').trigger('latest-builds:reload');
|
||||
},
|
||||
|
||||
error: handleFailedAjax
|
||||
});
|
||||
|
||||
$('#project-overview').load('<?php echo PHPCI_URL ?>home/summary', function () {
|
||||
$('#project-overview').trigger('project-overview:reload');
|
||||
$.ajax({
|
||||
url: '<?php echo PHPCI_URL ?>home/summary',
|
||||
|
||||
success: function (data) {
|
||||
$('#project-overview').html(data);
|
||||
$('#project-overview').trigger('project-overview:reload');
|
||||
},
|
||||
|
||||
error: handleFailedAjax
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -114,7 +114,16 @@
|
|||
<script>
|
||||
setInterval(function()
|
||||
{
|
||||
$('#latest-builds').load('<?php echo PHPCI_URL ?>project/builds/<?php print $project->getId(); ?>');
|
||||
$.ajax({
|
||||
url: '<?php echo PHPCI_URL ?>project/builds/<?php print $project->getId(); ?>',
|
||||
|
||||
success: function (data) {
|
||||
$('#latest-builds').html(data);
|
||||
$('#latest-builds').trigger('latest-builds:reload');
|
||||
},
|
||||
|
||||
error: handleFailedAjax
|
||||
});
|
||||
}, 10000);
|
||||
|
||||
$(function() {
|
||||
|
|
|
@ -47,7 +47,7 @@ function confirmDelete(url, subject, reloadAfter) {
|
|||
*/
|
||||
$.ajax({
|
||||
url: url,
|
||||
'success': function (data) {
|
||||
success: function (data) {
|
||||
if (reloadAfter) {
|
||||
dialog.onClose = function () {
|
||||
window.location.reload();
|
||||
|
@ -56,8 +56,12 @@ function confirmDelete(url, subject, reloadAfter) {
|
|||
|
||||
dialog.showStatusMessage('Successfully deleted!', 1000);
|
||||
},
|
||||
'error': function (data) {
|
||||
error: function (data) {
|
||||
dialog.showStatusMessage('Deletion failed! Server says "' + data.statusText + '"');
|
||||
|
||||
if (data.status == 401) {
|
||||
handleFailedAjax(data);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -258,24 +262,28 @@ function setupProjectForm()
|
|||
}
|
||||
});
|
||||
|
||||
$('#element-type').change(function()
|
||||
{
|
||||
$('#element-type').change(function() {
|
||||
if ($(this).val() == 'github') {
|
||||
$('#loading').show();
|
||||
|
||||
$.getJSON(window.PHPCI_URL + 'project/github-repositories', function (data) {
|
||||
$('#loading').hide();
|
||||
$.ajax({
|
||||
dataType: "json",
|
||||
url: window.PHPCI_URL + 'project/github-repositories',
|
||||
success: function (data) {
|
||||
$('#loading').hide();
|
||||
|
||||
if (data.repos) {
|
||||
$('#element-github').empty();
|
||||
if (data.repos) {
|
||||
$('#element-github').empty();
|
||||
|
||||
for (var i in data.repos) {
|
||||
var name = data.repos[i];
|
||||
$('#element-github').append($('<option></option>').text(name).val(name));
|
||||
for (var i in data.repos) {
|
||||
var name = data.repos[i];
|
||||
$('#element-github').append($('<option></option>').text(name).val(name));
|
||||
}
|
||||
|
||||
$('.github-container').slideDown();
|
||||
}
|
||||
|
||||
$('.github-container').slideDown();
|
||||
}
|
||||
},
|
||||
error: handleFailedAjax
|
||||
});
|
||||
} else {
|
||||
$('.github-container').slideUp();
|
||||
|
@ -342,8 +350,14 @@ var PHPCIObject = Class.extend({
|
|||
}
|
||||
|
||||
var cb = function() {
|
||||
$.getJSON(window.PHPCI_URL + uri, query, function(data) {
|
||||
$(window).trigger({type: name, queryData: data});
|
||||
$.ajax({
|
||||
dataType: "json",
|
||||
url: window.PHPCI_URL + uri,
|
||||
data: query,
|
||||
success: function(data) {
|
||||
$(window).trigger({type: name, queryData: data});
|
||||
},
|
||||
error: handleFailedAjax
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -454,3 +468,11 @@ var PHPCIObject = Class.extend({
|
|||
}
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
function handleFailedAjax(xhr)
|
||||
{
|
||||
if (xhr.status == 401) {
|
||||
window.location.href = window.PHPCI_URL + 'session/login';
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue