Newer
Older
function set_default_ip() {
// Retrieve the first available IP for the selected network
// and update the IP field
var network_id = $("#network_id").val();
$.getJSON(
$SCRIPT_ROOT + "/network/_retrieve_first_available_ip/" + network_id,
$("#ip").val(json.data);
// If random_mac is checked, generate a random address
// Empty the field otherwise
function fill_mac_address() {
if( $("#random_mac").prop("checked") ) {
$.getJSON(
$SCRIPT_ROOT + "/network/_generate_random_mac",
function(json) {
$("#mac_address").val(json.data.mac);
$("#mac_address").prop("readonly", true);
}
);
} else {
$("#mac_address").val("");
$("#mac_address").prop("readonly", false);
}
}
// Set the default IP on first page load for:
// - register new host
// - add interface
// Do NOT replace the IP on edit interface page load!
// (we have to keep the existing IP)
if( $("#hostForm").length || $("#interfaceForm").length ) {
// Set the default IP when changing network
$("#network_id").on('change', function() {
// Enable / disable item_id field depending on type
// Item can only be assigned for physical hosts
// And check / uncheck random_mac checkbox
$("#type").on('change', function() {
var host_type = $(this).val();
if( host_type == "Physical" ) {
$("#item_id").prop("disabled", false);
$("#random_mac").prop("checked", false).change();
} else {
$("#item_id").val("");
$("#item_id").prop("disabled", true);
$("#random_mac").prop("checked", true).change();
}
});
// Prefill interface name with hostname
$("#name").keyup(function(event) {
var hostname = $(this).val();
$("#interface_name").val(hostname);
});
// Fill MAC address on page load
if( $("#random_mac").length ) {
fill_mac_address();
}
// Fill or clear MAC address depending on random_mac checkbox
$("#random_mac").on('change', function() {
fill_mac_address();
});
// Force the first interface to have the hostname as name
// This only applies to the hostForm (not when editing or adding interfaces)
$("#hostForm input[name=interface_name]").prop("readonly", true);
var hosts_table = $("#hosts_table").DataTable({
"ajax": function(data, callback, settings) {
$.getJSON(
$SCRIPT_ROOT + "/network/_retrieve_hosts",
function(json) {
callback(json);
});
},
"pagingType": "full_numbers",
"pageLength": 20,
"lengthMenu": [[20, 50, 100, -1], [20, 50, 100, "All"]],
"columnDefs": [
{
"targets": [0],
"render": function(data, type, row) {
// render funtion to create link to Item view page
if ( data === null ) {
return data;
}
var url = $SCRIPT_ROOT + "/network/hosts/view/" + data;
return '<a href="'+ url + '">' + data + '</a>';
}
}
]