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

{% block pagewrapper %}
{{ form_start(form) }}
    <h1 class="page-title">
    {% if mode=="update" %}
    Modification Profil de Modération = {{ permmodoprofil.name }}
    {% elseif mode=="submit" %}
    Création Profil de Modération
    {% elseif mode=="delete" %}
    Suppression Profil de Modération = {{ permmodoprofil.name }}
    {% endif %}
    </h1>

    <p>
        {{ form_widget(form.submit) }} <a class="btn btn-secondary" href={{ path('app_core_config_permmodoprofil') }}>Annuler</a>
    </p>

    {% if app.session.flashbag.has('error') %}
        <div class='alert alert-danger' style='margin: 5px 0px'>
            <strong>Erreur</strong><br>
            {% for flashMessage in app.session.flashbag.get('error') %}
                {{ flashMessage }}<br>
            {% endfor %}
        </div>
    {% endif %}

    {% if app.session.flashbag.has('notice') %}
        <div class='alert alert-info' style='margin: 5px 0px'>
            <strong>Information</strong><br>
            {% for flashMessage in app.session.flashbag.get('notice') %}
                {{ flashMessage }}<br>
            {% endfor %}
        </div>
    {% endif %}
    <div class="card">
        <div class="card-header">
            <i class="fa fa-pencil-alt fa-fw"></i> Informations
        </div>

        <div class="card-body">
            {{ form_row(form.name) }}
        </div>
    </div>

    {% if mode=="update" %} 
    <div class="card">
        <div class="card-header">
            <i class="fa fa-table fa-fw"></i> Permissions Modérateur
        </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 >Action</th>
                        <th width="150px">Permission</th>
                    </tr>
                    </thead>

                    
                    {% for permmodo in permmodos %}
                        <tr>
                            <td>
                                <a href='{{ path(permmodo.route) }}' target='blank'><i class='fa fa-eye fa-fw fa-2x' title='Aperçu'></i></a>
                                {{ permmodo.label}}</td>
                            <td>
                            {% set checked="" %}
                            {% if permmodo.visible %} {% set checked="checked" %} {%endif %}
                            <input type="checkbox" class="switch" onChange="switchModo({{ permmodo.id }});" {{ checked }}>
                                
                            </td>
                        </tr>
                    {% endfor %}
                </table>
            </div>
        </div>
    </div>    
    {% endif %}
{{ form_end(form) }}
{% endblock %}


{% block localjavascript %}
    function showInfo(id) {
        $("#modalinfo #modalinfotext").html($("#"+id).attr("data").replace(/\n/g, "<br />"));
    }


    $(document).ready(function() {
        $('#dataTables').DataTable({
            responsive: true,
        });

        $(".switch").bootstrapSwitch();
    });

    function switchModo(id) {
        $.ajax({
            method: "POST",
            url: "{{ path('app_core_config_permmodo_update') }}",
            data: {
                "id": id,
                "profil": {{permmodoprofil.id}}
            }
        });
    }

{% endblock %}
