/*
 * Poller for the naclys script 
 *
 *
 *
 */

var status_hdlr = new XMLHttpRequest ();

var fetch_status = function () 
{
    var running_elt = document.getElementById('queues_status');
    var presence_elt = document.getElementById('presence_status');
 
    try 
	{
	    status_hdlr.open("GET", "/monitor", false);
	    status_hdlr.send(null);
	    
	    var status = eval ('(' + status_hdlr.responseText + ')'); 
	    
	    if (status.qsr > 0)
		running_elt.innerHTML = "There are " + status.qsr + " jobs running, the maximum number allowed is " + status.qsr_m + ".";
	    else 
	    running_elt.innerHTML = "There is no job running, the maximum number allowed is " + status.qsr_m + ".";
	    
	    presence_elt.innerHTML = "There are " + status.presence + " cores in the grid."; 
	    return ;
	}
    catch (e) { 
	running_elt.innerHTML = "Can't connect to the backoffice.";
	presence_elt.innerHTML = "Can't connect to the backoffice.";
	return; 
    }
	        
};

fetch_status (); 
