{% extends 'base.html' %}
{% load staticfiles %}
{% block stylesheets %}
    {{ block.super }}
    <link rel="stylesheet" href="{% static 'css/select2.css' %}"/>
{% endblock stylesheets %}
{% block content %}

    <h3>{{ current_substance }} history for {{ object }}</h3>

    <form method="get">
        <table class="table">
            <tr>
                {% for f in form %}
                    <td>{{ f.label_tag }}</td>
                    <td>
                        {{ f }}
                    </td>
                {% endfor %}
            </tr>
        </table>
    </form>

    <form method="get" action="{% url 'panelist_history_print' pk=object.pk %}" target="_blank">
        <table class="table">
            <tbody>
            <tr>
                <td style="vertical-align: middle; width:10%;">
                    <button type="submit"><span class="icon-printer on-left"></span>Print</button>
                </td>
                <td style="width: 80%;">
                    <label for="print_view_timespan">Timespan</label>
                    <select name="timespan" id="print_view_timespan" class="select2" style="width: 200px;">
                        <option value="r">most recent</option>
                        <option value="y">last twelve months</option>
                        <option value="a">all</option>
                    </select>
                </td>
            </tr>
            </tbody>
        </table>

        <input type="hidden" name="substance" value="{{ substance_key }}"/>

    </form>

    {% if history_data %}
        <table class="table striped" id="panelist_history_table">
            <thead>
            <tr>
                <th>Date</th>
                <th>ITE</th>
                <th>ppm</th>
                <th>&mu;mol/mol</th>
                <th>&sigma;</th>
                <th>10<sup>&sigma;</sup></th>
                <th>y<sub>ite</sub></th>
                <th>10<sup>y<sub>ite</sub></sup></th>
            </tr>
            </thead>
            {% for data in history_data %}
                <tr>
                    <td>{{ data.date }}</td>
                    <td><a href="{% url 'round_detail' pk=data.round_pk %}">{{ data.ite|floatformat:2 }}</a>
                    </td>
                    <td>
                        <a href='{% url 'reference gas_detail' pk=data.cylinder_pk %}'>{{ data.concentration|floatformat:2 }}</a>
                    </td>
                    <td>{{ data.ppm|floatformat:4 }}</td>
                    <td>{{ data.site|floatformat:4 }}</td>
                    <td style="color: {% if data.site_ok %}green{% else %}red{% endif %};">{{ data.site_10|floatformat:4 }}</td>
                    <td>{{ data.y_ite|floatformat:4 }}</td>
                    <td style="color: {% if data.y_ite_ok %}green{% else %}red{% endif %};">{{ data.y_ite_10|floatformat:4 }}</td>
                </tr>
            {% endfor %}
        </table>
    {% else %}
        no results yet.
    {% endif %}
{% endblock content %}
{% block scripts %}
    {{ block.super }}
    <script type="text/javascript" src="{% static 'js/select2.min.js' %}"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            // initialize jquery stuff after page load, fancier datepicker and select dropdown
            $(".select2").select2(
                    {
                        allowClear: false,
                        minimumResultsForSearch: -1
                    }
            );
        });
    </script>

    <script type="text/javascript">
        $(document).ready(function () {
            $('#panelist_history_table').DataTable(
                    {
                        'ordering': false,
                        'filter': false,
                        'info': false
                    }
            );

        });
    </script>
{% endblock %}