{% extends request.is_ajax|yesno:'bajax.html,base.html' %}
{% load i18n dpagination %}

{% block title %}{% trans 'Devices' %} - {{ group.title }}{% endblock %}

{% block breadcrumb %}
    <ol class="breadcrumb">
        <li><span class="glyphicon glyphicon-home"></span></li>
        <li><a href="{% url 'devapp:group_list' %}">{% trans 'Groups' %}</a></li>
        <li class="active">{{ group.title }}</li>
    </ol>
{% endblock %}

{% block page-header %}
    {% trans 'Devices' %}
{% endblock %}

{% block main %}
    <div class="table-responsive">
        <table class="table table-bordered">
            <thead>
            <tr>
                <th>#</th>
                <th class="col-md-2">
                    <a href="{% url 'devapp:devs' group.pk %}?{% url_order_by request order_by='ip_address' %}">
                        {% trans 'Ip address' %}
                    </a>
                    {% if order_by == 'ip_address' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}
                </th>
                <th class="col-md-4">
                    <a href="{% url 'devapp:devs' group.pk %}?{% url_order_by request order_by='comment' %}">
                        {% trans 'Comment' %}
                    </a>
                    {% if order_by == 'comment' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}
                </th>
                <th class="col-md-3">{% trans 'Mac address' %}</th>
                <th class="col-md-2">
                    <a href="{% url 'devapp:devs' group.pk %}?{% url_order_by request order_by='devtype' %}">
                        {% trans 'Device type' %}
                    </a>
                    {% if order_by == 'devtype' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}
                </th>
                <th class="col-md-1">Do</th>
            </tr>
            </thead>

            <tbody>
            {% with can_del_dev=perms.devapp.delete_device can_ch_dev=perms.devapp.change_device grpid=group.id %}
            {% for dev in devices %}
                {% url 'devapp:view' grpid dev.pk as viewurl %}
                <tr>
                    <td>
                        <a href="{{ viewurl }}" class="btn btn-sm btn-default">
                            {% if dev.status == 'und' %}&ndash;
                            {% else %}
                                {% if dev.status == 'unr' or dev.status == 'dwn' %}
                                    <span class="glyphicon glyphicon-eye-open text-danger"></span>
                                {% elif dev.status == 'up' %}
                                    <span class="glyphicon glyphicon-eye-open text-success"></span>
                                {% else %}
                                    <span class="glyphicon glyphicon-eye-open text-warning"></span>
                                {% endif %}
                            {% endif %}
                        </a>
                    </td>
                    <td><a href="{{ viewurl }}">{{ dev.ip_address|default:'' }}</a></td>
                    <td>{{ dev.comment }}</td>
                    <td>{{ dev.mac_addr|default:_('Not assigned') }}</td>
                    <td>{{ dev.get_devtype_display }}</td>
                    <td class="btn-group btn-group-xs btn-group-justified">
                        {% if can_del_dev %}
                            <a href="{% url 'devapp:del' grpid dev.pk %}" class="btn btn-danger btn-modal">
                                <span class="glyphicon glyphicon-remove"></span>
                            </a>
                        {% endif %}
                        {% if can_ch_dev %}
                            <a href="{% url 'devapp:edit' grpid dev.id %}" class="btn btn-default">
                                <span class="glyphicon glyphicon-edit"></span>
                            </a>
                        {% endif %}
                    </td>
                </tr>
            {% empty %}
                <tr>
                    <td colspan="6">{% trans 'Devices not found' %}. <a href="{% url 'devapp:add' group.pk %}">{% trans 'Create' %}</a></td>
                </tr>
            {% endfor %}
            {% endwith %}
            </tbody>

            <tfoot>
            <tr>
                <td colspan="6">
                    <a href="{% url 'devapp:add' group.pk %}" class="btn btn-success btn-sm">
                        <span class="glyphicon glyphicon-plus"></span> {% trans 'Create' %}
                    </a>
                </td>
            </tr>
            </tfoot>

        </table>
    </div>
{% endblock %}
