{% extends 'generic/object_detail.html' %}
{% load buttons %}
{% load helpers %}
{% load plugins %}

{% block extra_breadcrumbs %}
                <li><a href="{% url 'dcim:devicetype_list' %}?manufacturer={{ object.manufacturer.name }}">{{ object.manufacturer }}</a></li>
{% endblock extra_breadcrumbs %}

{% block buttons %}
        {% plugin_buttons object %}
        {% if perms.dcim.change_devicetype %}
            <div class="btn-group">
                <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    <span class="mdi mdi-plus-thick" aria-hidden="true"></span> Add Components <span class="caret"></span>
                </button>
                <ul class="dropdown-menu">
                    {% if perms.dcim.add_consoleporttemplate %}
                        <li><a href="{% url 'dcim:consoleporttemplate_add' %}?device_type={{ object.pk }}&return_url={{ object.get_absolute_url }}%23tab_consoleports">Console Ports</a></li>
                    {% endif %}
                    {% if perms.dcim.add_consoleserverporttemplate %}
                        <li><a href="{% url 'dcim:consoleserverporttemplate_add' %}?device_type={{ object.pk }}&return_url={{ object.get_absolute_url }}%23tab_consoleserverports">Console Server Ports</a></li>
                    {% endif %}
                    {% if perms.dcim.add_powerporttemplate %}
                        <li><a href="{% url 'dcim:powerporttemplate_add' %}?device_type={{ object.pk }}&return_url={{ object.get_absolute_url }}%23tab_powerports">Power Ports</a></li>
                    {% endif %}
                    {% if perms.dcim.add_poweroutlettemplate %}
                        <li><a href="{% url 'dcim:poweroutlettemplate_add' %}?device_type={{ object.pk }}&return_url={{ object.get_absolute_url }}%23tab_poweroutlets">Power Outlets</a></li>
                    {% endif %}
                    {% if perms.dcim.add_interfacetemplate %}
                        <li><a href="{% url 'dcim:interfacetemplate_add' %}?device_type={{ object.pk }}&return_url={{ object.get_absolute_url }}%23tab_interfaces">Interfaces</a></li>
                    {% endif %}
                    {% if perms.dcim.add_frontporttemplate %}
                        <li><a href="{% url 'dcim:frontporttemplate_add' %}?device_type={{ object.pk }}&return_url={{ object.get_absolute_url }}%23tab_frontports">Front Ports</a></li>
                    {% endif %}
                    {% if perms.dcim.add_rearporttemplate %}
                        <li><a href="{% url 'dcim:rearporttemplate_add' %}?device_type={{ object.pk }}&return_url={{ object.get_absolute_url }}%23tab_rearports">Rear Ports</a></li>
                    {% endif %}
                    {% if perms.dcim.add_devicebaytemplate %}
                        <li><a href="{% url 'dcim:devicebaytemplate_add' %}?device_type={{ object.pk }}&return_url={{ object.get_absolute_url }}%23tab_devicebays">Device Bays</a></li>
                    {% endif %}
                </ul>
            </div>
        {% endif %}
        {% if perms.dcim.add_devicetype %}
            {% clone_button object %}
        {% endif %}
        {% if perms.dcim.change_devicetype %}
            {% edit_button object %}
        {% endif %}
        {% if perms.dcim.delete_devicetype %}
            {% delete_button object %}
        {% endif %}
{% endblock buttons %}

{% block title %}{{ object.manufacturer }} {{ object.model }}{% endblock title %}

{% block content_left_page %}
            <div class="panel panel-default">
                <div class="panel-heading">
                    <strong>Chassis</strong>
                </div>
                <table class="table table-hover panel-body attr-table">
                    <tr>
                        <td>Manufacturer</td>
                        <td><a href="{% url 'dcim:devicetype_list' %}?manufacturer={{ object.manufacturer.name }}">{{ object.manufacturer }}</a></td>
                    </tr>
                    <tr>
                        <td>Model Name</td>
                        <td>
                            {{ object.model }}<br/>
                        </td>
                    </tr>
                    <tr>
                        <td>Part Number</td>
                        <td>{{ object.part_number|placeholder }}</td>
                    </tr>
                    <tr>
                        <td>Height (U)</td>
                        <td>{{ object.u_height }}</td>
                    </tr>
                    <tr>
                        <td>Full Depth</td>
                        <td>{{ object.is_full_depth | render_boolean }}</td>
                    </tr>
                    <tr>
                        <td>Parent/Child</td>
                        <td>
                            {{ object.get_subdevice_role_display|placeholder }}
                        </td>
                    </tr>
                    <tr>
                        <td>Front Image</td>
                        <td>
                            {% if object.front_image %}
                                <a href="{{ object.front_image.url }}">
                                    <img src="{{ object.front_image.url }}" alt="{{ object.front_image.name }}" class="img-responsive" />
                                </a>
                            {% else %}
                                <span class="text-muted">&mdash;</span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <td>Rear Image</td>
                        <td>
                            {% if object.rear_image %}
                                <a href="{{ object.rear_image.url }}">
                                    <img src="{{ object.rear_image.url }}" alt="{{ object.rear_image.name }}" class="img-responsive" />
                                </a>
                            {% else %}
                                <span class="text-muted">&mdash;</span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <td>Device Instances</td>
                        <td><a href="{% url 'dcim:device_list' %}?device_type={{ object.pk }}">{{ instance_count }}</a></td>
                    </tr>
                </table>
            </div>
{% endblock content_left_page %}

