templates/_menu/city_stations.html.twig line 1

Open in your IDE?
  1. <ul class="list-unstyled">
  2.     <a href="javascript:void(0);" id="listByStationsBtn">Показать по выбранным станциям</a>
  3.     {% for stationItem in item.children %}
  4.         <li>{% if stationItem.label != 'all_stations' %}<input type="checkbox" name="stations[]" value="{{ stationItem.extras.routes[0].parameters.station }}" />{% endif %}<a href="{{ stationItem.uri }}">{{ stationItem.label }}</a></li>
  5.     {% endfor %}
  6. </ul>
  7. <script type="text/javascript">
  8.     document.addEventListener('DOMContentLoaded', function() {
  9.         let listByStationsBtn = document.querySelector('#listByStationsBtn');
  10.         listByStationsBtn.addEventListener('click', function () {
  11.             listByStationsBtn.style.display = 'none';
  12.             let url = '{{ path('profile_list.list_by_stations', {city:app.request.get('city').uriIdentity, stations: '_stations_'|raw}) }}';
  13.             let stationIds = [];
  14.             document.querySelectorAll('input[name="stations[]"]').forEach(function (el) {
  15.                 if(el.checked) {
  16.                     stationIds.push(el.value);
  17.                     //можно выбрать не более 130 = 1950 символов + ~40 символов урл
  18.                     if(stationIds.length == 130) {
  19.                         return;
  20.                     }
  21.                 }
  22.             });
  23.             window.location = url.replace('_stations_', stationIds.join(','));
  24.         });
  25.     });
  26. </script>