{% extends request.is_ajax|yesno:'nullcont.htm,tariff_app/ext.html' %}
{% load i18n dpagination %}
{% block content %}

    <div class="table-responsive">
        <table class="table table-striped table-bordered">
            <thead>
            <tr>
                <th>
                    <a href="{% url 'tarifs:home' %}?{% url_order_by request order_by='title' %}">
                        {% trans 'tariff' %}
                    </a>
                    {% if order_by == 'title' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}
                </th>
                <th>
                    <a href="{% url 'tarifs:home' %}?{% url_order_by request order_by='speedIn' %}">
                        {% trans 'Speed In' %}
                    </a>
                    {% if order_by == 'speedIn' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}
                </th>
                <th>
                    <a href="{% url 'tarifs:home' %}?{% url_order_by request order_by='speedOut' %}">
                        {% trans 'Speed Out' %}
                    </a>
                    {% if order_by == 'speedOut' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}
                </th>
                <th>
                    <a href="{% url 'tarifs:home' %}?{% url_order_by request order_by='amount' %}">
                        {% trans 'Price' %}
                    </a>
                    {% if order_by == 'amount' %}<span class="glyphicon glyphicon-filter"></span>{% endif %}
                </th>
                <th>{% trans 'Users count' %}</th>
                <th width="250">{% trans 'Script' %}</th>
                <th width="50">#</th>
            </tr>
            </thead>
            <tbody>
            {% with can_ch_trf=perms.tariff_app.change_tariff can_del_trf=perms.tariff_app.delete_tariff %}
                {% for tar in tariflist %}
                    <tr>
                        <td>
                            {% if can_ch_trf %}
                                <a href="{% url 'tarifs:edit' tar.id %}"><b>{{ tar.title }}</b></a>
                            {% else %}
                                {{ tar.title }}
                            {% endif %}
                        </td>
                        <td>{{ tar.speedIn }}</td>
                        <td>{{ tar.speedOut }}</td>
                        <td>{{ tar.amount }} {% trans 'currency' %}</td>
                        <td>
                            {% if tar.usercount > 0 %}
                                <a href="{% url 'tariff_app:service_users' tar.pk %}">{{ tar.usercount }}</a>
                            {% else %}0{% endif %}
                        </td>
                        <td>{{ tar.get_calc_type_display }}</td>
                        <td>
                            {% if can_del_trf %}
                                <a href="{% url 'tarifs:del' tar.id %}" class="btn btn-sm btn-danger btn-modal">
                                    <span class="glyphicon glyphicon-remove-circle"></span>
                                </a>
                            {% endif %}
                        </td>
                    </tr>
                {% empty %}
                    <tr>
                        <td colspan="7">{% trans 'Services does not exist yet' %}.
                            {% if perms.tariff_app.add_tariff %}
                                <a href="{% url 'tarifs:add' %}" class="lgtbx">{% trans 'Create' %}</a>
                            {% endif %}
                        </td>
                    </tr>
                {% endfor %}
            {% endwith %}
            </tbody>

            {% if perms.tariff_app.add_tariff %}
                <tfoot>
                <tr>
                    <td colspan="7">
                        <a href="{% url 'tarifs:add' %}" class="btn btn-sm btn-success">
                            <span class="glyphicon glyphicon-plus"></span> {% trans 'Add' %}
                        </a>
                    </td>
                </tr>
                </tfoot>
            {% endif %}

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