FIX pagination on search results

This commit is contained in:
Christophe Battarel 2022-04-29 10:00:25 +02:00
parent 78f46bb98b
commit fb076a9282

View File

@ -559,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 = <?php echo $MAXPRODUCT - 2; ?>;
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;
}
@ -579,7 +587,8 @@ function Search2(keyCodeForEnter) {
pageproducts = 0;
jQuery(".wrapper2 .catwatermark").hide();
$.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=search&term=' + $('#search').val(), function (data) {
var nbsearchresults = 0;
$.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=search&term=' + search_term + '&search_start=' + search_start + '&search_limit=' + search_limit, function (data) {
for (i = 0; i < <?php echo $MAXPRODUCT ?>; i++) {
if (typeof (data[i]) == "undefined") {
$("#prodesc" + i).text("");
@ -618,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
@ -642,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<?php echo $MAXPRODUCT - 2; ?> span").hide();
}
else {
$("#prodiv<?php echo $MAXPRODUCT - 2; ?> span").show();
var search_start_less = Math.max(0, parseInt(search_start) - parseInt(<?php echo $MAXPRODUCT - 2;?>));
$("#search_start_less").val(search_start_less);
}
if (nbsearchresults != <?php echo $MAXPRODUCT - 2; ?>) {
$("#prodiv<?php echo $MAXPRODUCT - 1; ?> span").hide();
}
else {
$("#prodiv<?php echo $MAXPRODUCT - 1; ?> span").show();
var search_start_more = parseInt(search_start) + parseInt(<?php echo $MAXPRODUCT - 2;?>);
$("#search_start_more").val(search_start_more);
}
});
}, 500); // 500ms delay
}
@ -918,7 +946,7 @@ if (empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
</div>
<div class="topnav-right">
<div class="login_block_other">
<input type="text" id="search" name="search" class="input-search-takepos" onkeyup="Search2(<?php echo $keyCodeForEnter; ?>);" placeholder="<?php echo dol_escape_htmltag($langs->trans("Search")); ?>" autofocus>
<input type="text" id="search" name="search" class="input-search-takepos" onkeyup="Search2('<?php echo $keyCodeForEnter; ?>', null);" placeholder="<?php echo dol_escape_htmltag($langs->trans("Search")); ?>" autofocus>
<a onclick="ClearSearch();"><span class="fa fa-backspace"></span></a>
<a href="<?php echo DOL_URL_ROOT.'/'; ?>" target="backoffice" rel="opener"><!-- we need rel="opener" here, we are on same domain and we need to be able to reuse this tab several times -->
<span class="fas fa-home"></span></a>
@ -1213,7 +1241,7 @@ if (!empty($conf->global->TAKEPOS_WEIGHING_SCALE)) {
if (!empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
print '<!-- Show the search input text -->'."\n";
print '<div class="margintoponly">';
print '<input type="text" id="search" class="input-search-takepos" name="search" onkeyup="Search2('.$keyCodeForEnter.');" style="width: 80%; width:calc(100% - 51px); font-size: 150%;" placeholder="'.dol_escape_htmltag($langs->trans("Search")).'" autofocus> ';
print '<input type="text" id="search" class="input-search-takepos" name="search" onkeyup="Search2(\"'.$keyCodeForEnter.'\", null);" style="width: 80%; width:calc(100% - 51px); font-size: 150%;" placeholder="'.dol_escape_htmltag($langs->trans("Search")).'" autofocus> ';
print '<a class="marginleftonly hideonsmartphone" onclick="ClearSearch();">'.img_picto('', 'searchclear').'</a>';
print '</div>';
}
@ -1246,10 +1274,10 @@ if (!empty($conf->global->TAKEPOS_WEIGHING_SCALE)) {
<?php
if ($count == ($MAXCATEG - 2)) {
//echo '<img class="imgwrapper" src="img/arrow-prev-top.png" height="100%" id="catimg'.$count.'" />';
echo '<span class="fa fa-chevron-left centerinmiddle" style="font-size: 5em;"></span>';
echo '<span class="fa fa-chevron-left centerinmiddle" style="font-size: 5em; cursor: pointer;"></span>';
} elseif ($count == ($MAXCATEG - 1)) {
//echo '<img class="imgwrapper" src="img/arrow-next-top.png" height="100%" id="catimg'.$count.'" />';
echo '<span class="fa fa-chevron-right centerinmiddle" style="font-size: 5em;"></span>';
echo '<span class="fa fa-chevron-right centerinmiddle" style="font-size: 5em; cursor: pointer;"></span>';
} else {
if (!getDolGlobalString('TAKEPOS_HIDE_CATEGORY_IMAGES')) {
echo '<img class="imgwrapper" height="100%" id="catimg'.$count.'" />';
@ -1288,10 +1316,10 @@ if (!empty($conf->global->TAKEPOS_WEIGHING_SCALE)) {
<?php
if ($count == ($MAXPRODUCT - 2)) {
//echo '<img class="imgwrapper" src="img/arrow-prev-top.png" height="100%" id="proimg'.$count.'" />';
print '<span class="fa fa-chevron-left centerinmiddle" style="font-size: 5em;"></span>';
print '<span class="fa fa-chevron-left centerinmiddle" style="font-size: 5em; cursor: pointer;"></span>';
} elseif ($count == ($MAXPRODUCT - 1)) {
//echo '<img class="imgwrapper" src="img/arrow-next-top.png" height="100%" id="proimg'.$count.'" />';
print '<span class="fa fa-chevron-right centerinmiddle" style="font-size: 5em;"></span>';
print '<span class="fa fa-chevron-right centerinmiddle" style="font-size: 5em; cursor: pointer;"></span>';
} else {
if (getDolGlobalString('TAKEPOS_HIDE_PRODUCT_IMAGES')) {
echo '<button type="button" id="probutton'.$count.'" class="productbutton" style="display: none;"></button>';
@ -1312,6 +1340,9 @@ if (!empty($conf->global->TAKEPOS_WEIGHING_SCALE)) {
$count++;
}
?>
<input type="hidden" id="search_start_less" value="0">
<input type="hidden" id="search_start_more" value="0">
<input type="hidden" id="search_pagination" value="">
</div>
</div>
</div>