{% extends 'layout.html.twig' %}
{% block layout %}
<div class="row" style="display:block; padding-left:40px">
<h2 style="text-align: center">
Chercher une jurisprudence
</h2>
</div>
<div class="row" style="padding-left:40px; padding-top:40px;">
<div class="col-sm-10 col-lg-6" id="select_category">
<select class="form-control custom-select" id="0">
<option value="none">Sélectionez une catégorie</option>
{% for data in jpData[0] %}
<option class="option-category" value="{{ data.id }}">{{ data.name }}</option>
{% endfor %}
</select>
</div>
<br />
<div class="col-md-10" id="jurisprudences_list" style="padding-top:20px">
</div>
</div>
{% endblock %}
{% block javascripts %}
{{ parent() }}
<script>
var categoryRequestId = null;
$(document).ready ( function () {
$(document).on('change', 'select', function () {
// Get the selected element id
var customSelectId = $(this).attr('id');
// Get parent ID
categoryRequestId = $(this).val();
// Load jurisprudences
showJurisprudences();
// Remove next select
for (let i = (parseInt(customSelectId)+1); i < 10; i++) {
// Get element after the selected id
var selectAfterCustomId = $('#'+i);
// Remove it
selectAfterCustomId.remove();
}
var newCustomSelectId = parseInt(customSelectId) + 1;
var newSelect = '<select class="custom-select" id="'+newCustomSelectId+'" style="margin-top:10px"><option>Sélectionner une sous catégorie</option>';
var jpDataEncode = {{ jpData|json_encode|raw }};
var okFlag = false;
if (jpDataEncode[newCustomSelectId] === undefined) {
return;
}
// if ('Sélectionner une sous catégorie' === categoryRequestId) {
// newCustomSelectId = newCustomSelectId -1;
// }
jpDataEncode[newCustomSelectId].forEach(jpCategory => {
if (jpCategory.parentId == categoryRequestId) {
okFlag = true;
var newOption = '<option class="option-category" value="'+jpCategory.id+'">'+jpCategory.name+'</option>';
newSelect = newSelect+''+newOption;
}
})
newSelect = newSelect+'</select>';
if (okFlag === true) {
$('#select_category').append(newSelect)
}
})
})
function showJurisprudences() {
if (categoryRequestId == null) {
return;
}
// Add loader
$('#jurisprudences_list').html('<div class="spinner-border text-primary" role="status"><span class="sr-only">Loading...</span></div>');
var jpListUrl = "{{ path('jurisprudences_list') }}";
$.ajax({
type: 'GET',
url: jpListUrl,
data: {
'categorie': categoryRequestId,
}
}).then(function(response) {
$('#jurisprudences_list').html(response);
});
}
</script>
{% endblock %}
{% block stylesheets %}
{{ parent() }}
<style>
@media screen and (max-width: 1000px) {
.custom-select {
font-size: 50px;
}
}
</style>
{% endblock %}