From 8da35492d63b3bc08c6d4a977427e6b3d8468a61 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 13 Jun 2015 10:02:56 -0400 Subject: [PATCH] CRM-16645 - Add scrolling to pcp autocomplete --- CRM/Contact/Page/AJAX.php | 22 +++++++++++++------- templates/CRM/Contribute/Form/SoftCredit.tpl | 6 +++--- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/CRM/Contact/Page/AJAX.php b/CRM/Contact/Page/AJAX.php index 35f485a60a..fb2b92e690 100644 --- a/CRM/Contact/Page/AJAX.php +++ b/CRM/Contact/Page/AJAX.php @@ -158,7 +158,7 @@ class CRM_Contact_Page_AJAX { public static function getPCPList() { $name = CRM_Utils_Array::value('term', $_GET); $name = CRM_Utils_Type::escape($name, 'String'); - $limit = '10'; + $limit = $max = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'search_autocomplete_count', NULL, 10); $where = ' AND pcp.page_id = cp.id AND pcp.contact_id = cc.id'; @@ -181,8 +181,11 @@ class CRM_Contact_Page_AJAX { $whereClause = " WHERE ( sort_name LIKE '$strSearch' $includeNickName ) {$where} "; } - if (!empty($_GET['limit'])) { - $limit = CRM_Utils_Type::escape($_GET['limit'], 'Positive'); + $offset = $count = 0; + if (!empty($_GET['page'])) { + $page = (int) $_GET['page']; + $offset = $limit * ($page - 1); + $limit++; } $select = 'cc.sort_name, pcp.title, cp.title'; @@ -198,17 +201,22 @@ class CRM_Contact_Page_AJAX { FROM civicrm_pcp pcp, civicrm_event cp, civicrm_contact cc {$includeEmailFrom} {$whereClause} AND pcp.page_type = 'event' - LIMIT 0, {$limit} ) t ORDER BY sort_name + LIMIT $offset, $limit "; $dao = CRM_Core_DAO::executeQuery($query); - $results = array(); + $output = array('results' => array(), 'more' => FALSE); while ($dao->fetch()) { - $results[] = array('id' => $dao->id, 'text' => $dao->data); + if (++$count > $max) { + $output['more'] = TRUE; + } + else { + $output['results'][] = array('id' => $dao->id, 'text' => $dao->data); + } } - CRM_Utils_JSON::output($results); + CRM_Utils_JSON::output($output); } public static function relationship() { diff --git a/templates/CRM/Contribute/Form/SoftCredit.tpl b/templates/CRM/Contribute/Form/SoftCredit.tpl index d78bdb1f89..9d30c5d0a5 100644 --- a/templates/CRM/Contribute/Form/SoftCredit.tpl +++ b/templates/CRM/Contribute/Form/SoftCredit.tpl @@ -96,11 +96,11 @@ minimumInputLength: 1, ajax: { url: pcpURL, - data: function(term) { - return {term: term}; + data: function(term, page) { + return {term: term, page: page}; }, results: function(response) { - return {results: response}; + return response; } }, initSelection: function(el, callback) { -- 2.25.1