{% extends '@ajax-layout/layout.twig' %}

{% block body %}
    <div class="popupExport">
        <form method="post" name="filtre_Export" id="filtre_Export">
            {% if typeCompany is same as ('S') %}
                {{ multiSelect('AddCompany', '', leftColum, post, '', 'popupExport', null, []) }}
            {% else %}
                {{ multiSelect('AddCompany', '', leftColum, post, '', 'popupExport', null, []) }}
            {% endif %}
        </form>
    </div>
    <div class="modal-footer">
        <button class="secondaire" onclick="desactivePopup();">{{ 'Annuler' | trad }}</button>
        <button class="principal buttonSend">{{ 'Valider' | trad }}</button>
    </div>
    <script>

        $('#modal-title').html('{{ titleModal }}')

        $( '.buttonSend' ).on('click', function (e) {
            var payload = {}

            $( "ul#AddCompany_right li" ).each(function(i) {
                payload[i] = $( this ).attr('data-codevalue');
            });

            $.ajax({
                type: "POST",
                url: '{{ path('ProjetAchat.Company.addCompany', {typeObjet:typeObjet, idModel: idModel, typeCompany: typeCompany}) }}',
                data: {values: JSON.stringify(payload)},
                dataType: 'json',
                success: function(result){

            		desactivePopup();
            		redirectJSWithPost(window.location.pathname, {'onglet': 'companies'});
                }
            });

        })
    </script>
{% endblock %}