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

{% block body %}
<div id="genetableau">
	<center>
	<div>
		<form method="POST" id='formulaireEntity'>
			<input type="hidden" name="divCode" value="{{ post.divCode }}" />
			<input type="hidden" name="divLibelle" value="{{ post.divLibelle }}" />
			
			<table class="table" id="tableau">
				<thead class="thead-dark">
    				<tr>
    					<th>{{ triTable('ID_PROFIL',  infoPagination.filter.tri_ID_PROFIL, 'Code' | trad, 'tableau', path('Panier.ImportLigne.listeFormat'), 'formulaireEntity') }}</th>
    					<th>{{ triTable('NOM_PROFIL',  infoPagination.filter.tri_NOM_PROFIL, 'Libellé' | trad,'tableau', path('Panier.ImportLigne.listeFormat'), 'formulaireEntity') }}</th>
						<th>{{ 'Favoris ?' | trad }}</th>
					</tr>
    			</thead>
    			<tbody>
    				<tr>
    					<th>{{ filterTable('ID_PROFIL', infoPagination.filter.filter_ID_PROFIL, '', 'tableau', path('Panier.ImportLigne.listeFormat'), 'formulaireEntity') }}</th>
    					<th>{{ filterTable('NOM_PROFIL', infoPagination.filter.filter_NOM_PROFIL, '', 'tableau', path('Panier.ImportLigne.listeFormat'), 'formulaireEntity') }}</th>
						<th></th>
					</tr>
    				{% for entity in listEntity %}
    				<tr>
    					<td onclick="{{ attrJs('changeCodeLibelle', [post.divCode, entity[primaryKey], post.divLibelle, entity[libelleKey] ~ ' (' ~ entity[primaryKey] ~ ')' ]) }};desactivePopup()">{{ entity[primaryKey] | convert_encoding('UTF-8', 'ISO-8859-1')  }}</td>
    					<td onclick="{{ attrJs('changeCodeLibelle', [post.divCode, entity[primaryKey], post.divLibelle, entity[libelleKey] ~ ' (' ~ entity[primaryKey] ~ ')' ]) }};desactivePopup()">{{ entity[libelleKey] | convert_encoding('UTF-8', 'ISO-8859-1') }}</td>
						<td>
							{{ inputAdvance('SWITCH', {
								name : 'favoris'~entity[primaryKey],
								value : entity[primaryKey] == fav,
								'inputAttr' : {
									'data-switchFormat' : 'on',
									'data-pathSwitch' : path('Panier.ImportLigne.updateFavorisFormat', {idFormat:entity[primaryKey]})
								},
							}) }}
						</td>
    				</tr>
    				{% endfor %}
    			</tbody>
			</table>
			
		</form>
		
		{{ paginations(path('Panier.ImportLigne.listeFormat'),infoPagination.nombreDePage, infoPagination.page, infoPagination.post, 'modal-body') }}
	</div>

	</center>
	</div>
    <script>
        $('#modal-title').html("{{ 'Liste des formats d\'import' | trad }}");

        document.addEventListener('change',(event) => {

            var target = event.target;

            if (!(target instanceof HTMLElement) ) {
                return;
            }

            if (!$(target).data('switchformat')) {
                return;
            }
			activeLoader();

			path = $(target).data('pathswitch');

			$.ajax({
				url: path,
				type: 'POST',
				dataType: 'html',
				data: {},
				success: function (data) {
					desactiveLoader();

					$('.input_value_switch[data-switchformat]').each(function(){
						if ($(this).is(':checked') && $(this).attr('id') != $(target).attr('id')) {
							changeValueSwitch($(this).attr('name'), false);
						}
					});
				},
			});
		});
    </script>
{% endblock %}