{% macro sortUrl(order, direction) %}
    {% if direction == 'ASC' %}
        {% set newDirection = 'DESC' %}
    {% else %}
        {% set newDirection = 'ASC' %}
    {% endif %}

    {{ path('claro_admin_security_token_list', {'order': order , 'direction': newDirection}) }}
{% endmacro %}

{% from _self import sortUrl %}

{% extends "ClarolineCoreBundle:Administration:layout.html.twig" %}

{% block title %}{{ parent() ~ ' - ' ~ 'mail' | trans({}, 'platform') | striptags | raw }}{% endblock %}

{% block breadcrumb %}
    {{
        macros.breadcrumbs([
            {
                'icon': 'fa fa-cog',
                'name': 'administration'|trans({}, 'platform'),
                'href': path('claro_admin_parameters_index')
            },
            {
                'name': 'parameters'|trans({}, 'platform'),
                'href': path('claro_admin_parameters_index')
            },
            {
                'name': 'security_token'|trans({}, 'platform'),
                'href': ''
            }
        ])
    }}
{% endblock %}

{% block section_content %}
    <div class="panel-heading">
        <h3 class="panel-title">{{ 'security_token_list'|trans({}, 'platform') }}</h3>
    </div>
    <div class="panel-body">
        
        {% if tokens|length > 0 %}
            <div class="table-responsive">
                <table class="table table-hover">
                    <tr>
                        <th>
                            <a href="{{ sortUrl('tokenName', direction) }}">
                                {{ 'name'|trans({}, 'platform') }}
                            </a>
                        </th>
                        <th>{{ 'ip_address'|trans({}, 'platform') }}</th>
                        <th>{{ 'token'|trans({}, 'platform') }}</th>
                        <th>{{ 'actions'|trans({}, 'platform') }}</th>
                    </tr>

                    {% for token in tokens %}
                    <tr>
                        <td>{{ token.getClientName() }}</td>
                        <td>{{ token.getClientIp() }}</td>
                        <td>{{ token.getToken() }}</td>
                        <td>
                            <a href="{{ path('claro_admin_security_token_edit_form', {'tokenId': token.getId()}) }}"
                                class="btn btn-default"
                            >
                                <i class="fa fa-edit"></i>
                            </a>
                            <span class="btn btn-default delete-security-token-btn" data-token-id="{{ token.getId() }}">
                                <i class="fa fa-trash-o"></i>
                            </span>
                        </td>
                    </tr>
                    {% endfor %}
                </table>
            </div>
        {% endif %}
        
        <a href="{{ path('claro_admin_security_token_create_form') }}"
            class="btn btn-primary"
        >
            {{ 'create_security_token'|trans({}, 'platform') }}
        </a>
    </div>

    <div id="delete-security-token-validation-box" class="modal fade" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h3>{{ 'security_token_delete_confirm_title'|trans({}, 'platform') }}</h3>
                </div>
                <div class="modal-body">
                    <p>{{ 'security_token_delete_confirm_message'|trans({}, 'platform') }}</p>
                </div>
                <div class="modal-footer">
                    <input type="button" id="delete-security-token-confirm-ok" class="btn btn-primary" value="{{ 'ok'|trans({}, 'platform') }}"/>
                    <input type="button" class="btn btn-default" data-dismiss="modal" value="{{ 'cancel'|trans({}, 'platform') }}"/>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block javascripts %}
    {{ parent() }}
    <script
        src='{{ asset('bundles/clarolinecore/js/administration/securityTokenList.js') }}'
        type="text/javascript">
    </script>
{% endblock %}