{% extends "admin.html.twig" %}

{% block adminContent %}
    <h1>
        {{ 'admin.modules.title'|trans }}
        <small>
            {{ 'admin.modules.subtitle'|trans }}
        </small>
    </h1>
    
    <hr>
        
    <table class="table table-bordered">
        <thead class="thead-light">
            <tr>
                <th>{{ 'label.module'|trans }}</th>
                <th>{{ 'label.enabled'|trans }}</th>
            </tr>
        </thead>
        <tbody>
            {% for module in modules %}
                <tr>
                    <td>{{module.name}}</td>
                    <td>
                        <input type="checkbox" value="1" {% if module.active %}checked{% endif %} class="module-status" data-key="{{ module.key }}">
                    </td>
                </tr>
            {% endfor %}
        </tbody>
    </table>
{% endblock %}

{% block javascripts %}
    {{ parent() }}
    <script>
        $(function() {
            'use strict'
            
            $('.module-status').on('change', function () {
                var checkbox = $(this);
                
                $.ajax({
                    url: '{{ path('admin_modulos_update') }}',
                    type: 'post',
                    data: {
                        key: checkbox.data('key') ,
                        active: checkbox.is(':checked') ? 1 : 0,
                    },
                    succes: function () {
                    }
                });
            });
        });
    </script>
{% endblock %}
