$(document).ready(function(){ // setup a function to grab the assignments function getNodesAndAssignments() { $.getJSON("nodes.json", function(json){ nodesTableBody = ""; $.each(json.nodes, function (uuid, data) { nodesTableBody += ""; nodesTableBody += "" + data.type + ""; nodesTableBody += "" + uuid + ""; nodesTableBody += "" + (data.pool ? data.pool : "") + ""; nodesTableBody += "" + data.public.ip + ":" + data.public.port + ""; nodesTableBody += "" + data.local.ip + ":" + data.local.port + ""; nodesTableBody += ""; nodesTableBody += ""; }); $('#nodes-table tbody').html(nodesTableBody); }); $.getJSON("assignments.json", function(json){ queuedTableBody = ""; $.each(json.queued, function (uuid, data) { queuedTableBody += ""; queuedTableBody += "" + uuid + ""; queuedTableBody += "" + data.type + ""; queuedTableBody += "" + (data.pool ? data.pool : "") + ""; queuedTableBody += ""; }); $('#assignments-table tbody').html(queuedTableBody); }); } // do the first GET on page load getNodesAndAssignments(); // grab the new assignments JSON every two seconds var getNodesAndAssignmentsInterval = setInterval(getNodesAndAssignments, 2000); // hook the node delete to the X button $(document.body).on('click', '.glyphicon-remove', function(){ // fire off a delete for this node $.ajax({ url: "/node/" + $(this).data('uuid'), type: 'DELETE', success: function(result) { console.log("Succesful request to delete node."); } }); }); });