From fe010227508b27e1e1d205f6666ef63b5ced44bf Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 7 Jan 2014 19:13:22 -0800 Subject: [PATCH] CRM-12872 - Ajax-enable pager rowCount --- CRM/Utils/Pager.php | 31 +++------------- CRM/Utils/System.php | 8 ++-- templates/CRM/common/pager.tpl | 67 +++++++++++++++++++++++++--------- 3 files changed, 59 insertions(+), 47 deletions(-) diff --git a/CRM/Utils/Pager.php b/CRM/Utils/Pager.php index 08a6674c4d..3b90bcc7dd 100644 --- a/CRM/Utils/Pager.php +++ b/CRM/Utils/Pager.php @@ -112,9 +112,7 @@ class CRM_Utils_Pager extends Pager_Sliding { 'status' => CRM_Utils_Array::value('status', $params), 'buttonTop' => CRM_Utils_Array::value('buttonTop', $params), 'buttonBottom' => CRM_Utils_Array::value('buttonBottom', $params), - 'twentyfive' => $this->getPerPageLink(25), - 'fifty' => $this->getPerPageLink(50), - 'onehundred' => $this->getPerPageLink(100), + 'currentLocation' => $this->getCurrentLocation(), ); /** @@ -263,29 +261,10 @@ class CRM_Utils_Pager extends Pager_Sliding { return array($offset, $this->_perPage); } - /** - * given a number create a link that will display the number of - * rows as specified by that link - * - * @param int $perPage the number of rows - * - * @return string the link - * @access void - */ - function getPerPageLink($perPage) { - if ($perPage != $this->_perPage) { - $href = $this->makeURL(self::PAGE_ROWCOUNT, $perPage); - $link = sprintf('%s', - $href, - $this->_classString, - $perPage - ) . $this->_spacesBefore . $this->_spacesAfter; - } - else { - $link = $this->_spacesBefore . $perPage . $this->_spacesAfter; - } - - return $link; + function getCurrentLocation() { + $config = CRM_Core_Config::singleton(); + $path = CRM_Utils_Array::value($config->userFrameworkURLVar, $_GET); + return CRM_Utils_System::url($path, CRM_Utils_System::getLinksUrl(self::PAGE_ID, FALSE, TRUE), FALSE, NULL, FALSE) . $this->getCurrentPageID(); } function getFirstPageLink() { diff --git a/CRM/Utils/System.php b/CRM/Utils/System.php index 71bca4f36f..f2cbf2c7b4 100644 --- a/CRM/Utils/System.php +++ b/CRM/Utils/System.php @@ -147,11 +147,10 @@ class CRM_Utils_System { } $querystring = array_merge($querystring, array_unique($arrays)); - $querystring = array_map('htmlentities', $querystring); - $url = implode('&', $querystring); + $url = implode('&', $querystring); if ($urlVar) { - $url .= (!empty($querystring) ? '&' : '') . $urlVar . '='; + $url .= (!empty($querystring) ? '&' : '') . $urlVar . '='; } return $url; @@ -207,6 +206,9 @@ class CRM_Utils_System { * RSS feed. * @param $fragment string A fragment identifier (named anchor) to append to the link. * + * @param bool $htmlize + * @param bool $frontend + * @param bool $forceBackend * @return string an HTML string containing a link to the given path. * @access public * @static diff --git a/templates/CRM/common/pager.tpl b/templates/CRM/common/pager.tpl index 5464a00de1..dd05e9b1d2 100644 --- a/templates/CRM/common/pager.tpl +++ b/templates/CRM/common/pager.tpl @@ -48,10 +48,8 @@ {* Controller for 'Rows Per Page' *} {if $location eq 'bottom' and $pager->_totalItems > 25}
-   - {$pager->_response.twentyfive}  |   - {$pager->_response.fifty}  |   - {$pager->_response.onehundred}  +   +
{/if} @@ -61,9 +59,12 @@ {literal} cj(function($) { {/literal} - var $form = $('#{$form.formName}'); - var numPages = {$pager->_response.numPages}; - var currentPage = {$pager->_response.currentPage}; + var + $form = $('#{$form.formName}'), + numPages = {$pager->_response.numPages}, + currentPage = {$pager->_response.currentPage}, + perPageCount = {$pager->_perPage}, + currentLocation = {$pager->_response.currentLocation|json_encode}; {literal} function refresh(url) { var options = url ? {url: url} : {}; @@ -74,24 +75,54 @@ if (isNaN(num) || num < 1 || num > numPages || num === currentPage) { return; } - var url = $('a.crm-pager-link', $form).attr('href'); - refresh(url.replace(/crmPID=\d/, 'crmPID=' + num)); + refresh(currentLocation.replace(/crmPID=\d+/, 'crmPID=' + num)); } - $('input[name^=crmPID]', $form).spinner({ - min: 1, - max: numPages - }) + function changeCount(num) { + num = parseInt(num, 10); + if (isNaN(num) || num < 1 || num === perPageCount) { + return; + } + refresh(currentLocation.replace(/&crmRowCount=\d+/, '') + '&crmRowCount=' + num); + } + function preventSubmit(e) { + if (e.keyCode == 13) { + e.preventDefault(); + $(this).trigger('change'); + return false; + } + } + $('input[name^=crmPID]', $form) + .spinner({ + min: 1, + max: numPages + }) .on('change', function() { page($(this).spinner('value')); - }); + return false; + }) + .on('keyup keydown keypress', preventSubmit); + $('input.crm-rows-per-page-select', $form) + .spinner({ + min: 25, + step: 25 + }) + .on('change', function() { + changeCount($(this).spinner('value')); + return false; + }) + .on('keyup keydown keypress', preventSubmit); $form .on('click', 'a.ui-spinner-button', function(e) { - page($(this).siblings('input[name^=crmPID]').spinner('value')); + if ($(this).is('.crm-pager a')) { + page($(this).siblings('input[name^=crmPID]').spinner('value')); + } else { + changeCount($(this).siblings('input.crm-rows-per-page-select').spinner('value')); + } }) .on('click', 'a.crm-pager-link, #alpha-filter a', function() { - refresh($(this).attr('href')); - return false; - }); + refresh($(this).attr('href')); + return false; + }); }); {/literal} -- 2.25.1