{% extends 'SonataAdminBundle:CRUD:base_edit.html.twig' %}
{% block javascripts %}
{{ parent() }}

{% if app.request.get('_route') == 'admin_app_user_edit' %}
    <script type="text/javascript">
    $(function () {
        $("input[name='{{ admin.uniqid }}[groups][]']").each(function () {
            $(this).on('ifChecked', function(event){
                if ($.trim($(this).closest('label').text()) == 'Gestionnaire de Groupe' || $.trim($(this).closest('label').text()) == 'Contact') {
                    $('#sonata-ba-field-container-{{ admin.uniqid }}_groupesgere label.hide').removeClass('hide');
                    $('#sonata-ba-field-container-{{ admin.uniqid }}_groupesgere div.select2-container').removeClass('hide');
                } else if ($.trim($(this).closest('label').text()) == 'Comptoir') {
                    console.log('Comptoir');
                    $('#sonata-ba-field-container-{{ admin.uniqid }}_comptoirsgere label.hide').removeClass('hide');
                    $('#sonata-ba-field-container-{{ admin.uniqid }}_comptoirsgere div.select2-container').removeClass('hide');
                }
            });
            $(this).on('ifUnchecked', function(event){
                if ($.trim($(this).closest('label').text()) == 'Gestionnaire de Groupe' || $.trim($(this).closest('label').text()) == 'Contact') {
                    $('#{{ admin.uniqid }}_groupesgere').select2('val',[]);
                    $('#sonata-ba-field-container-{{ admin.uniqid }}_groupesgere label.control-label').addClass('hide');
                    $('#sonata-ba-field-container-{{ admin.uniqid }}_groupesgere div.select2-container').addClass('hide');
                } else if ($.trim($(this).closest('label').text()) == 'Comptoir') {
                    $('#{{ admin.uniqid }}_comptoirsgere').select2('val',[]);
                    $('#sonata-ba-field-container-{{ admin.uniqid }}_comptoirsgere label.control-label').addClass('hide');
                    $('#sonata-ba-field-container-{{ admin.uniqid }}_comptoirsgere div.select2-container').addClass('hide');
                }
            });
        });
    });
    </script>
{% endif %}
{% endblock %}
