Merge pull request #20746 from altairisfr/pagin

NEW TakePos - pagination on search results
This commit is contained in:
Laurent Destailleur 2022-04-29 15:59:50 +02:00 committed by GitHub
commit cc55b4444f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 9 deletions

View File

@ -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();

View File

@ -372,6 +372,9 @@ function LoadProducts(position, issubcat) {
function MoreProducts(moreorless) {
console.log("MoreProducts");
if ($('#search_pagination').val() != '') return Search2('<?php echo $keyCodeForEnter; ?>', moreorless);
var maxproduct = <?php echo ($MAXPRODUCT - 2); ?>;
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 = <?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;
}
@ -576,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("");
@ -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<?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
}
@ -915,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>
@ -1210,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>';
}
@ -1243,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.'" />';
@ -1285,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>';
@ -1309,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>