templates/infoauto/index.html.twig line 1

Open in your IDE?
  1. {% extends 'base.html.twig' %}
  2. {% block title %}Infoauto - Precios{% endblock %}
  3. {% block body %}
  4.     <h1>Infoauto - Precios</h1>
  5.     <div class="row mt-3 border border-1 container-options">
  6.         <div class="col-12 col-lg-2 border-end container-brands">
  7.             <h4 class="text-center">Marca</h4>
  8.             <div class="list-group">
  9.                 {% for key, item in brands %}
  10.                     <button type="button" class="list-group-item list-group-item-action border-0 btn-brand" data-key="{{ key }}" data-id="{{ item.brandId }}" data-name="{{ item.brandName }}">
  11.                         {{ item.brandName }}
  12.                     </button>
  13.                 {% endfor %}
  14.             </div>
  15.         </div>
  16.         <div class="col-12 col-lg-2 border-end container-models">
  17.             <h4 class="text-center">Modelo</h4>
  18.             <div class="list-group"></div>
  19.         </div>
  20.         <div class="col-12 col-lg-2 border-end container-years">
  21.             <h4 class="text-center">Fabricación</h4>
  22.             <div class="list-group"></div>
  23.         </div>
  24.         <div class="col-12 col-lg-4 border-end container-versions">
  25.             <h4 class="text-center">Versión</h4>
  26.             <div class="list-group"></div>
  27.         </div>
  28.         <div class="col-12 col-lg-2 container-prices">
  29.             <h4 class="text-center">Precio</h4>
  30.             <div class="list-group"></div>
  31.         </div>
  32.     </div>
  33.     <style>
  34.         .container-options {
  35.             height: calc(100vh - 230px);
  36.         }
  37.         .container-brands, .container-models, .container-years, .container-versions, .container-prices {
  38.             overflow-y: auto;
  39.             height: 100%;
  40.         }
  41.     </style>
  42. {% endblock %}
  43. {% block javascripts %}
  44.     {{ parent() }}
  45.     <script src="{{ asset('js/jquery.tmpl.min.js') }}"></script>
  46.     <script type="text/javascript">
  47.         var brands = {{ brands|json_encode|raw }};
  48.         var brandSelected = 0;
  49.         var modelSelected = 0;
  50.         var yearSelected = 0;
  51.         var versionSelected = 0;
  52.         console.log(brands);
  53.         $('.btn-brand').click(function() {
  54.             $('.container-brands .list-group button').removeClass('active');
  55.             $(this).addClass('active');
  56.             $('.container-models .list-group button').remove();
  57.             brands[$(this).data('key')].brandGroups.sort((a, b) => a.name.localeCompare(b.name));
  58.             brandSelected = $(this).data('id');
  59.             $.each(brands[$(this).data('key')].brandGroups, function(index, item) {
  60.                 $('.container-models .list-group').append( $('#button-model-template').tmpl({ type: 'model', key: index, id: item.id, name: item.name, list_price: item.list_price, groups: JSON.stringify(item) }) );
  61.             });
  62.         });
  63.         $(document).off('click', '.btn-model').on('click', '.btn-model',  function() {
  64.             $('.container-models .list-group button').removeClass('active');
  65.             $(this).addClass('active');
  66.             $('.container-years .list-group button').remove();
  67.             $('.container-versions .list-group button').remove();
  68.             $('.container-prices .list-group button').remove();
  69.             modelSelected = $(this).data('id');
  70.             if ($(this).data('list-price')) {
  71.                 $('.container-years .list-group').append($('#button-year-template').tmpl({type: 'year', year: '0km'}));
  72.             }
  73.             let groups = JSON.parse( $(this).attr('data-groups') );
  74.             for (var i = groups.prices_to; i >= groups.prices_from; i--) {
  75.                 $('.container-years .list-group').append( $('#button-year-template').tmpl({ type: 'year', year: i }) );
  76.             }
  77.         });
  78.         $(document).off('click', '.btn-year').on('click', '.btn-year',  function() {
  79.             $('.container-years .list-group button').removeClass('active');
  80.             $(this).addClass('active');
  81.             $('.container-versions .list-group button').remove();
  82.             $('.container-prices .list-group button').remove();
  83.             yearSelected = $(this).data('year');
  84.             $('.spinner-' + yearSelected + ' div').removeClass('spinner-hide');
  85.             $.get('{{ path('infoauto_get_versions') }}', {brandId:brandSelected, modelId:modelSelected, modelYear:yearSelected }, function(data) {
  86.                 $.each(data, function(index, item) {
  87.                     $('.container-versions .list-group').append( $('#button-version-template').tmpl({ type: 'version', name: item.name, price: item.price, codia: item.codia }) );
  88.                 });
  89.                 $('.spinner-' + yearSelected + ' > div').addClass('spinner-hide');
  90.             });
  91.         });
  92.         $(document).off('click', '.btn-version').on('click', '.btn-version',  function() {
  93.             $('.container-versions .list-group button').removeClass('active');
  94.             $(this).addClass('active');
  95.             $('.container-prices .list-group button').remove();
  96.             $('.container-prices .list-group').append( $('#button-price-template').tmpl({ type: 'price', price: $(this).data('price'), codia: $(this).data('codia') }) );
  97.         });
  98.         function formatNumber(num) {
  99.             return new Intl.NumberFormat('es-ES', { minimumFractionDigits: 0 }).format(num);
  100.         }
  101.     </script>
  102.     <script id="button-model-template" type="text/x-jquery-tmpl">
  103.         <button type="button" class="list-group-item list-group-item-action border-0 btn-${type}" data-key="${key}" data-id="${id}" data-name="${name}" data-list-price="${list_price}" data-groups='${groups}'>
  104.             ${name}
  105.         </button>
  106.     </script>
  107.     <script id="button-year-template" type="text/x-jquery-tmpl">
  108.         <button type="button" class="list-group-item list-group-item-action border-0 btn-${type} spinner-${year}" data-year="${year}">
  109.             ${year}
  110.             <div class="spinner-border text-white float-end spinner-hide" role="status">
  111.                 <span class="visually-hidden"></span>
  112.             </div>
  113.         </button>
  114.     </script>
  115.     <script id="button-version-template" type="text/x-jquery-tmpl">
  116.         <button type="button" class="list-group-item list-group-item-action border-0 btn-${type}" data-price="${price}" data-codia="${codia}">
  117.             ${name}
  118.         </button>
  119.     </script>
  120.     <script id="button-price-template" type="text/x-jquery-tmpl">
  121.         <button type="button" class="list-group-item list-group-item-action border-0 btn-${type}" data-price="${price}" data-codia="${codia}">
  122.             $  ${price}.000
  123.         </button>
  124.     </script>
  125. {% endblock %}