{% extends 'admin/change_list.html' %}

{% load static driver27 %}

{% block title %}Positions of {{ race }}{% endblock %}

{% block extrastyle %}
    {{ block.super }}

    <link rel="stylesheet" href="{% static 'driver27/css/positions.css' %}">
{% endblock %}

{% block extrahead %}
    {{ block.super }}
    <script src="{% static 'admin/js/vendor/jquery/jquery.js' %}"></script>
    <script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <script src="{% static 'driver27/js/positions.js' %}"></script>
{% endblock %}

{% block breadcrumbs %}
    <div class="breadcrumbs">
        <a href="{% url 'admin:index' %}">Home</a> &rsaquo;
        <a href="{% url 'admin:driver27_race_changelist' %}">Races</a> &rsaquo;
        <a href="{% url 'admin:driver27_race_change' race.id %}">{{ race }}</a> &rsaquo;
        Results
    </div>
{% endblock %}

{% block content %}
    <h1>Positions of {{ race }}</h1>

    <form id='form-positions' method="post">
        {% csrf_token %}
        <input type="button" value="Update positions"/>
    </form>

    {% with results=race.results.all %}
        {% include 'driver27/admin/_results_links.html' %}
        <div class="result-list">
            <input type="button" class="deselect-dnf" value="Deselect DNF">
            <ul id="qualifying" class="ordered-race-results">
                <caption>Qualifying</caption>
                {% for result in results|order_results:'qualifying' %}
                    {% with seat=result.seat pos_key='qualifying' %}
                        {% include 'driver27/admin/_positions_ul.html' %}
                    {% endwith %}
                {% endfor %}
            </ul>
        </div>


        {% include 'driver27/admin/_results_links.html' %}
        <div class="result-list">
            <input type="button" class="deselect-dnf" value="Deselect DNF">
            <ul id="finish" class="ordered-race-results">
                <caption>Finish</caption>
                {% for result in results|order_results:'finish' %}
                    {% with seat=result.seat pos_key='finish' %}
                        {% include 'driver27/admin/_positions_ul.html' %}
                    {% endwith %}
                {% endfor %}
            </ul>
        </div>

        {% include 'driver27/admin/_results_links.html' %}

        <ul id="other_seats">
            <caption>Other seats</caption>
            {% for seat in race.no_seats.all %}
                {% with pos_key=None %}
                    {% include 'driver27/admin/_positions_ul.html' %}
                {% endwith %}
            {% endfor %}
        </ul>
    {% endwith %}
{% endblock %}