Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
1188c7a8 | 3 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 4 | | | |
1188c7a8 TO |
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 | | |
6a488035 TO |
8 | +--------------------------------------------------------------------+ |
9 | *} | |
10 | {if $pager and $pager->_response} | |
11 | {if $pager->_response.numPages > 1} | |
12 | <div class="crm-pager"> | |
6a488035 TO |
13 | <span class="element-right"> |
14 | {if $location eq 'top'} | |
d8249fcb | 15 | {$pager->_response.titleTop} |
6a488035 | 16 | {else} |
d8249fcb | 17 | {$pager->_response.titleBottom} |
6a488035 TO |
18 | {/if} |
19 | </span> | |
d8249fcb | 20 | </span> |
6a488035 TO |
21 | <span class="crm-pager-nav"> |
22 | {$pager->_response.first} | |
23 | {$pager->_response.back} | |
24 | {$pager->_response.next} | |
f813f78e | 25 | {$pager->_response.last} |
26 | {$pager->_response.status} | |
6a488035 TO |
27 | </span> |
28 | ||
29 | </div> | |
30 | {/if} | |
f813f78e | 31 | |
6a488035 TO |
32 | {* Controller for 'Rows Per Page' *} |
33 | {if $location eq 'bottom' and $pager->_totalItems > 25} | |
34 | <div class="form-item float-right"> | |
b50fdacc CW |
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}"/> | |
6a488035 TO |
37 | </div> |
38 | <div class="clear"></div> | |
39 | {/if} | |
40 | ||
d8249fcb CW |
41 | {if $location neq 'top'} |
42 | <script type="text/javascript"> | |
43 | {literal} | |
3cc60a06 | 44 | CRM.$(function($) { |
d8249fcb | 45 | {/literal} |
fe010227 | 46 | var |
67df5485 | 47 | $form = $({if empty($form.formClass)}'#crm-main-content-wrapper'{else}'form.{$form.formClass}'{/if}), |
fe010227 CW |
48 | numPages = {$pager->_response.numPages}, |
49 | currentPage = {$pager->_response.currentPage}, | |
50 | perPageCount = {$pager->_perPage}, | |
cf6519a7 | 51 | currentLocation = {$pager->_response.currentLocation|json_encode}, |
9545c40d | 52 | spinning = null, |
cf6519a7 | 53 | refreshing = false; |
d8249fcb CW |
54 | {literal} |
55 | function refresh(url) { | |
cf6519a7 CW |
56 | if (!refreshing) { |
57 | refreshing = true; | |
58 | var options = url ? {url: url} : {}; | |
67df5485 | 59 | $form.off('.crm-pager').closest('.crm-ajax-container, #crm-main-content-wrapper').crmSnippet(options).crmSnippet('refresh'); |
cf6519a7 | 60 | } |
d8249fcb CW |
61 | } |
62 | function page(num) { | |
63 | num = parseInt(num, 10); | |
64 | if (isNaN(num) || num < 1 || num > numPages || num === currentPage) { | |
65 | return; | |
66 | } | |
fe010227 | 67 | refresh(currentLocation.replace(/crmPID=\d+/, 'crmPID=' + num)); |
d8249fcb | 68 | } |
fe010227 CW |
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 | }) | |
d8249fcb CW |
88 | .on('change', function() { |
89 | page($(this).spinner('value')); | |
fe010227 CW |
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')); | |
fe010227 CW |
99 | }) |
100 | .on('keyup keydown keypress', preventSubmit); | |
d8249fcb | 101 | $form |
67df5485 | 102 | .on('click.crm-pager', 'a.ui-spinner-button', function(e) { |
cf6519a7 CW |
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); | |
d8249fcb | 113 | }) |
4c5309c7 | 114 | // Handle sorting, paging and alpha filtering links |
67df5485 | 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) { |
fe010227 | 116 | refresh($(this).attr('href')); |
4c5309c7 | 117 | e.preventDefault(); |
fe010227 | 118 | }); |
d8249fcb CW |
119 | }); |
120 | {/literal} | |
121 | </script> | |
122 | {/if} | |
123 | ||
6a488035 | 124 | {/if} |