{% extends 'base.html.twig' %}

{% block body %}
    <div class="row">
        <div class="col-md-12">
            <table class="table table-striped table-hover table-references">
                <thead>
                <tr>
                    <th>Type</th>
                    <th>Id</th>
                    <th>Authority</th>
                    <th>Title</th>
                    <th>Issued</th>
                </tr>
                </thead>
                <tbody>
                {% for reference in references %}
                    <tr data-url="{{ path('edit', {'id': reference.id|escape('url')}) }}">
                        <td>{{ reference.type }}</td>
                        <td>{{ reference.id }}</td>
                        <td>{{ reference.authority }}</td>
                        <td>{{ reference.title }}</td>
                        <td class="date-field">{{ reference.issued|localizeddate('medium', 'none') }}</td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
        <div class="col-md-12">
            <a href="{{ path('create') }}" class="btn btn-success">Créer</a>
            <a href="{{ asset('references.yml') }}" class="btn btn-default">Télécharger references.yml</a>
        </div>
    </div>
{% endblock %}

{% block javascripts %}
    <script type="text/javascript">
        $(document).ready( function () {
            $('.table-references').DataTable({
                drawCallback: function () {
                    $('.table-references tbody tr').on('click', function() {
                        window.location = $(this).data('url');
                    });
                }
            });
        } );
    </script>
{% endblock %}