{% block content_right_page %}
            <div class="panel panel-default">
                <div class="panel-heading">
                    <strong>Comments</strong>
                </div>
                <div class="panel-body rendered-markdown">
                    {% if object.comments %}
                        {{ object.comments|render_markdown }}
                    {% else %}
                        <span class="text-muted">None</span>
                    {% endif %}
                </div>
            </div>
{% endblock content_right_page %}

{% block content_full_width_page %}
            <ul class="nav nav-tabs" role="tablist">
                <li role="presentation" class="active">
                    <a href="#interfaces" role="tab" data-toggle="tab">Interfaces {% badge interface_table.rows|length %}</a>
                </li>
                <li role="presentation">
                    <a href="#frontports" role="tab" data-toggle="tab">Front Ports {% badge front_port_table.rows|length %}</a>
                </li>
                <li role="presentation">
                    <a href="#rearports" role="tab" data-toggle="tab">Rear Ports {% badge rear_port_table.rows|length %}</a>
                </li>
                <li role="presentation">
                    <a href="#consoleports" role="tab" data-toggle="tab">Console Ports {% badge consoleport_table.rows|length %}</a>
                </li>
                <li role="presentation">
                    <a href="#consoleserverports" role="tab" data-toggle="tab">Console Server Ports {% badge consoleserverport_table.rows|length %}</a>
                </li>
                <li role="presentation">
                    <a href="#powerports" role="tab" data-toggle="tab">Power Ports {% badge powerport_table.rows|length %}</a>
                </li>
                <li role="presentation">
                    <a href="#poweroutlets" role="tab" data-toggle="tab">Power Outlets {% badge poweroutlet_table.rows|length %}</a>
                </li>
                <li role="presentation">
                    <a href="#devicebays" role="tab" data-toggle="tab">Device Bays {% badge devicebay_table.rows|length %}</a>
                </li>
            </ul>
            <div class="tab-content">
                <div role="tabpanel" class="tab-pane active" id="interfaces">
                    {% include 'dcim/inc/devicetype_component_table.html' with table=interface_table title='Interfaces' tab='interfaces' %}
                </div>
                <div role="tabpanel" class="tab-pane" id="frontports">
                    {% include 'dcim/inc/devicetype_component_table.html' with table=front_port_table title='Front Ports' tab='frontports' %}
                </div>
                <div role="tabpanel" class="tab-pane" id="rearports">
                    {% include 'dcim/inc/devicetype_component_table.html' with table=rear_port_table title='Rear Ports' tab='rearports' %}
                </div>
                <div role="tabpanel" class="tab-pane" id="consoleports">
                    {% include 'dcim/inc/devicetype_component_table.html' with table=consoleport_table title='Console Ports' tab='consoleports' %}
                </div>
                <div role="tabpanel" class="tab-pane" id="consoleserverports">
                    {% include 'dcim/inc/devicetype_component_table.html' with table=consoleserverport_table title='Console Server Ports' tab='consoleserverports' %}
                </div>
                <div role="tabpanel" class="tab-pane" id="powerports">
                    {% include 'dcim/inc/devicetype_component_table.html' with table=powerport_table title='Power Ports' tab='powerports' %}
                </div>
                <div role="tabpanel" class="tab-pane" id="poweroutlets">
                    {% include 'dcim/inc/devicetype_component_table.html' with table=poweroutlet_table title='Power Outlets' tab='poweroutlets' %}
                </div>
                <div role="tabpanel" class="tab-pane" id="devicebays">
                    {% include 'dcim/inc/devicetype_component_table.html' with table=devicebay_table title='Device Bays' tab='devicebays' %}
                </div>
            </div>
{% endblock content_full_width_page %}

{% block javascript %}
{{ block.super }}
<script type="text/javascript">
    // Redirect user to appropriate components tab if specified
    var hash = document.location.hash;
    var prefix = "tab_";
    if (hash) {
        $('.nav-tabs a[href="'+hash.replace(prefix,"")+'"]').tab('show');
    }
    $('.nav-tabs a').on('shown.bs.tab', function (e) {
        window.location.hash = e.target.hash.replace("#", "#" + prefix);
    });
</script>
{% endblock javascript %}
