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

{% block body %}
    <div>
        <center>
            <div id="genetableau">
                {% set formName = 'formulaireListeDemandesServices' %}
                <form method="POST" name="{{ formName }}" id='{{ formName }}'>
                    <input type="hidden" name="filter_SE#point#SOLDE_DS" value="{{ post['filter_SE#point#SOLDE_DS'] }}" />
                    <input type="hidden" name="filter_SE#point#TYPE_DEM" value="{{ post['filter_SE#point#TYPE_DEM'] }}" />
                    <input type="hidden" name="filter_SE#point#SITE" value="{{ post['filter_SE#point#SITE'] }}" />
                    <input type="hidden" name="divCode" value="{{ post.divCode }}" />
                    <input type="hidden" name="divLibelle" value="{{ post.divLibelle }}" />
                    <input type="hidden" name="divDest" value="{{ post.divDest }}" />
                    <table class="table" id="tableau">
                        <thead class="thead-dark">
                            <tr>
                                <th>{{ triTable('NO_DS',  infoPagination.filter.tri_NO_DS, 'N°DS' | trad, 'genetableau', path('Ajax.liste.demandesServices'), formName) }}</th>
                                <th>{{ triTable('DTE_CREAT',  infoPagination.filter.tri_DTE_CREAT, 'Création' | trad, 'genetableau', path('Ajax.liste.demandesServices'), formName) }}</th>
                                <th>{{ triTable('SITE',  infoPagination.filter.tri_SITE, 'Site tiré' | trad, 'genetableau', path('Ajax.liste.demandesServices'), formName) }}</th>
                                <th>{{ triTable('COMMENTAIRE',  infoPagination.filter.tri_COMMENTAIRE, 'Commentaire' | trad, 'genetableau', path('Ajax.liste.demandesServices'), formName) }}</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <th>{{ filterTable('egal_NO_DS', infoPagination.filter.filter_egal_NO_DS, '', 'genetableau', path('Ajax.liste.demandesServices'), formName) }}</th>
                                <th>{{ filterTable('date_DTE_CREAT', infoPagination.filter.filter_date_DTE_CREAT, '', 'genetableau', path('Ajax.liste.demandesServices'), formName, 'datepicker') }}</th>
                                <th>{{ filterTable('SE#point#SITE', infoPagination.filter['filter_SE#point#SITE'],'','genetableau', path('Ajax.liste.demandesServices'), formName) }}</th>
                                <th>{{ filterTable('M#point#CONTMEMO', infoPagination.filter['filter_M#point#CONTMEMO'],'','genetableau', path('Ajax.liste.demandesServices'), formName) }}</th>
                            </tr>
                            {% for demandeService in demandesServices %}
                                <tr onclick="changeInputValue('{{ demandeService.NO_DS }}', '{{ post.divCode }}', '{{ post.divLibelle }}'); changeDestInput('{{ post.divDest }}', '{{ demandeService.TIERS }}'); desactivePopup()">
                                    <td>{{ demandeService.NO_DS }}</td>
                                    <td>{{ demandeService.DTE_CREAT | dateTrad }}</td>
                                    <td>{{ demandeService.SITE_DESIGN ~ ' (' ~ demandeService.SITE ~ ')' }}</td>
                                    <td>{{ shortLibelle(demandeService.COMMENTAIRE, 55) }}</td>
                                </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </form>
                {{ paginations(path('Ajax.liste.demandesServices'),infoPagination.nombreDePage, infoPagination.page, infoPagination.post, 'modal-body') }}
            </div>

        </center>
    </div>
    <script type="application/javascript">
        function changeInputValue (noDs, divCode, divLibelle) {
            const divCodeInput = $('#' + CSS.escape(divCode));

            divCodeInput.val(noDs);
            divCodeInput.trigger('change');
            $('#' + CSS.escape(divLibelle)).val(noDs);
        }

        function changeDestInput (divDest, tiers) {
            if (divDest) {
                const faceInput = $('#' + CSS.escape(divDest));

                faceInput.val(tiers);
                faceInput.trigger('change');
                $('#' + CSS.escape(divDest.replace('text', 'input'))).val(tiers);
                $('#' + CSS.escape(divDest.replace('text', 'input'))).trigger(tiers);
            }
        }
    </script>
{% endblock %}