function show_instances() {
$.get("/api/v1/instances", function(data) {
$("#main_content").html("
List of Spectrum 2 instances
Name | Status | Actions |
");
var admin = $.cookie("admin") == "1";
$.each(data.instances, function(i, instance) {
if (instance.running) {
if (admin) {
var command = instance.running ? "stop" : "start";
}
else {
var command = instance.registered ? "unregister" : "register";
if (instance.registered) {
instance.status += "
Registered as " + instance.username;
}
}
}
else if (admin) {
var command = "start";
}
var row = ''+ instance.name + ' | ' +
'' + instance.status + ' | ' +
'' + command + '' + ' |
';
$("#main_result > tbody:last-child").append(row);
$(".button_command").click(function(e) {
e.preventDefault();
$(this).parent().empty().progressbar( {value: false} ).css('height', '1em');
var url = $(this).attr('href');
$.get(url, function(data) {
show_instances();
});
})
});
});
}