src/Cms/CoreBundle/Resources/views/includes/Search/Sort.html.twig line 1

Open in your IDE?
  1. {% set term = _args.term %}
  2. {% set htmlId = _args.htmlId|default('campussuite-search-term-' ~ token()) %}
  3. <div id="{{ htmlId }}" data-campussuite-search-term>
  4.     <input type="hidden" data-sort-value value="{{ term.field }}" />
  5.     <input type="hidden" data-sort-direction value="{{ term.direction }}" />
  6.     <div class="dropdown action-item">
  7.         <a class="btn btn-filter dropdown-toggle" data-toggle="dropdown" aria-expanded="true">
  8.             <span>Sort by</span>
  9.             <i class="fa fa-chevron-down"></i>
  10.         </a>
  11.         <ul class="dropdown-menu" role="menu" aria-labelledby="export">
  12.             {% for value,label in term.options['options']|sort %}
  13.                 <li role="presentation">
  14.                     <a role="menuitem" tabindex="-1" href="#" data-sort-option="{{ value }}"{% if term.field is same as(value) %} style="font-weight: bold;"{% endif %}>{{ label }}</a>
  15.                 </li>
  16.             {% endfor %}
  17.         </ul>
  18.     </div>
  19.     <div class="action-item filter-asc"{% if term.direction is same as('ASC') %} style="display: none;"{% endif %}>
  20.         <a class="btn btn-filter filter-icon" href="#">
  21.             <i class="fa fa-chevron-up"></i>
  22.         </a>
  23.     </div>
  24.     <div class="action-item filter-des"{% if term.direction is same as('DESC') %} style="display: none;"{% endif %}>
  25.         <a class="btn btn-filter filter-icon" href="#">
  26.             <i class="fa fa-chevron-down"></i>
  27.         </a>
  28.     </div>
  29. </div>
  30. <script type="text/javascript">
  31.     $(function () {
  32.         $('#{{ htmlId }}').on('click', 'a', function (e) {
  33.             var $target = $(e.currentTarget),
  34.                 plugin = $(e.delegateTarget).data('campussuiteSearchTerm');
  35.             e.preventDefault();
  36.             switch (true) {
  37.                 case $target.closest('.action-item').hasClass('filter-asc'):
  38.                     plugin.$element.find('[data-sort-direction]').val('ASC');
  39.                     $(e.currentTarget).trigger('campussuite.search.submit');
  40.                     break;
  41.                 case $target.closest('.action-item').hasClass('filter-des'):
  42.                     plugin.$element.find('[data-sort-direction]').val('DESC');
  43.                     $(e.currentTarget).trigger('campussuite.search.submit');
  44.                     break;
  45.                 case $target.attr('role') === 'menuitem':
  46.                     plugin.$element.find('[data-sort-value]').val($target.attr('data-sort-option'));
  47.                     $(e.currentTarget).trigger('campussuite.search.submit');
  48.                     break;
  49.             }
  50.         });
  51.         $('#{{ htmlId }}').campussuiteSearchTerm({
  52.             _init: function () {
  53.                 // noop
  54.             },
  55.             compiler: function () {
  56.                 var value = this.$element.find('[data-sort-value]').val(),
  57.                     direction = this.$element.find('[data-sort-direction]').val();
  58.                 if (value === undefined || value === null || typeof value !== 'string' || value === '') {
  59.                     return null;
  60.                 }
  61.                 if (direction !== 'ASC' && direction !== 'DESC') {
  62.                     direction = 'ASC';
  63.                 }
  64.                 return 'sort:' + value + ':' + direction;
  65.             }
  66.         });
  67.     });
  68. </script>