$.ajaxSetup({
cache: false
});
$(function() {
});
$( window ).on( "load", function()
{
// NOTE: Disabled for now. Breaks viewing the source.
// Clears the URL to remove everything off after '?'.
//var newURL = location.href.split("?")[0];
//window.history.pushState('object', document.title, newURL);
// Show the list of unconfigured (and configured) hosts on the main page.
if ($('#unconfigured_hosts').length) {
// Toggle the table with the list of hosts that can be configured.
$("#toggle_unconfigured_icon").click(function(){
$("#unconfigured_hosts").toggle();
});
$("#toggle_unconfigured_text").click(function(){
$("#unconfigured_hosts").toggle();
});
// Walk through the network.json file and use it to pre-fill the form.
setInterval(function() {
$.getJSON('/status/all_status.json', function(data) {
//console.log('read /status/all_status.json');
var show_none = 1;
var say_none = $('#unconfigured_hosts').data('none');
var say_yes = $('#unconfigured_hosts').data('yes');
var say_no = $('#unconfigured_hosts').data('no');
var say_unconfigured = $('#unconfigured_hosts').data('unconfigured');
var say_configured = $('#unconfigured_hosts').data('configured');
var say_type = $('#unconfigured_hosts').data('type');
var say_accessible = $('#unconfigured_hosts').data('accessible');
var say_at_ip = $('#unconfigured_hosts').data('at-ip');
// Open the table
var body = '
';
// clear + append can't be the best way to do this...
$("#unconfigured_hosts").empty();
$("#unconfigured_hosts").append(body);
});
}, 1000);
};
// Run in we're showing a specific hosts' network.
if ($('#network_interface_table').length) {
var host_name = $('#network_interface_table').data('host-name');
var say_title = $('#network_interface_table').data('title');
var say_mac_address = $('#network_interface_table').data('mac-address');
var say_name = $('#network_interface_table').data('name');
var say_state = $('#network_interface_table').data('state');
var say_speed = $('#network_interface_table').data('speed');
var say_up_order = $('#network_interface_table').data('up-order');
var say_up = $('#network_interface_table').data('up');
var say_down = $('#network_interface_table').data('down');
//console.log('showing network info for: ['+host_name+']');
setInterval(function() {
$.getJSON('/status/all_status.json', function(data) {
//console.log('read all_status.json: ['+data+']');
// Build the HTML
var body = '';
body += '';
body += ''+say_title+' | ';
body += '
';
body += '';
body += ''+say_mac_address+' | ';
body += ''+say_name+' | ';
body += ''+say_state+' | ';
body += ''+say_speed+' | ';
body += ''+say_up_order+' | ';
body += '
';
$.each(data.hosts, function(i, host) {
//console.log('This is: ['+host.name+']');
if (host.name != host_name) {
// Skip
return true;
};
//console.log('Found it!');
$.each(host.network_interfaces, function(j, nic) {
// Only real interfaces have a 'changed_order' value.
if (nic.changed_order) {
var say_link_state = say_down;
if (nic.link_state == 1) {
say_link_state = say_up;
}
body += '';
body += ''+nic.mac_address+' | ';
body += ''+nic.name+' | ';
body += ''+say_link_state+' | ';
body += ''+nic.say_speed+' | ';
body += ''+nic.changed_order+' | ';
body += '
';
}
});
});
body += '
';
// clear + append can't be the best way to do this...
$("#network_interface_table").empty();
$("#network_interface_table").append(body);
});
}, 1000);
};
})