Skip to content
Snippets Groups Projects
Commit fe010227 authored by colemanw's avatar colemanw
Browse files

CRM-12872 - Ajax-enable pager rowCount

parent d8249fcb
Branches
Tags
No related merge requests found
......@@ -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('<a href="%s" %s>%s</a>',
$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() {
......
......@@ -147,11 +147,10 @@ class CRM_Utils_System {
}
$querystring = array_merge($querystring, array_unique($arrays));
$querystring = array_map('htmlentities', $querystring);
$url = implode('&amp;', $querystring);
$url = implode('&', $querystring);
if ($urlVar) {
$url .= (!empty($querystring) ? '&amp;' : '') . $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
......
......@@ -48,10 +48,8 @@
{* Controller for 'Rows Per Page' *}
{if $location eq 'bottom' and $pager->_totalItems > 25}
<div class="form-item float-right">
<label>{ts}Rows per page:{/ts}</label> &nbsp;
{$pager->_response.twentyfive}&nbsp; | &nbsp;
{$pager->_response.fifty}&nbsp; | &nbsp;
{$pager->_response.onehundred}&nbsp;
<label for="{$form.formName}-rows-per-page-select">{ts}Rows per page:{/ts}</label> &nbsp;
<input class="crm-rows-per-page-select" id="{$form.formName}-rows-per-page-select" type="text" size="3" value="{$pager->_perPage}"/>
</div>
<div class="clear"></div>
{/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}
</script>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment