{% extends '@CadolesCore/base.html.twig' %}

{% block localstyle %}
th { font-size: 10px; }
td { font-size: 10px; }
{% endblock %}
{% block pagewrapper %}
    {% if access=="config" %}
    <h1 class="page-header">Gestion des Utilisateurs</h1>
    {% if masteridentity=="SQL" %}
    <a class="btn btn-success" href={{ path('cadoles_core_config_user_submit') }}>Ajouter</a>
    <a class="btn btn-success" href={{ path('cadoles_core_config_user_export') }}>Exporter CSV</a>
    <br><br>
    {% elseif masteridentity=="LDAP" %}
    <a class="btn btn-success" href={{ path('cadoles_core_config_user_sync') }}>Synchroniser avec Annuaire</a>
    <br><br>
    {% endif %}
    {% else %}
    <br>
    {% endif %}

    <div class="panel panel-primary">
        <div class="panel-heading">
            <i class="fa fa-table fa-fw"></i> Liste des Utilisateurs
        </div>

        <div class="panel-body">
            <div class="dataTable_wrapper">
                <table class="table table-striped table-bordered table-hover" id="dataTables" style="width:100%; font-size:11px;">
                    <thead>
                    <tr>
                        {% if access=="config" %}
                        <th class="no-sort" width="70px">Action</th>
                        {% endif %}
                        <th class="no-sort {% if fields["avatar"] is defined and fields["avatar"].perm==0 %}no-visible{% endif %}">Avatar</th>
                        <th class="{% if fields["login"] is defined and fields["login"].perm==0 and access!="config"%}no-visible{% endif %}">Login</th>
                        <th class="{% if fields["lastname"] is defined and fields["lastname"].perm==0 %}no-visible{% endif %}">Nom</th>
                        <th class="{% if fields["firstname"] is defined and fields["firstname"].perm==0 %}no-visible{% endif %}">Prénom</th>
                        <th class="{% if fields["email"] is defined and fields["email"].perm==0 %}no-visible{% endif %}">Email</th>
                        <th class="{% if fields["telephonenumber"] is defined and fields["telephonenumber"].perm==0 %}no-visible{% endif %}">Téléphone</th>
                        <th class="{% if fields["niveau01"] is defined and fields["niveau01"].perm==0 %}no-visible{% endif %}">{{ labelniveau01 }}</th>
                        {% if viewniveau02 %}
                        <th class="no-sort {% if fields["niveau02"] is defined and fields["niveau02"].perm==0 %}no-visible{% endif %}">{{ labelniveau02 }}</th>
                        {% endif %}
                        <th class="no-sort {% if fields["group"] is defined and fields["group"].perm==0 and is_granted('ROLE_USER') %}no-visible{% endif %}">Groupes</th>
                        <th class="{% if fields["job"] is defined and fields["job"].perm==0 %}no-visible{% endif %}">Métier</th>
                        <th class="{% if fields["position"] is defined and fields["position"].perm==0 %}no-visible{% endif %}">Fonction</th>
                        <th class="{% if fields["visitedate"] is defined and fields["visitedate"].perm==0 and (is_granted('ROLE_USER') or is_granted('ROLE_ANIM')) %}no-visible{% endif %}">Visite</th>
                        <th class="{% if fields["role"] is defined and fields["role"].perm==0 %}no-visible{% endif %}">Rôle</th>                        
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>
{% endblock %}

{% block localjavascript %}
    $(document).ready(function() {
        {% if access=="profil" %}
            $(".sidebar").remove();
            $("body").removeClass("body");
            $("body").addClass("simple");
            $("#page-wrapper").css("margin","auto");
            //$("#page-wrapper").css("max-width","1000px");
            $("#page-wrapper").css("border-left","none");
        {% endif %}

        $('#dataTables').DataTable({
            columnDefs: [ { "targets": 'no-sort', "orderable": false },{ "targets": 'no-visible', "visible": false } ],
            responsive: true,
            iDisplayLength: 100,
            processing: true,
            serverSide: true,
            {% if access=="config" %}
            order: [[ 2, "asc" ]],
        	ajax: "{{ path('cadoles_core_config_user_ajax_list') }}",
            {% else %}
            order: [[ 1, "asc" ]],
            ajax: "{{ path('cadoles_core_user_user_ajax_list') }}",
            {% endif %}
        });
    });
{% endblock %}
