Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
819d0d41 | 3 | | CiviCRM version 4.5 | |
6a488035 | 4 | +--------------------------------------------------------------------+ |
819d0d41 | 5 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
6 | +--------------------------------------------------------------------+ |
7 | | This file is a part of CiviCRM. | | |
8 | | | | |
9 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
10 | | under the terms of the GNU Affero General Public License | | |
11 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
12 | | | | |
13 | | CiviCRM is distributed in the hope that it will be useful, but | | |
14 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
15 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
16 | | See the GNU Affero General Public License for more details. | | |
17 | | | | |
18 | | You should have received a copy of the GNU Affero General Public | | |
19 | | License and the CiviCRM Licensing Exception along | | |
20 | | with this program; if not, contact CiviCRM LLC | | |
21 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
22 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
23 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
24 | +--------------------------------------------------------------------+ | |
25 | *} | |
26 | {if $pager and $pager->_response} | |
27 | {if $pager->_response.numPages > 1} | |
28 | <div class="crm-pager"> | |
6a488035 TO |
29 | <span class="element-right"> |
30 | {if $location eq 'top'} | |
d8249fcb | 31 | {$pager->_response.titleTop} |
6a488035 | 32 | {else} |
d8249fcb | 33 | {$pager->_response.titleBottom} |
6a488035 TO |
34 | {/if} |
35 | </span> | |
d8249fcb | 36 | </span> |
6a488035 TO |
37 | <span class="crm-pager-nav"> |
38 | {$pager->_response.first} | |
39 | {$pager->_response.back} | |
40 | {$pager->_response.next} | |
f813f78e | 41 | {$pager->_response.last} |
42 | {$pager->_response.status} | |
6a488035 TO |
43 | </span> |
44 | ||
45 | </div> | |
46 | {/if} | |
f813f78e | 47 | |
6a488035 TO |
48 | {* Controller for 'Rows Per Page' *} |
49 | {if $location eq 'bottom' and $pager->_totalItems > 25} | |
50 | <div class="form-item float-right"> | |
fe010227 CW |
51 | <label for="{$form.formName}-rows-per-page-select">{ts}Rows per page:{/ts}</label> |
52 | <input class="crm-rows-per-page-select" id="{$form.formName}-rows-per-page-select" type="text" size="3" value="{$pager->_perPage}"/> | |
6a488035 TO |
53 | </div> |
54 | <div class="clear"></div> | |
55 | {/if} | |
56 | ||
d8249fcb CW |
57 | {if $location neq 'top'} |
58 | <script type="text/javascript"> | |
59 | {literal} | |
3cc60a06 | 60 | CRM.$(function($) { |
d8249fcb | 61 | {/literal} |
fe010227 CW |
62 | var |
63 | $form = $('#{$form.formName}'), | |
64 | numPages = {$pager->_response.numPages}, | |
65 | currentPage = {$pager->_response.currentPage}, | |
66 | perPageCount = {$pager->_perPage}, | |
cf6519a7 | 67 | currentLocation = {$pager->_response.currentLocation|json_encode}, |
9545c40d | 68 | spinning = null, |
cf6519a7 | 69 | refreshing = false; |
d8249fcb CW |
70 | {literal} |
71 | function refresh(url) { | |
cf6519a7 CW |
72 | if (!refreshing) { |
73 | refreshing = true; | |
74 | var options = url ? {url: url} : {}; | |
75 | $form.off().closest('.crm-ajax-container, #crm-main-content-wrapper').crmSnippet(options).crmSnippet('refresh'); | |
76 | } | |
d8249fcb CW |
77 | } |
78 | function page(num) { | |
79 | num = parseInt(num, 10); | |
80 | if (isNaN(num) || num < 1 || num > numPages || num === currentPage) { | |
81 | return; | |
82 | } | |
fe010227 | 83 | refresh(currentLocation.replace(/crmPID=\d+/, 'crmPID=' + num)); |
d8249fcb | 84 | } |
fe010227 CW |
85 | function changeCount(num) { |
86 | num = parseInt(num, 10); | |
87 | if (isNaN(num) || num < 1 || num === perPageCount) { | |
88 | return; | |
89 | } | |
90 | refresh(currentLocation.replace(/&crmRowCount=\d+/, '') + '&crmRowCount=' + num); | |
91 | } | |
92 | function preventSubmit(e) { | |
93 | if (e.keyCode == 13) { | |
94 | e.preventDefault(); | |
95 | $(this).trigger('change'); | |
96 | return false; | |
97 | } | |
98 | } | |
99 | $('input[name^=crmPID]', $form) | |
100 | .spinner({ | |
101 | min: 1, | |
102 | max: numPages | |
103 | }) | |
d8249fcb CW |
104 | .on('change', function() { |
105 | page($(this).spinner('value')); | |
fe010227 CW |
106 | }) |
107 | .on('keyup keydown keypress', preventSubmit); | |
108 | $('input.crm-rows-per-page-select', $form) | |
109 | .spinner({ | |
110 | min: 25, | |
111 | step: 25 | |
112 | }) | |
113 | .on('change', function() { | |
114 | changeCount($(this).spinner('value')); | |
fe010227 CW |
115 | }) |
116 | .on('keyup keydown keypress', preventSubmit); | |
d8249fcb CW |
117 | $form |
118 | .on('click', 'a.ui-spinner-button', function(e) { | |
cf6519a7 CW |
119 | var $el = $(this); |
120 | // Update after a short delay to allow multiple clicks | |
121 | spinning !== null && window.clearTimeout(spinning); | |
122 | spinning = window.setTimeout(function() { | |
123 | if ($el.is('.crm-pager a')) { | |
124 | page($el.siblings('input[name^=crmPID]').spinner('value')); | |
125 | } else { | |
126 | changeCount($el.siblings('input.crm-rows-per-page-select').spinner('value')); | |
127 | } | |
128 | }, 200); | |
d8249fcb CW |
129 | }) |
130 | .on('click', 'a.crm-pager-link, #alpha-filter a', function() { | |
fe010227 CW |
131 | refresh($(this).attr('href')); |
132 | return false; | |
133 | }); | |
d8249fcb CW |
134 | }); |
135 | {/literal} | |
136 | </script> | |
137 | {/if} | |
138 | ||
6a488035 | 139 | {/if} |