templates/front/network/network.html.twig line 1

Open in your IDE?
  1. {% extends "front/_common/_base.html.twig" %}
  2. {% block cssadicional %}{% endblock %}
  3. {% block classbody %}{% endblock %}
  4. {% block content %}
  5.     <section class="red_section">
  6.         <div class="red_banner">
  7.             <div class="red_banner_content ww_center">
  8.                 <div class="red_banner_miga">
  9.                     <ul>
  10.                         <li><a href="{{ path('home') }}">Inicio</a></li>
  11.                         <li><a class="active">Contacto</a></li>
  12.                     </ul>
  13.                 </div>
  14.                 <h2 class="red_banner_title">{{ sd.title }}</h2>
  15.             </div>
  16.         </div>
  17.         <div class="red_section_container ww_center">
  18.             <div class="red_section_left">
  19.                 <div class="red_section_info">
  20.                     {% if sd.text1 %}
  21.                         <h3>{{ sd.text1 }}</h3>
  22.                     {% endif %}
  23.                     {% if sd.text2 %}
  24.                         <h4>{{ sd.text2 }}</h4>
  25.                     {% endif %}
  26.                     {% if sd.text3 %}
  27.                         <p>{{ sd.text3 }}</p>
  28.                     {% endif %}
  29.                 </div>
  30.                 <div class="red_section_items">
  31.                     {% for item in categories %}
  32.                         <div class="red_section_datos">
  33.                             <span class="red_section_ico">
  34.                                 <img src="{{ asset(item.icon|image_path) }}" width="" alt="{{ item.title }}">
  35.                             </span>
  36.                             <div class="red_section_text">
  37.                                 <h2>{{ item.title }}</h2>
  38.                                 {% if item.description %}
  39.                                     <p>{{ item.description }}</p>
  40.                                 {% endif %}
  41.                             </div>
  42.                         </div>
  43.                     {% endfor %}
  44.                 </div>
  45.                 <div class="red_section_select">
  46.                     <div class="red_section_select_val">
  47.                         <span class="icon-arrow_drop_down"></span>
  48.                         <select name="" id="department">
  49.                             <option value="all" selected>Todos los departamentos</option>
  50.                             {% for item in departments %}
  51.                                 <option value="{{ item.slug }}">{{ item.title }}</option>
  52.                             {% endfor %}
  53.                         </select>
  54.                     </div>
  55.                     <div class="red_section_select_val">
  56.                         <span class="icon-arrow_drop_down"></span>
  57.                         <select name="" id="city" disabled>
  58.                             <option value="all" selected>Todas las provincias</option>
  59.                         </select>
  60.                     </div>
  61.                 </div>
  62.                 <div class="red_titlte_mapa">
  63.                     <h2></h2>
  64.                 </div>
  65.                 <div class="red_section_mapa_responsive"></div>
  66.                 <div class="red_section_box" id="establishments">
  67.                     {#% include 'front/network/establishment.html.twig' with {'establishments': establishments} %#}
  68.                 </div>
  69.                 <div class="red_info_resultado" id="red_info_resultado" style="display: none;">
  70.                     <p>{{ sd.noResults }}</p>
  71.                 </div>
  72.             </div>
  73.             <div class="red_section_mapa">
  74.                 {% include 'front/network/map.html.twig' %}
  75.             </div>
  76.         </div>
  77.     </section>
  78. {% endblock %}
  79. {% block jsfinal %}
  80.     <script type="text/javascript">
  81.         let itemClick = false;
  82.         $('#Peru_Regions g').on('click', function () {
  83.             itemClick = true;
  84.             $('.st0').removeClass('is_active');
  85.             $(this).find('.st0').addClass('is_active');
  86.             const department = $(this).find('.st0').data('department');
  87.             const department_name = $(this).find('.st0').data('name');
  88.             if ($('#department option[value="' + department + '"]').length > 0) {
  89.                 $('#department').val(department).trigger('change');
  90.             } else {
  91.                 $('#department option:selected').prop('selected', false);
  92.                 updateEstablishmentsByDepartment(department);
  93.             }
  94.             $('.red_titlte_mapa h2').text(department_name);
  95.         })
  96.         let div = document.querySelector('.red_section_mapa');
  97.         function myFunction(x) {
  98.             if (x.matches) {
  99.                 document.querySelector('.red_section_mapa_responsive').appendChild(div)
  100.             } else {
  101.                 document.querySelector('.red_section_container').appendChild(div)
  102.             }
  103.         }
  104.         var x = window.matchMedia("(max-width: 1023px)")
  105.         myFunction(x)
  106.         x.addListener(myFunction)
  107.         $('#department').on('change', function () {
  108.             const department = $('#department').val();
  109.             if (department === 'all') {
  110.                 $('.st0').removeClass('is_active');
  111.                 updateAllEstablishments();
  112.             } else {
  113.                 updateCities(department);
  114.                 updateEstablishments(department, null);
  115.             }
  116.             const department_name = $('#department option:selected').text();
  117.             if (!itemClick) {
  118.                 $('.red_titlte_mapa h2').text(department_name);
  119.                 itemClick = false;
  120.             }
  121.             if ($('#p_' + department).length > 0) {
  122.                 $('.st0').removeClass('is_active');
  123.                 $('#p_' + department).addClass('is_active');
  124.             }
  125.         })
  126.         $('#city').on('change', function () {
  127.             const department = $('#department').val();
  128.             let city = $('#city').val();
  129.             if (city === 'all') {
  130.                 city = null;
  131.             }
  132.             updateEstablishments(department, city);
  133.         })
  134.         if (URL_DEPARTMENTS) {
  135.             updateDepartments();
  136.         }
  137.         function updateDepartments() {
  138.             $.ajax({
  139.                 url: URL_DEPARTMENTS,
  140.                 type: 'post',
  141.                 beforeSend: function () {
  142.                     $('#department').html("").prop('disabled', true);
  143.                     $('#city').prop('disabled', true);
  144.                 },
  145.                 success: function (data) {
  146.                     $('#department').html(createDepartmentSelect(data));
  147.                 },
  148.                 complete: function () {
  149.                     $('#department').prop('disabled', false);
  150.                     $('#city').prop('disabled', false);
  151.                 }
  152.             })
  153.         }
  154.         function updateCities(department) {
  155.             $.ajax({
  156.                 url: URL_CITIES_BY_DEPARTMENT,
  157.                 type: 'post',
  158.                 data: {department: department},
  159.                 beforeSend: function () {
  160.                     $('#department').prop('disabled', true);
  161.                     $('#city').html("").prop('disabled', true);
  162.                 },
  163.                 success: function (data) {
  164.                     $('#city').html(createCitySelect(data));
  165.                 },
  166.                 complete: function () {
  167.                     $('#department').prop('disabled', false);
  168.                     $('#city').prop('disabled', false);
  169.                 }
  170.             })
  171.         }
  172.         function updateEstablishments(department, city) {
  173.             if (city == null) {
  174.                 updateEstablishmentsByDepartment(department);
  175.             } else {
  176.                 updateEstablishmentsByCity(department, city);
  177.             }
  178.         }
  179.         const noResultsMessage = '{{ sd.noResults }}';
  180.         const noResultMessageContainer = $('#red_info_resultado');
  181.         updateAllEstablishments();
  182.         function updateAllEstablishments() {
  183.             $.ajax({
  184.                 url: URL_NETWORK_ESTABLISHMENTS,
  185.                 type: 'post',
  186.                 beforeSend: function () {
  187.                     $('#department').prop('disabled', true);
  188.                     $('#city').prop('disabled', true);
  189.                     $('#establishments').html("");
  190.                     $('.red_info_resultado').hide();
  191.                 },
  192.                 success: function (data) {
  193.                     if (data) {
  194.                         $('#establishments').html(data);
  195.                     } else {
  196.                         $('.red_info_resultado').show();
  197.                     }
  198.                 },
  199.                 complete: function () {
  200.                     $('#department').prop('disabled', false);
  201.                 }
  202.             })
  203.         }
  204.         function updateEstablishmentsByDepartment(department) {
  205.             $.ajax({
  206.                 url: URL_ESTABLISHMENTS_BY_DEPARTMENT,
  207.                 type: 'post',
  208.                 data: {department: department},
  209.                 beforeSend: function () {
  210.                     $('#department').prop('disabled', true);
  211.                     $('#city').html("").prop('disabled', true);
  212.                     $('#establishments').hide().html("");
  213.                     $('.red_info_resultado').hide();
  214.                 },
  215.                 success: function (data) {
  216.                     if (data.status) {
  217.                         $('#establishments').show().html(data.content);
  218.                         $('#city').prop('disabled', false);
  219.                     } else {
  220.                         const message = data.message ? data.message : noResultsMessage;
  221.                         noResultMessageContainer.text(message);
  222.                         $('#establishments').hide();
  223.                         $('.red_info_resultado').show();
  224.                     }
  225.                 },
  226.                 complete: function () {
  227.                     $('#department').prop('disabled', false);
  228.                     $('#city').html(createCitySelect([]));
  229.                 }
  230.             })
  231.         }
  232.         function updateEstablishmentsByCity(department, city) {
  233.             $.ajax({
  234.                 url: URL_ESTABLISHMENTS_BY_CITY,
  235.                 type: 'post',
  236.                 data: {department: department, city: city},
  237.                 beforeSend: function () {
  238.                     $('#department').prop('disabled', true);
  239.                     $('#city').prop('disabled', true);
  240.                     $('#establishments').html("");
  241.                     $('.red_info_resultado').hide();
  242.                 },
  243.                 success: function (data) {
  244.                     if (data.status) {
  245.                         $('#establishments').html(data.content);
  246.                     } else {
  247.                         const message = data.message ? data.message : noResultsMessage;
  248.                         noResultMessageContainer.text(message);
  249.                         $('.red_info_resultado').show();
  250.                     }
  251.                 },
  252.                 complete: function () {
  253.                     $('#department').prop('disabled', false);
  254.                     $('#city').prop('disabled', false);
  255.                 }
  256.             })
  257.         }
  258.         function createCitySelect(data) {
  259.             let options = "<option value=\"all\" selected>Todas las provincias</option>";
  260.             $.each(data, function (i, v) {
  261.                 options += "<option value=\"" + v['slug'] + "\">" + v['title'] + "</option>";
  262.             });
  263.             return options;
  264.         }
  265.         function createDepartmentSelect(data) {
  266.             let options = "<option value=\"all\" selected>Todas los departamentos</option>";
  267.             $.each(data, function (i, v) {
  268.                 options += "<option value=\"" + v['slug'] + "\">" + v['title'] + "</option>";
  269.             });
  270.             return options;
  271.         }
  272.     </script>
  273. {% endblock %}