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

{% block body %}

<div id="code-gestion">
	
	<form class=" {% if post.valide_obligatoire == 1 %}formInvisible{% endif %}" id='form'>
		<input type="hidden" name="NUM_LOT" id="NUM_LOT" value="{{ post.NUM_LOT }}" />
		<input type="hidden" name="CODE_SI" id="CODE_SI" value="{{ post.CODE_SI }}" />
		<input type="hidden" name="CODE_STE" id="CODE_STE" value="{{ post.CODE_STE }}" />
		<input type="hidden" name="inputCG" id="inputCG" value="{{ post.inputCG }}" />
		<input type="hidden" name="affichageLibelle" id="affichageLibelle" value="{{ post.affichageLibelle }}" />
		<input type="hidden" name="CODE_GESTION_PAR_ID" id="CODE_GESTION_PAR_ID" value="{{ post.CODE_GESTION_PAR_ID }}" />
		{% if post.valide_obligatoire != 1 %}
		<div class="colonne last">
			<div class="row">
				{{ inputSwitch(
					'Uniquement les CG valides ?' | trad,
					'cg_valide',
					post.cg_valide | default('0'),
					attr({
						onchange: 'ajaxRechercheTableau('
							~ [
								path('Ajax.Treeview.codeGestion'),
								'code-gestion',
								'form'
							] |map(item => item |json) | join(',') 
							~')'
					}),
				) }}
			</div>
		</div>
		{% endif %}
	</form>
	<div id="treeview" class="treeview">
	</div>
	<div class="border-top">
		<button class="button principal button_right" 
			onclick="{%- apply escape('html_attr') -%}
			choixCG(
				{{- path('Ajax.Treeview.getCodeGestion') | json -}},
				{{- post.inputCG | json -}},
				{{- CODE_GESTION_PAR_ID | json -}},
				{{- post.affichageLibelle | json -}}
			);{%- endapply -%}"
		>{{ 'Valider'|trad }}</button>
	</div>
	
	<script>
	$('#treeview').treeview({
		'data': {{ treeCG | json }},
		'showTags': true,
		'levels': 2,
		'enableLinks': true,
	});
	</script>
</div>

{% endblock %}