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

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