{% macro renderPager(pager, max, page, userId) %}
    {{
        pagerfanta(
            pager,
            'twitter_bootstrap_translated',
            {
                'proximity' : 1,
                'routeName': 'claro_admin_user_workspaces',
                'routeParams': {'max': max, 'page': page, 'user': userId}
            }
        )
    }}
{% endmacro %}

{% from _self import renderPager %}
{% from "ClarolineCoreBundle::macros.html.twig" import maxResultsSelectBox %}

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

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

{% block breadcrumb %}
    {{
        macros.breadcrumbs([
            {
                'icon': 'fa fa-cog',
                'name': 'administration'|trans({}, 'platform'),
                'href': path('claro_admin_index')
            },
            {
                'name': 'users_management'|trans({}, 'platform'),
                'href': path('claro_admin_users_management')
            },
            {
                'name': 'users'|trans({}, 'platform'),
                'href': path('claro_admin_user_list')
            },
            {
                'name': user.getUsername()|trans({}, 'platform'),
                'href': ''
            }
        ])
    }}
{% endblock %}

{% block section_content %}
    <div class="panel-heading">
        <h3 class="panel-title">{{ 'workspace_list'|trans({}, 'platform') }}</h3>
    </div>

    <div class="panel-body">
        <div class="row">
            <div class="col-md-8">
                {% if pager.getNbPages() > 1 %}
                    {{ renderPager(pager, max, page, user.getId()) }}
                {% endif %}
            </div>
            <div id="search-button"></div>
            <div class="col-md-4" style="margin-top: 15px;">
                {{ maxResultsSelectBox(max, "$('#search-button').trigger('click');", 'workspaces_per_page') }}
            </div>
        </div>
        <div class="table-responsive">
            <table id="workspace-table"  class="table table-striped table-bordered table-condensed">
                <thead>
                    <tr>
                        <th>{{ 'name'|trans({}, 'platform') }}</th>
                        <th>{{ 'code'|trans({}, 'platform') }}</th>
                    </tr>
                </thead>
                <tbody>
                    {% for workspace in pager.currentPageResults %}
                        <tr>
                            <td><a href="{{ path('claro_workspace_open', {'workspaceId': workspace.getId()}) }}">{{ workspace.getName() }}</a></td>
                            <td>{{ workspace.getCode() }}</td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
        {% if pager.getNbPages() > 1 %}
            {{ renderPager(pager, max, page, user.getId()) }}
        {% endif %}
    </div>
{% endblock %}

{% block javascripts %}
    {{ parent() }}
    <script src='{{ asset('bundles/clarolinecore/js/table.js') }}' type="text/javascript"></script>
    <script>
        parameters = {};
        parameters.route = {};
        parameters.route.action = {};
        parameters.route.normal = {"route": "claro_admin_user_workspaces", "parameters": {'user': '{{ user.getId() }}' }};
        Claroline.Table.initialize(parameters);
    </script>
{% endblock %}
