{% macro renderPager(search, pager) %}
    {% if search == '' %}
        {{ pagerfanta(pager,'twitter_bootstrap_translated',{'proximity' : 1,
            'routeName': 'claro_admin_user_list_pics'
            }
            )
        }}
    {% else %}
        {{ pagerfanta(pager,'twitter_bootstrap_translated',
            {
                'proximity' : 1,
                'routeName': 'claro_admin_user_list_search',
                'routeParams': {'search': search}
            })
        }}
    {% endif %}
{% endmacro %}

{% macro displayControls(workspaceId) %}
    {% if app.user %}
        <button class="btn btn-default action-button" data-action="remove">
            <i class="fa fa-trash-o"></i>
            {{ 'delete'|trans({}, 'platform') }}
        </button>
        <button class="btn btn-default action-button" data-action="password">
            <i class="fa fa-trash-o"></i>
            {{ 'reset_password'|trans({}, 'platform') }}
        </button>
    {% endif %}
{% endmacro %}

{% from _self import renderPager %}
{% from _self import displayControls %}

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

{% block title %}{{ parent() ~ ' - ' ~ 'users_list' | 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':''
            }
        ])
    }}
{% endblock %}

{% block section_content %}

<div class="panel-heading">
    <h3 class="panel-title">{{ 'users_list'|trans({}, 'platform') }}</h3>
</div>
<div class="panel-body">
    <div>
        {{ macros.flashBox() }}
    </div>
    <div class="search-bar row">
        <div class="col-md-6">
            {{ displayControls(workspace.getId()) }}
        </div>
        <div class="col-md-6">
            <div class="input-group">
                <input class="form-control" type="text" id="search-items-txt" placeholder="{{ 'search'|trans({}, 'platform') }}" value={{search}}>
                <span class="input-group-btn">
                    <button class="filter btn btn-default" type="button" id="search-button">
                        <i class="fa fa-search"></i>
                    </button>
                </span>
            </div>
        </div>
    </div>

    {{ renderPager(search, pager) }}

    <div>
    </div>
    <div class="row">
        {% if search == ''%}
            <p> <a href="{{ path('claro_admin_user_list')}}"> {{'change_view'|trans({}, 'platform') }}</a> </p>
        {% else %}
            <p> <a href="{{ path('claro_admin_user_list',{'search':search})}}"> {{'change_view'|trans({}, 'platform') }}</a> </p>
        {% endif %}

    {% for user in pager.currentPageResults %}

            <div class="col-sm-6 col-md-3">
                <div class="thumbnail">
                <span class="row-user">
                    {{ user.getLastName() }},
                    {{ user.getFirstName() }}
                </span>
                {{ user.getId() }}

                {% if user.getPicture() != "" %}
                <a href="{{ path('claro_public_profile_view', {'publicUrl':user.getPublicUrl()}) }}" class="thumbnail">
                    <div class="user-picture" style="background-image:url('{{ asset('uploads/pictures/') ~  user.getPicture() }}');
                "></div>
                </a>
                {% else %}
                <div class="user-picture" style="background-image:url('{{asset('bundles/clarolinecore/images/workspace/tools/user.png')}}');
                ">
                </div>
                {% endif %}
                <div class="well">
                    {{ user.getMail() }} <br />
                    <a href="{{ path('claro_profile_view', {'userId': user.getId()}) }}">
                        <i class="fa fa-user"> </i>
                    </a>
                    <a href="{{ path('claro_user_profile_edit', {'user': user.getId()}) }}">
                        <i class="fa fa-pencil"></i>
                    </a>
                    {% if is_granted('ROLE_ADMIN') %}

                    {% if user.getId() != app.user.id %}
                    <a href="{{ path('claro_desktop_open', {'_switch': user.getUsername()}) }}">
                        <i class="fa fa-eye"></i>
                    </a>
                    {% endif %}
                        {% spaceless %}
                        {% for role in user.getEntityRoles() %}
                            {% if role.type == 1 %}
                                {{ role.getTranslationKey()|trans({}, 'platform')  }}
                                {% if not loop.last %}, {% endif %}
                            {% endif %}
                        {% endfor %}
                        {% endspaceless %}

                    <input type="checkbox" value="{{ user.id }}" class="chk-item" align="center"></input>

                    {% endif %}
                </div>
            </div>
        </div>
        {% if loop.index is divisibleby(4) %}
                    </div>
                    <div class="clearfix"></div>
                    <div class="row">
    {% endif %}
        {% endfor %}
    </div>

    {{ renderPager(search, pager) }}
    <div>
        {{ displayControls(workspace.getId()) }}
    </div>

</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_list", "parameters": {}};
        parameters.route.search = {"route": "claro_admin_user_list_search", "parameters": {}};
        parameters.route.action.remove = {"route": "claro_admin_multidelete_user", "parameters": {}, "type": "DELETE", "confirmTemplate": removeUserConfirm, "delete": true};
        parameters.route.action.password = {"route": "claro_security_initialize_password", "parameters": {}, "type": "POST", "confirmTemplate": resetPasswordConfirm};
        Claroline.Table.initialize(parameters);
    </script>
{% endblock %}
