[% USE url %]
[% IF opt %]
  <table id="data-table" class="table table-striped table-bordered" width="100%" cellspacing="0">
    <thead>
      <tr>
        <th>Domain</th>
        <th>Node</th>
        <th>Name</th>
        <th>User</th>
        <th>First Seen</th>
        <th>Last Seen</th>
      </tr>
    </thead>
  </table>
[% ELSE %]
  <table id="data-table" class="table table-striped table-bordered" width="100%" cellspacing="0">
    <thead>
      <tr>
        <th>Domain</th>
        <th>Count</th>
      </tr>
    </thead>
  </table>
[% END %]

<script type="text/javascript">
$(document).ready(function() {
  var table = $('#data-table').dataTable({
    [% IF opt %]
    "serverSide": true,
    "order": [[ 0, "desc" ]],
    "ajax": "[% uri_for('/ajax/content/report/netbios/data') %]?[% url(params('query').hash) %]",
    "columns": [
      {
        "data": 'domain',
        "render": function(data, type, row, meta) {
          return he.encode(data || '(Blank Domain)');
        }
      }, {
        "data": 'mac',
        "render": function(data, type, row, meta) {
          return '<a href="[% search_node %]&q=' + encodeURIComponent(data) + '">' + he.encode(data.toUpperCase()) + '</a>';
        }
      }, {
        "data": 'nbname',
        "render": function(data, type, row, meta) {
          var prefix = '';
          if (row.domain) {
            prefix = '\\\\' + row.domain + '\\';
          }
          return he.encode(prefix) + '<a href="[% search_node %]&q=' + encodeURIComponent(data) + '">' + he.encode(data) + '</a>';
        }
      }, {
        "data": 'nbuser',
        "render": function(data, type, row, meta) {
          return he.encode(row.nbuser || '[No User]');
        }
      }, {
        "data": 'time_first',
        "render": function(data, type, row, meta) {
          return moment(data).format('YYYY-MM-DD HH:mm');
        }
      }, {
        "data": 'time_last',
        "render": function(data, type, row, meta) {
          return moment(data).format('YYYY-MM-DD HH:mm');
        }
      }
    ],
    "order": [[0, "asc"], [5, "desc"]],
    [% ELSE %]
    "deferRender": true,
    "data": [% results %],
    "columns": [    
      {
        "data": 'domain',
        "render": function(data, type, row, meta) {
          return '<a href="[% uri_for('/report/netbios') %]?domain=' + encodeURIComponent(data || 'blank') + '">' + he.encode(data || '(Blank Domain)') + '</a>';
        }
      }, {
        "data": 'count',
        "render": function(data, type, row, meta) {
          return data.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
        }
      }
    ],
    "order": [[1, "desc"]],
    [% END %]
[% INCLUDE 'ajax/datatabledefaults.tt' -%]
  });
});
</script>

