[% SET user_can_port_control = user_has_role('port_control') %]
<table class="table table-condensed table-striped">
  </tbody>
    <tr>
      <td>System Name</td>
      <td>[% d.name %]</td>
    </tr>
    <tr>
      <td>Location
      [% IF user_can_port_control %]
      <i class="icon-edit nd_edit-icon nd_device-details-edit"></i>
      [% END %]
      </td>
      [% IF user_can_port_control %]
      <td class="nd_editable-cell" contenteditable="true"
        data-field="location" data-for-device="[% d.ip %]">
          [% d.location | html_entity %]
      </td>
      [% ELSE %]
      <td>
        <a rel="tooltip" data-placement="top" data-offset="5" data-title="Find Similar Devices"
        href="[% search_device %]&q=[% d.location | uri %]&location=[% d.location | uri %]">[% d.location | html_entity %]</a>
      </td>
      [% END %]
    </tr>
    <tr>
      <td>Contact
      [% IF user_can_port_control %]
      <i class="icon-edit nd_edit-icon nd_device-details-edit"></i>
      [% END %]
      </td>
      [% IF user_can_port_control %]
      <td class="nd_editable-cell" contenteditable="true"
        data-field="contact" data-for-device="[% d.ip | html_entity %]">
          [% d.contact | html_entity %]
      </td>
      [% ELSE %]
      <td>[% d.contact | html_entity %]</td>
      [% END %]
    </tr>
    <tr>
      <td>Vendor / Model</td>
      <td>
        <a rel="tooltip" data-placement="top" data-offset="5" data-title="Find Similar Devices"
        href="[% search_device %]&q=[% d.vendor | uri %]&vendor=[% d.vendor | uri %]">[% d.vendor | html_entity %]</a>
        /
        <a rel="tooltip" data-placement="top" data-offset="5" data-title="Find Similar Devices"
        href="[% search_device %]&q=[% d.model | uri %]&model=[% d.model | uri %]">[% d.model | html_entity %]</a>
      </td>
    </tr>
    <tr>
      <td>OS / Version</td>
      <td>
        <a rel="tooltip" data-placement="top" data-offset="5" data-title="Find Similar Devices"
        href="[% search_device %]&q=[% d.os | uri %]&os=[% d.os | uri %]">[% d.os | html_entity %]</a>
        /
        <a rel="tooltip" data-placement="top" data-offset="5" data-title="Find Similar Devices"
        href="[% search_device %]&q=[% d.os_ver | uri %]&os_ver=[% d.os_ver | uri %]">[% d.os_ver | html_entity %]</a>
      </td>
    </tr>
    <tr>
      <td>Serial Number</td>
      <td>[% d.serial | html_entity %]</td>
    </tr>
    <tr>
      <td>Description</td>
      <td>[% d.description | html_entity | html_line_break %]</td>
    </tr>
    [% IF settings._extra_device_details.size %]
    [% FOREACH config IN settings._extra_device_details %]
    <tr>
      <td>
          [% config.label %]
      </td>
      <td>
          [% TRY %]
          [% INCLUDE "plugin/${config.name}/device_details.tt" %]
          [% CATCH %]
          <!-- dummy content required by Template Toolkit TRY -->
          [% END %]
      </td>
    </tr>
    [% END %]
    [% END %]
    <tr>
      <td>Administration</td>
      <td>
        <a href="ssh://[% d.ip | uri %]" target="_blank">
          <span class="label label-info"><i class="icon-keyboard"></i> SSH</span></a>
        <a href="telnet://[% d.ip | uri %]" target="_blank">
          <span class="label label-info"><i class="icon-keyboard"></i> Telnet</span></a>
        <a href="https://[% d.ip | uri %]/" target="_blank">
          <span class="label label-info"><i class="icon-external-link"></i> Web</span></a>
      </td>
    </tr>
    <tr>
      <td>SNMP Class</td>
      <td><a target="_blank" href="https://metacpan.org/pod/[% d.snmp_class | uri %]">[% d.snmp_class | html_entity %]</td>
    </tr>
    <tr>
      <td>Uptime</td>
      <td>[% d.uptime_age | html_entity %]</td>
    </tr>
    <tr>
      <td>Layers</td>
      <td>
        [% d.layers.substr(7,1) ? '<span class="badge badge-success">1</span>' : '<span class="badge">&nbsp;</span>' %]
        [% d.layers.substr(6,1) ? '<span class="badge badge-success">2</span>' : '<span class="badge">&nbsp;</span>' %]
        [% d.layers.substr(5,1) ? '<span class="badge badge-success">3</span>' : '<span class="badge">&nbsp;</span>' %]
        [% d.layers.substr(4,1) ? '<span class="badge badge-success">4</span>' : '<span class="badge">&nbsp;</span>' %]
        [% d.layers.substr(3,1) ? '<span class="badge badge-success">5</span>' : '<span class="badge">&nbsp;</span>' %]
        [% d.layers.substr(2,1) ? '<span class="badge badge-success">6</span>' : '<span class="badge">&nbsp;</span>' %]
        [% d.layers.substr(1,1) ? '<span class="badge badge-success">7</span>' : '<span class="badge">&nbsp;</span>' %]
      </td>
    </tr>
    <tr>
      <td>Last Discover</td>
      <td>[% d.last_discover_stamp | html_entity %]</td>
    </tr>
    <tr>
      <td>Last Arpnip</td>
      <td>[% d.last_arpnip_stamp | html_entity %]</td>
    </tr>
    <tr>
      <td>Last Macsuck</td>
      <td>[% d.last_macsuck_stamp | html_entity %]</td>
    </tr>
    <tr>
      <td>Hardware Status</td>
      <td>Fan: [% d.fan | html_entity %]
        <br/>PS1 [[% d.ps1_type | html_entity %]]: [% d.ps1_status | html_entity %]
        <br/>PS2 [[% d.ps2_type | html_entity %]]: [% d.ps2_status | html_entity %]</td>
    </tr>
    [% IF p.size %]
    <tr>
      <td>PoE Status</td>
      <td>
      [% FOREACH m IN p %]
        [% UNLESS m.module == 1 %]
          <br/>
        [% END %]
        Module [% m.module %]: [% m.status | html_entity %], [% m.poe_capable_ports %] power-capable ports, [% m.poe_powered_ports %] powered ([% m.poe_disabled_ports %] admin disabled, [% m.poe_errored_ports %] errors), [% m.poe_power_committed %]/[% m.power %] watts committed.
      [% END %]
      </td>
    </tr>
    [% END %]
    <tr>
      <td>MAC Address</td>
      <td>[% d.mac | html_entity %]</td>
    </tr>
    <tr>
      <td>VTP Domain</td>
      <td>[% d.vtp_domain | html_entity %]</td>
    </tr>
    [% IF user_has_role('admin') %]
    <tr data-for-device="[% d.ip %]">
      <td>Admin Tasks</td>
      <td>
        <input type="hidden" data-form="discover" value="[% d.ip %]" name="device"/>
        <button class="btn btn-info btn-small nd_adminbutton" name="discover">Discover</button>
        <input type="hidden" data-form="arpnip" value="[% d.ip %]" name="device"/>
        <button class="btn btn-info btn-small nd_adminbutton" name="arpnip">Arpnip</button>
        <input type="hidden" data-form="macsuck" value="[% d.ip %]" name="device"/>
        <button class="btn btn-info btn-small nd_adminbutton" name="macsuck">Macsuck</button>
        <input type="hidden" data-form="nbtstat" value="[% d.ip %]" name="device"/>
        <button class="btn btn-info btn-small nd_adminbutton" name="nbtstat">NBTstat</button>

        <button class="btn btn-danger btn-small pull-right"
          data-toggle="modal" data-target="#nd_devdel" type="button">Delete</button>

        <div id="nd_devdel" class="nd_modal nd_deep-horizon modal hide fade" tabindex="-1"
          role="dialog" aria-labelledby="nd_devdel-label" aria-hidden="true">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
            <h3 id="nd_devdel-label">Confirm Delete: [% d.dns || d.ip | html_entity %]</h3>
          </div>
          <div class="modal-body">
            <blockquote>
              <ul>
                <li><p>This action is immediate and not reversible</p></li>
                <li><p>All associated Nodes may be removed from the database</p></li>
              </ul>
            </blockquote>
            <textarea id="nd_devdel-log" class="input-block-level" rows="2" data-form="delete"
              placeholder="Enter a log message" name="log"></textarea>
            <label class="checkbox">
              <input id="nd_devdel-archive" type="checkbox" data-form="delete" name="archive">
              <h4 class="nd_unbolden">Archive Nodes</h4>
            </label>
            <input type="hidden" data-form="delete" value="[% d.ip %]" name="device"/>
          </div>
          <div class="modal-footer">
            <button class="btn btn-success" data-dismiss="modal" aria-hidden="true">Cancel</button>
            <button class="btn btn-danger nd_adminbutton" name="delete" data-dismiss="modal">Confirm</button>
          </div>
        </div>
      </td>
    </tr>
    [% END %]
  </tbody>
</table>
