diff --git a/htdocs/takepos/ajax/ajax.php b/htdocs/takepos/ajax/ajax.php index a3bcc04b5c8..20fb282b1cd 100644 --- a/htdocs/takepos/ajax/ajax.php +++ b/htdocs/takepos/ajax/ajax.php @@ -48,6 +48,8 @@ $category = GETPOST('category', 'alphanohtml'); // Can be id of category or 'sup $action = GETPOST('action', 'aZ09'); $term = GETPOST('term', 'alpha'); $id = GETPOST('id', 'int'); +$search_start = GETPOST('search_start', 'int'); +$search_limit = GETPOST('search_limit', 'int'); if (empty($user->rights->takepos->run)) { accessforbidden(); @@ -232,6 +234,9 @@ if ($action == 'getProducts') { $reshook=$hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; + // load only one page of products + $sql.= $db->plimit($search_limit, $search_start); + $resql = $db->query($sql); if ($resql) { $rows = array(); diff --git a/htdocs/takepos/index.php b/htdocs/takepos/index.php index b23907b64f1..d934765b846 100644 --- a/htdocs/takepos/index.php +++ b/htdocs/takepos/index.php @@ -372,6 +372,9 @@ function LoadProducts(position, issubcat) { function MoreProducts(moreorless) { console.log("MoreProducts"); + + if ($('#search_pagination').val() != '') return Search2('', moreorless); + var maxproduct = ; if (moreorless=="more"){ @@ -556,12 +559,20 @@ function New() { * @param {int} keyCodeForEnter Key code for "enter" * return {void} */ -function Search2(keyCodeForEnter) { +function Search2(keyCodeForEnter, moreorless) { console.log("Search2 Call ajax search to replace products keyCodeForEnter="+keyCodeForEnter); + var search_term = $('#search').val(); + var search_start = 0; + var search_limit = ; + if (moreorless != null) { + search_term = $('#search_pagination').val(); + search_start = $('#search_start_'+moreorless).val(); + } + var search = false; var eventKeyCode = window.event.keyCode; - if (typeof keyCodeForEnter === 'undefined' || eventKeyCode == keyCodeForEnter) { + if (keyCodeForEnter == '' || eventKeyCode == keyCodeForEnter) { search = true; } @@ -576,7 +587,8 @@ function Search2(keyCodeForEnter) { pageproducts = 0; jQuery(".wrapper2 .catwatermark").hide(); - $.getJSON('/takepos/ajax/ajax.php?action=search&term=' + $('#search').val(), function (data) { + var nbsearchresults = 0; + $.getJSON('/takepos/ajax/ajax.php?action=search&term=' + search_term + '&search_start=' + search_start + '&search_limit=' + search_limit, function (data) { for (i = 0; i < ; i++) { if (typeof (data[i]) == "undefined") { $("#prodesc" + i).text(""); @@ -615,6 +627,7 @@ function Search2(keyCodeForEnter) { } $("#prodiv" + i).data("rowid", data[i]['rowid']); $("#prodiv" + i).data("iscat", 0); + nbsearchresults++; } }).always(function (data) { // If there is only 1 answer @@ -639,6 +652,24 @@ function Search2(keyCodeForEnter) { } else ClearSearch(); } + // memorize search_term and start for pagination + $("#search_pagination").val($("#search").val()); + if (search_start == 0) { + $("#prodiv span").hide(); + } + else { + $("#prodiv span").show(); + var search_start_less = Math.max(0, parseInt(search_start) - parseInt()); + $("#search_start_less").val(search_start_less); + } + if (nbsearchresults != ) { + $("#prodiv span").hide(); + } + else { + $("#prodiv span").show(); + var search_start_more = parseInt(search_start) + parseInt(); + $("#search_start_more").val(search_start_more); + } }); }, 500); // 500ms delay } @@ -915,7 +946,7 @@ if (empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
';
- echo '';
+ echo '';
} else {
if (!getDolGlobalString('TAKEPOS_HIDE_CATEGORY_IMAGES')) {
echo '
';
- print '';
+ print '';
} else {
if (getDolGlobalString('TAKEPOS_HIDE_PRODUCT_IMAGES')) {
echo '';
@@ -1309,6 +1340,9 @@ if (!empty($conf->global->TAKEPOS_WEIGHING_SCALE)) {
$count++;
}
?>
+
+
+