{% load helpers %}
<tr class="frontport{% if frontport.cable %} {{ frontport.cable.get_status_class }}{% endif %}">

    {# Checkbox #}
    {% if perms.dcim.change_frontport or perms.dcim.delete_frontport %}
        <td class="pk">
            <input name="pk" type="checkbox" value="{{ frontport.pk }}" />
        </td>
    {% endif %}

    {# Name #}
    <td>
        <i class="fa fa-fw fa-square{% if not frontport.cable %}-o{% endif %}"></i> {{ frontport }}
    </td>

    {# Type #}
    <td>{{ frontport.get_type_display }}</td>

    {# Rear port #}
    <td>{{ frontport.rear_port }}</td>
    <td>{{ frontport.rear_port_position }}</td>

    {# Description #}
    <td>{{ frontport.description|placeholder }}</td>

    {# Cable/connection #}
    {% if frontport.cable %}
        <td>
            <a href="{{ frontport.cable.get_absolute_url }}">{{ frontport.cable }}</a>
            <a href="{% url 'dcim:frontport_trace' pk=frontport.pk %}" class="btn btn-primary btn-xs" title="Trace">
                <i class="fa fa-share-alt" aria-hidden="true"></i>
            </a>
        </td>
        {% with far_end=frontport.get_cable_peer %}
            <td>
                {% if far_end.parent.provider %}
                    <i class="fa fa-fw fa-globe" title="Circuit"></i>
                    <a href="{{ far_end.parent.get_absolute_url }}">
                        {{ far_end.parent.provider }}
                        {{ far_end.parent }}
                    </a>
                {% else %}
                    <a href="{{ far_end.parent.get_absolute_url }}">
                        {{ far_end.parent }}
                    </a>
                {% endif %}
            </td>
            <td>{{ far_end }}</td>
        {% endwith %}
    {% else %}
        <td colspan="3">
            <span class="text-muted">Not connected</span>
        </td>
    {% endif %}

    {# Actions #}
    <td class="text-right noprint">
        {% if frontport.cable %}
            {% include 'dcim/inc/cable_toggle_buttons.html' with cable=frontport.cable %}
        {% elif perms.dcim.add_cable %}
            <span class="dropdown">
                <button type="button" class="btn btn-success btn-xs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    <span class="glyphicon glyphicon-resize-small" aria-hidden="true"></span>
                </button>
                <ul class="dropdown-menu dropdown-menu-right">
                    <li><a href="{% url 'dcim:frontport_connect' termination_a_id=frontport.pk termination_b_type='interface' %}?return_url={{ device.get_absolute_url }}">Interface</a></li>
                    <li><a href="{% url 'dcim:frontport_connect' termination_a_id=frontport.pk termination_b_type='console-server-port' %}?return_url={{ device.get_absolute_url }}">Console Server Port</a></li>
                    <li><a href="{% url 'dcim:frontport_connect' termination_a_id=frontport.pk termination_b_type='console-port' %}?return_url={{ device.get_absolute_url }}">Console Port</a></li>
                    <li><a href="{% url 'dcim:frontport_connect' termination_a_id=frontport.pk termination_b_type='front-port' %}?return_url={{ device.get_absolute_url }}">Front Port</a></li>
                    <li><a href="{% url 'dcim:frontport_connect' termination_a_id=frontport.pk termination_b_type='rear-port' %}?return_url={{ device.get_absolute_url }}">Rear Port</a></li>
                    <li><a href="{% url 'dcim:frontport_connect' termination_a_id=frontport.pk termination_b_type='circuit-termination' %}?return_url={{ device.get_absolute_url }}">Circuit Termination</a></li>
                </ul>
            </span>
        {% endif %}
        {% if perms.dcim.change_frontport %}
            <a href="{% url 'dcim:frontport_edit' pk=frontport.pk %}?return_url={{ device.get_absolute_url }}" title="Edit port" class="btn btn-info btn-xs">
                <i class="glyphicon glyphicon-pencil" aria-hidden="true"></i>
            </a>
        {% endif %}
        {% if perms.dcim.delete_frontport %}
            <a href="{% url 'dcim:frontport_delete' pk=frontport.pk %}?return_url={{ device.get_absolute_url }}" title="Delete port" class="btn btn-danger btn-xs">
                <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
            </a>
        {% endif %}
    </td>
</tr>
