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

{% block pagewrapper %}
    <form>
    <h1 class="page-header">Modération</h1>

    <div class="panel panel-primary">
        <div class="panel-heading">
            <i class="fa fa-table fa-fw"></i> Permissions Modérateur
        </div>

        <div class="panel-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>{{ 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>
    </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('cadoles_core_config_permmodo_update') }}",
            data: {
                "id": id,
            }
        });
    }

{% endblock %}
