| 1 | {* |
| 2 | +--------------------------------------------------------------------+ |
| 3 | | Copyright CiviCRM LLC. All rights reserved. | |
| 4 | | | |
| 5 | | This work is published under the GNU AGPLv3 license with some | |
| 6 | | permitted exceptions and without any warranty. For full license | |
| 7 | | and copyright information, see https://civicrm.org/licensing | |
| 8 | +--------------------------------------------------------------------+ |
| 9 | *} |
| 10 | {if $pager and $pager->_response} |
| 11 | {if $pager->_response.numPages > 1} |
| 12 | <div class="crm-pager"> |
| 13 | <span class="element-right"> |
| 14 | {if $location eq 'top'} |
| 15 | {$pager->_response.titleTop} |
| 16 | {else} |
| 17 | {$pager->_response.titleBottom} |
| 18 | {/if} |
| 19 | </span> |
| 20 | </span> |
| 21 | <span class="crm-pager-nav"> |
| 22 | {$pager->_response.first} |
| 23 | {$pager->_response.back} |
| 24 | {$pager->_response.next} |
| 25 | {$pager->_response.last} |
| 26 | {$pager->_response.status} |
| 27 | </span> |
| 28 | |
| 29 | </div> |
| 30 | {/if} |
| 31 | |
| 32 | {* Controller for 'Rows Per Page' *} |
| 33 | {if $location eq 'bottom' and $pager->_totalItems > 25} |
| 34 | <div class="form-item float-right"> |
| 35 | <label for="{$form.formClass}-rows-per-page-select">{ts}Rows per page:{/ts}</label> |
| 36 | <input class="crm-rows-per-page-select" id="{$form.formClass}-rows-per-page-select" type="text" size="3" value="{$pager->_perPage}"/> |
| 37 | </div> |
| 38 | <div class="clear"></div> |
| 39 | {/if} |
| 40 | |
| 41 | {if $location neq 'top'} |
| 42 | <script type="text/javascript"> |
| 43 | {literal} |
| 44 | CRM.$(function($) { |
| 45 | {/literal} |
| 46 | var |
| 47 | $form = $({if empty($form.formClass)}'#crm-main-content-wrapper'{else}'form.{$form.formClass}'{/if}), |
| 48 | numPages = {$pager->_response.numPages}, |
| 49 | currentPage = {$pager->_response.currentPage}, |
| 50 | perPageCount = {$pager->_perPage}, |
| 51 | currentLocation = {$pager->_response.currentLocation|json_encode}, |
| 52 | spinning = null, |
| 53 | refreshing = false; |
| 54 | {literal} |
| 55 | function refresh(url) { |
| 56 | if (!refreshing) { |
| 57 | refreshing = true; |
| 58 | var options = url ? {url: url} : {}; |
| 59 | $form.off('.crm-pager').closest('.crm-ajax-container, #crm-main-content-wrapper').crmSnippet(options).crmSnippet('refresh'); |
| 60 | } |
| 61 | } |
| 62 | function page(num) { |
| 63 | num = parseInt(num, 10); |
| 64 | if (isNaN(num) || num < 1 || num > numPages || num === currentPage) { |
| 65 | return; |
| 66 | } |
| 67 | refresh(currentLocation.replace(/crmPID=\d+/, 'crmPID=' + num)); |
| 68 | } |
| 69 | function changeCount(num) { |
| 70 | num = parseInt(num, 10); |
| 71 | if (isNaN(num) || num < 1 || num === perPageCount) { |
| 72 | return; |
| 73 | } |
| 74 | refresh(currentLocation.replace(/&crmRowCount=\d+/, '') + '&crmRowCount=' + num); |
| 75 | } |
| 76 | function preventSubmit(e) { |
| 77 | if (e.keyCode == 13) { |
| 78 | e.preventDefault(); |
| 79 | $(this).trigger('change'); |
| 80 | return false; |
| 81 | } |
| 82 | } |
| 83 | $('input[name^=crmPID]', $form) |
| 84 | .spinner({ |
| 85 | min: 1, |
| 86 | max: numPages |
| 87 | }) |
| 88 | .on('change', function() { |
| 89 | page($(this).spinner('value')); |
| 90 | }) |
| 91 | .on('keyup keydown keypress', preventSubmit); |
| 92 | $('input.crm-rows-per-page-select', $form) |
| 93 | .spinner({ |
| 94 | min: 25, |
| 95 | step: 25 |
| 96 | }) |
| 97 | .on('change', function() { |
| 98 | changeCount($(this).spinner('value')); |
| 99 | }) |
| 100 | .on('keyup keydown keypress', preventSubmit); |
| 101 | $form |
| 102 | .on('click.crm-pager', 'a.ui-spinner-button', function(e) { |
| 103 | var $el = $(this); |
| 104 | // Update after a short delay to allow multiple clicks |
| 105 | spinning !== null && window.clearTimeout(spinning); |
| 106 | spinning = window.setTimeout(function() { |
| 107 | if ($el.is('.crm-pager a')) { |
| 108 | page($el.siblings('input[name^=crmPID]').spinner('value')); |
| 109 | } else { |
| 110 | changeCount($el.siblings('input.crm-rows-per-page-select').spinner('value')); |
| 111 | } |
| 112 | }, 200); |
| 113 | }) |
| 114 | // Handle sorting, paging and alpha filtering links |
| 115 | .on('click.crm-pager', 'a.crm-pager-link, #alpha-filter a, th a.sorting, th a.sorting_desc, th a.sorting_asc', function(e) { |
| 116 | refresh($(this).attr('href')); |
| 117 | e.preventDefault(); |
| 118 | }); |
| 119 | }); |
| 120 | {/literal} |
| 121 | </script> |
| 122 | {/if} |
| 123 | |
| 124 | {/if} |