Skip to content
Snippets Groups Projects
hosts.js 1005 B
Newer Older
$(document).ready(function() {

  function update_available_ips() {
    // Retrieve available IPs for the selected network
    // and update the IP select field
    var network_id = $("#network_id").val();
    $.getJSON(
      $SCRIPT_ROOT + "/networks/_retrieve_available_ips/" + network_id,
      function(json) {
        var $ip = $("#ip");
        $ip.empty();
        $.map(json.data, function(option, index) {
          $ip.append($("<option></option>").attr("value", option).text(option));
        });
      }
    );
  }

  // Populate IP select field on first page load
  update_available_ips();

  // Update IP select field when changing network
  $("#network_id").on('change', function() {
    update_available_ips();
  });

  var hosts_table =  $("#hosts_table").DataTable({
    "ajax": function(data, callback, settings) {
      $.getJSON(
        $SCRIPT_ROOT + "/networks/_retrieve_hosts",
        function(json) {
          callback(json);
        });
    },
    "paging": false
  });

});