templates/jurisprudence/default.html.twig line 1

Open in your IDE?
  1. {% extends 'layout.html.twig' %}
  2. {% block layout %}
  3.     <div class="row" style="display:block; padding-left:40px">
  4.         <h2 style="text-align: center">
  5.             Chercher une jurisprudence
  6.         </h2>
  7.     </div>
  8.     <div class="row" style="padding-left:40px; padding-top:40px;">
  9.             <div class="col-sm-10 col-lg-6" id="select_category">
  10.                 <select class="form-control custom-select" id="0">
  11.                     <option value="none">Sélectionez une catégorie</option>
  12.                     {% for data in jpData[0] %}
  13.                         <option class="option-category" value="{{ data.id }}">{{ data.name }}</option>
  14.                     {% endfor %}
  15.                 </select>
  16.             </div>
  17.         <br />
  18.         <div class="col-md-10" id="jurisprudences_list" style="padding-top:20px">
  19.         </div>
  20.     </div>
  21. {% endblock %}
  22. {% block javascripts %}
  23.     {{ parent() }}
  24.     <script>
  25.         var categoryRequestId = null;
  26.         $(document).ready ( function () {
  27.             $(document).on('change', 'select', function () {
  28.                 // Get the selected element id
  29.                 var customSelectId = $(this).attr('id');
  30.                 // Get parent ID
  31.                 categoryRequestId = $(this).val();
  32.                 // Load jurisprudences
  33.                 showJurisprudences();
  34.                 // Remove next select
  35.                 for (let i = (parseInt(customSelectId)+1); i < 10; i++) {
  36.                     // Get element after the selected id
  37.                     var selectAfterCustomId = $('#'+i);
  38.                     // Remove it
  39.                     selectAfterCustomId.remove();
  40.                 }
  41.                 var newCustomSelectId = parseInt(customSelectId) + 1;
  42.                 var newSelect = '<select class="custom-select" id="'+newCustomSelectId+'" style="margin-top:10px"><option>Sélectionner une sous catégorie</option>';
  43.                 var jpDataEncode = {{ jpData|json_encode|raw }};
  44.                 var okFlag = false;
  45.                 if (jpDataEncode[newCustomSelectId] === undefined) {
  46.                     return;
  47.                 }
  48.                 // if ('Sélectionner une sous catégorie' === categoryRequestId) {
  49.                 //     newCustomSelectId = newCustomSelectId -1;
  50.                 // }
  51.                 jpDataEncode[newCustomSelectId].forEach(jpCategory => {
  52.                     if (jpCategory.parentId == categoryRequestId) {
  53.                         okFlag = true;
  54.                         var newOption = '<option class="option-category" value="'+jpCategory.id+'">'+jpCategory.name+'</option>';
  55.                         newSelect = newSelect+''+newOption;
  56.                     }
  57.                 })
  58.                 newSelect = newSelect+'</select>';
  59.                 if (okFlag === true) {
  60.                     $('#select_category').append(newSelect)
  61.                 }
  62.             })
  63.         })
  64.         function showJurisprudences() {
  65.             if (categoryRequestId == null) {
  66.                 return;
  67.             }
  68.             // Add loader
  69.             $('#jurisprudences_list').html('<div class="spinner-border text-primary" role="status"><span class="sr-only">Loading...</span></div>');
  70.             var jpListUrl = "{{ path('jurisprudences_list') }}";
  71.             $.ajax({
  72.                 type: 'GET',
  73.                 url: jpListUrl,
  74.                 data: {
  75.                     'categorie': categoryRequestId,
  76.                 }
  77.             }).then(function(response) {
  78.                 $('#jurisprudences_list').html(response);
  79.             });
  80.         }
  81.     </script>
  82. {% endblock %}
  83. {% block stylesheets %}
  84.     {{ parent() }}
  85.     <style>
  86.         @media screen and (max-width: 1000px) {
  87.             .custom-select {
  88.                 font-size: 50px;
  89.             }
  90.         }
  91.     </style>
  92. {% endblock %}