{% extends "SsoBackendBundle:Token:base.html.twig" %}
{% block title %}{{ parent() }} - List{% endblock %}

{% block body %}
    <div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
         aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h2>Do you really want to delete this token?</h2>
                </div>
                <div class="modal-body">
                    <p>You are about to delete one token, this procedure is irreversible.</p>
                    <p>Do you want to proceed?</p>
                    <p>We hope that you know what you do!</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                    <a href="#" class="btn btn-danger danger">Delete</a>
                </div>
            </div>
        </div>
    </div>
    <h2>Token List</h2>
    <div class="row">
        <div class="col-md-12 col-ld-12">
            <a class="btn btn-primary dropdown-toggle" data-toggle="collapse" data-target="#filters">
                show filter
                <span class="caret"></span>
            </a>
        </div>
        <div class="col-md-12 col-ld-12">
            <div id="filters" class="collapse">
                <form class="well" action="{{ path('_admin_backend_token_list') }}"
                      method="get" {{ form_enctype(filterForm) }}>
                    {{ form_widget(filterForm) }}
                    <p>
                        <button class="btn btn-success" type="submit" name="filter_action" value="filter">filter
                        </button>
                        <button class="btn btn-danger" type="submit" name="filter_action" value="reset">reset</button>
                    </p>
                </form>
            </div>
        </div>
    </div>
    <hr/>
    <div class="row">
        <div class="col-md-12 col-ld-12">
            <table class="table table-striped table-bordered table-condensed">
                <tr>
                    <th>ServiceToken</th>
                    <th>ServiceToken2Ip</th>
                    <th>AllowedCallsPerDay</th>
                    <th>ValidUntil</th>
                    <th>Blocked</th>
                    <th>Access</th>
                    <th>Description</th>
                    <th>Action</th>
                </tr>
                {% for token in tokens %}
                    <tr>
                        <td><a class="tt" data-toggle="tooltip" data-placement="top" title="{{ token.ServiceToken }}"
                               href="#"><span class="cutstring">{{ token.ServiceToken }}</span></a></td>
                        <td>{{ token.ServiceToken2Ip }}</td>
                        <td>{{ token.AllowedCallsPerDay }}</td>
                        <td>{{ token.ValidUntil|date('Y-m-d') }}</td>
                        <td>{{ token.Blocked }}</td>
                        <td>{{ token.accessRestricted ? 'restricted' : '' }}</td>
                        <td>{{ token.Description }}</td>
                        <td>
                            <a class="btn btn-default btn-xs"
                               href="{{ path('_admin_backend_token_edit', {'tokenId': token.ServiceToken}) }}">edit</a>
                            <a class="btn btn-success btn-xs"
                               href="{{ path('_admin_backend_token_show', {'tokenId': token.ServiceToken}) }}">show</a>
                            <a class="btn btn-danger btn-xs" data-toggle="modal" data-target="#confirm-delete"
                               data-href="{{ path('_admin_backend_token_delete', {'tokenId': token.ServiceToken}) }}"
                               href="#">delete</a>
                        </td>
                    </tr>
                {% endfor %}
            </table>
        </div>
    </div>

    <div>
        {{ pagerHtml|raw }}
    </div>

    <a class="btn btn-default" href="{{ path('_admin_backend_token_create') }}" title="add token">
        add token
    </a>

    <div class="well" style="margin-top: 20px;">
        If <strong>access is restricted</strong>, an additional filter is added to User-AdvancedSearch (User-Show, -Add
        and -Update will follow in later releases).
    </div>
{% endblock %}

{% block javascripts %}
    <script>
        $(function () {
            $(".tt").tooltip();
            $('#confirm-delete').on('show.bs.modal', function (e) {
                $(this).find('.danger').attr('href', $(e.relatedTarget).data('href'));
            });
        });
    </script>
    {{ parent() }}
{% endblock %}
