{% extends "layout-1-col.html" %}
{% load stafflink russian %}
{% block l-page %}l-page_add{% endblock %}
{% block rightcolumn %}{% endblock %}

{% block content %}
<lego:b-page-title>
    <lego:title>Заявки на покупку книг, страница {{ pages.current }} <img class="ajax-indicator" style="display:none" src="/media/lego/common/block/b-spin/_size/b-spin_16.gif"/></lego:title>
</lego:b-page-title>
<div class="b-list-requests">
    <table>
        <thead>
            <tr>
                <td>№ заявки</td>
                <td>Статус</td>
                <td>Дата заявки</td>
                <td>Сотрудник</td>
                <td>Город</td>
                <td>Книги</td>
                <td>Цена</td>
            </tr>
        </thead>
        <tbody>
        {% for req in requests %}
            <tr class="b-list-requests-item {% if req.state == 'DELIVERED' %}delivered{% endif %}">
                <td><a href="{% url view_request req.id %}">{{ req.id }}</a></td>
                {% if admin %}
                    <td>
                        <div class="b-request-status" onclick="return {{ req.id }}">
                            <div class="b-request-status-popup">
                                {% for state, title in states %}
                                    <div class="b-request-status-item {% if req.state == state %}b-request-status-item-selected{% endif %}" 
                                         onclick="return '{{ state }}'">{{ title }}</div>
                                {% endfor %}
                            </div>
                        </div>
                    </td>
                {% else %}
                    <td>{{ req.get_state_display }}</td>
                {% endif %}
                <td class="b-list-requests__date">{{ req.created_at|human_datetime }}</td>
                <td>{% stafflink req.customer %}</td>
                <td>{{ req.delivery_office.name }}</td>
                <td>{% for book in req.requested_books.all %}
                    <div
                        class="b-list-request-book {% if book.approved %}b-list-request-book-approved{% endif %} {% if admin %}enabled{% endif %}"
                        onclick="return {{ book.id }}">
                        {% if admin %}<a class="b-list-request-book-add-link" href="{% url add_book %}?req={{ book.id }}" title="Добавить книгу" target="_blank">&#x271a;</a>{% endif %}
                        <a href="//h.yandex.net?{{ book.url|urlencode }}">{{ book.title }}</a>
                        {% if book.count > 1 %}&times; {{ book.count }}{% endif %}
                    </div>
                {% endfor %}</td>
                <td class="b-list-requests__price">{{ req.price }}</td>
            </tr>
        {% empty %}
            <tr>
                <td colspan="3">нет заявок</td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
</div>

<lego:b-pager current-page="{{ pages.current }}" total-count="{{ pages.total }}" page-url="{% url manage_requests %}" page-param="page" pager-radius="2" start-from="1"></lego:b-pager>


{% endblock %}