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>
|
<script>
|
||||||
var refreshProjectData = function()
|
var refreshProjectData = function()
|
||||||
{
|
{
|
||||||
$('#latest-builds').load('<?php echo PHPCI_URL ?>home/latest', function () {
|
$.ajax({
|
||||||
$('#latest-builds').trigger('latest-builds:reload');
|
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 () {
|
$.ajax({
|
||||||
$('#project-overview').trigger('project-overview:reload');
|
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>
|
<script>
|
||||||
setInterval(function()
|
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);
|
}, 10000);
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
|
@ -47,7 +47,7 @@ function confirmDelete(url, subject, reloadAfter) {
|
||||||
*/
|
*/
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: url,
|
url: url,
|
||||||
'success': function (data) {
|
success: function (data) {
|
||||||
if (reloadAfter) {
|
if (reloadAfter) {
|
||||||
dialog.onClose = function () {
|
dialog.onClose = function () {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
|
@ -56,8 +56,12 @@ function confirmDelete(url, subject, reloadAfter) {
|
||||||
|
|
||||||
dialog.showStatusMessage('Successfully deleted!', 1000);
|
dialog.showStatusMessage('Successfully deleted!', 1000);
|
||||||
},
|
},
|
||||||
'error': function (data) {
|
error: function (data) {
|
||||||
dialog.showStatusMessage('Deletion failed! Server says "' + data.statusText + '"');
|
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') {
|
if ($(this).val() == 'github') {
|
||||||
$('#loading').show();
|
$('#loading').show();
|
||||||
|
|
||||||
$.getJSON(window.PHPCI_URL + 'project/github-repositories', function (data) {
|
$.ajax({
|
||||||
$('#loading').hide();
|
dataType: "json",
|
||||||
|
url: window.PHPCI_URL + 'project/github-repositories',
|
||||||
|
success: function (data) {
|
||||||
|
$('#loading').hide();
|
||||||
|
|
||||||
if (data.repos) {
|
if (data.repos) {
|
||||||
$('#element-github').empty();
|
$('#element-github').empty();
|
||||||
|
|
||||||
for (var i in data.repos) {
|
for (var i in data.repos) {
|
||||||
var name = data.repos[i];
|
var name = data.repos[i];
|
||||||
$('#element-github').append($('<option></option>').text(name).val(name));
|
$('#element-github').append($('<option></option>').text(name).val(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
$('.github-container').slideDown();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
$('.github-container').slideDown();
|
error: handleFailedAjax
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$('.github-container').slideUp();
|
$('.github-container').slideUp();
|
||||||
|
@ -342,8 +350,14 @@ var PHPCIObject = Class.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
var cb = function() {
|
var cb = function() {
|
||||||
$.getJSON(window.PHPCI_URL + uri, query, function(data) {
|
$.ajax({
|
||||||
$(window).trigger({type: name, queryData: data});
|
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