Git-Center/js/app.js

40 lines
1.3 KiB
JavaScript
Raw Normal View History

2013-10-16 21:10:51 +00:00
"use strict";
2013-10-02 10:21:30 +00:00
window.addEventListener('load', function() {
var sections = document.querySelectorAll('section');
for (var i = 0; i < sections.length; i++) {
2013-10-02 14:33:16 +00:00
callRequest('status', sections[i].id);
2013-10-02 10:21:30 +00:00
}
});
2013-10-02 14:33:16 +00:00
function callRequest(action, section, message) {
2013-10-02 10:21:30 +00:00
var pre = document.querySelector('#' + section + ' pre');
pre.innerHTML = '<span class="loading">Loading ...</span>';
2013-10-02 14:33:16 +00:00
var label = document.querySelector('#' + section + ' .label');
label.classList.remove('label-success');
label.classList.remove('label-important');
label.classList.add('label-warning');
label.innerHTML = 'Loading';
2013-10-02 10:21:30 +00:00
var xhr = new XMLHttpRequest();
xhr.open('POST', 'ajax.php');
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
2013-10-02 14:33:16 +00:00
xhr.send('action=' + action + '&section=' + section + '&message=' + message);
2013-10-02 10:21:30 +00:00
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && (xhr.status === 200 || xhr.status === 0)) {
2013-10-02 12:47:25 +00:00
pre.innerHTML = xhr.responseText;
2013-10-02 14:33:16 +00:00
var splitLabel = xhr.responseText.split("\n").reverse();
label.classList.remove('label-warning');
if (splitLabel[1] !== 'nothing to commit (working directory clean)') {
label.classList.add('label-important');
label.innerHTML = 'Update needed';
} else {
label.classList.add('label-success');
label.innerHTML = 'OK';
}
2013-10-02 10:21:30 +00:00
}
};
}