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

{% block body %}
    <div>
        <center>
            <div id="genetableau">
                {% set formName = "formListeSiteStock" %}
                <form method="POST" id="{{ formName }}">
                    <input type="hidden" name="divCode" value="{{ post.divCode }}" />
                    <input type="hidden" name="divLibelle" value="{{ post.divLibelle }}" />
                    <input type="hidden" name="divCodeSte" value="{{ post.divCodeSte }}" />
                    <input type="hidden" name="is_bon_transfert_multisociete" value="{{ post.is_bon_transfert_multisociete }}" />
                    <input type="hidden" name="site_origine" value="{{ post.site_origine }}" />
                    {% if post.hasOpenedOnlyFilter is defined %}
                        <input type="hidden" name="hasOpenedOnlyFilter" value="{{ post.hasOpenedOnlyFilter }}" />
                        {{ inputSwitch(
                            'Sites ouverts uniquement ?' | trad,
                            'opened_only',
                            post.opened_only is null ? 'OFF': 'ON',
                            'onChange="ajaxRechercheTableau(\''~path('Ajax.liste.siteStockAccessible')~'\', \'genetableau\', \'formListeSiteStock\')"'
                        ) }}
                    {% else %}
                        <input type="hidden" name="opened_only" value="true" />
                    {% endif %}
                    <table class="table" id="tableau">
                        <thead class="thead-dark">
                        <tr>
                            <th>{{ triTable('SITE',  infoPagination.filter.tri_SITE, 'Code' | trad, 'genetableau', path('Ajax.liste.siteStockAccessible'), formName) }}</th>
                            <th>{{ triTable('DESIGN',  infoPagination.filter.tri_DESIGN, 'Libellé' | trad, 'genetableau', path('Ajax.liste.siteStockAccessible'), formName) }}</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <th>{{ filterTable('SITE', infoPagination.filter.filter_SITE, '', 'genetableau', path('Ajax.liste.siteStockAccessible'), formName) }}</th>
                            <th>{{ filterTable('DESIGN', infoPagination.filter.filter_DESIGN, '', 'genetableau', path('Ajax.liste.siteStockAccessible'), formName) }}</th>
                        </tr>
                        {% for siteStock in sitesStocks %}
                            <tr onclick="{{ attrJs('changeCodeLibelle', [ post.divCode, siteStock.SITE, post.divLibelle, siteStock.DESIGN ~ ' (' ~ siteStock.SITE ~ ')']) }}; changeCodeSte('{{ siteStock.CODE_STE }}', '{{ post.divCodeSte }}'); desactivePopup()">
                                <td>{{ siteStock.SITE   | convert_encoding('UTF-8', 'ISO-8859-1') }}</td>
                                <td>{{ siteStock.DESIGN  | convert_encoding('UTF-8', 'ISO-8859-1') }}</td>
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>

                </form>

                {{ paginations(path('Ajax.liste.siteStockAccessible'),infoPagination.nombreDePage, infoPagination.page, infoPagination.post, 'modal-body') }}
            </div>
            <script type="application/javascript">
                function changeCodeSte (codeSte, divCodeSte) {
                    if (!divCodeSte) {
                        return;
                    }

                    $('#' + CSS.escape(divCodeSte)).val(codeSte);
                }
            </script>
        </center>
    </div>
{% endblock %}