{% extends 'base.html.twig' %}

{% block localstyle %}
    {%if access!="config" %}
    .page-header {
        padding: 0px 30px 100px 30px !important;
    }    
    {%endif%}
{% endblock %}

{% block pagewrapper %}
    <h1 class="page-title">
        {%if access=="config" %}
        Gestion des Groupes
        {%else%}
        Mes Groupes de Travail
        {%endif%}
    </h1>

    <p>
    {% set permgroup = app.session.get('permgroup') %}
    {% if is_granted('ROLE_ADMIN') or (is_granted('ROLE_MODO') and (permgroup=="ROLE_MODO" or permgroup=="ROLE_ANIM" or permgroup=="ROLE_USER")) or (is_granted('ROLE_ANIM') and (permgroup=="ROLE_ANIM" or permgroup=="ROLE_USER")) or (is_granted('ROLE_USER') and permgroup=="ROLE_USER") %}
        <a class="btn btn-success" href={{ path('app_core_'~access~'_group_submit') }}>
            {% if access=="config" %}
                Ajouter
            {% else %}
                Créer un Groupe de Travail
            {% endif %}
        </a>
    {% endif %}
    {%if access=="config" %}
        <a class="btn btn-success" href={{ path('app_core_config_group_export') }}>Exporter CSV</a>
    {% endif %}
    </p>
    
    <div class="card">
        <div class="card-header">
            <i class="fa fa-table fa-fw"></i>Liste des Groupes
        </div>

        <div class="card-body">
            <div class="dataTable_wrapper">
                <table class="table table-striped table-bordered table-hover" id="dataTables" style="width:100%">
                    <thead>
                    <tr>
                        <th width="180px" class="no-sort">Action</th>
                        <th width="80px" class="no-sort text-center">Icône</th>
                        <th>Label</th>
                        <th>Ouvert</th>
                        <th class="no-sort {% if masteridentity=="SQL" or access!="config" %} no-visible {% endif %}">Filtre</th>
                        {% if portal_activate %}
                        <th>Groupe de Travail</th>
                        <th class="text-center">Propriétaire</th>
                        <th class="no-sort">Visite</th>
                        {% if access=="config" %}
                        <th>Création Pages</th>
                        <th>Création Calendriers</th>
                        <th>Création Blogs</th>
                        <th>Création Projets</th>
                        {% endif %}
                        {% endif %}
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>

    {%if access!="config" %}
        {% set permannu = app.session.get('permannu') %}
        {% if is_granted('ROLE_ADMIN') or (is_granted('ROLE_MODO') and (permannu=="ROLE_MODO" or permannu=="ROLE_ANIM" or permannu=="ROLE_USER")) or (is_granted('ROLE_ANIM') and (permannu=="ROLE_ANIM" or permannu=="ROLE_USER")) or (is_granted('ROLE_USER') and permannu=="ROLE_USER") %}
            <h1 class="page-title">Groupes organisationnels</h1>

            <div class="card">
                <div class="card-header">
                    <i class="fa fa-table fa-fw"></i>Liste des Groupes
                </div>

                <div class="card-body">
                    <div class="dataTable_wrapper">
                        <table class="table table-striped table-bordered table-hover" id="dataTables2" style="width:100%">
                            <thead>
                            <tr>
                                <th width="180px" class="no-sort">Action</th>
                                <th width="80px" class="no-sort text-center">Icône</th>
                                <th>Label</th>
                            </tr>
                            </thead>

                            <tbody>
                                {% for group in grouporgas %}
                                    <tr>
                                        <td><a href="{{ path("app_core_user_group_info",{id:group.id}) }}" title='Utilisateurs du Groupe'><i class='fa fa-users fa-2x fa-fw'></i></a></td>
                                        <td><img src="{{ asset((group.icon?group.icon.label:"uploads/icon/icon_pin.png")) }}" class='avatar' style='background-color:transparent; width:30px;'></td>
                                        <td>{{group.label}}</td>
                                    </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>            
        {% endif %}
    {% endif %}
{% endblock %}


{% block localjavascript %}
    $(document).ready(function() {
        $('#dataTables').DataTable({
            columnDefs: [ { "targets": 'no-sort', "orderable": false },{ "targets": 'no-visible', "visible": false },{"targets": "text-center", "className": "text-center"} ],
            responsive: true,
            iDisplayLength: 100,
            order: [[ 2, "asc" ]],
            processing: true,
            serverSide: true,
        	ajax: "{{ path('app_core_'~access~'_group_ajax_list') }}",

            drawCallback: function(settings) {
                $("a[data-method='out']").click(function(){
                    if( !confirm('Êtes-vous sûr de vouloir vous désinscrire de ce groupe ?')) {
                        return false;
                    }        
                });               
            }                
        });

        $('#dataTables2').DataTable({
            columnDefs: [ { "targets": 'no-sort', "orderable": false },{ "targets": 'no-visible', "visible": false },{"targets": "text-center", "className": "text-center"} ],
            responsive: true,
            iDisplayLength: 100,
            order: [[ 2, "asc" ]],
        });        
    }); 
{% endblock %}
