Merge pull request #20746 from altairisfr/pagin
NEW TakePos - pagination on search results
This commit is contained in:
commit
cc55b4444f
@ -48,6 +48,8 @@ $category = GETPOST('category', 'alphanohtml'); // Can be id of category or 'sup
|
|||||||
$action = GETPOST('action', 'aZ09');
|
$action = GETPOST('action', 'aZ09');
|
||||||
$term = GETPOST('term', 'alpha');
|
$term = GETPOST('term', 'alpha');
|
||||||
$id = GETPOST('id', 'int');
|
$id = GETPOST('id', 'int');
|
||||||
|
$search_start = GETPOST('search_start', 'int');
|
||||||
|
$search_limit = GETPOST('search_limit', 'int');
|
||||||
|
|
||||||
if (empty($user->rights->takepos->run)) {
|
if (empty($user->rights->takepos->run)) {
|
||||||
accessforbidden();
|
accessforbidden();
|
||||||
@ -232,6 +234,9 @@ if ($action == 'getProducts') {
|
|||||||
$reshook=$hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
|
$reshook=$hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= $hookmanager->resPrint;
|
$sql .= $hookmanager->resPrint;
|
||||||
|
|
||||||
|
// load only one page of products
|
||||||
|
$sql.= $db->plimit($search_limit, $search_start);
|
||||||
|
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
$rows = array();
|
$rows = array();
|
||||||
|
|||||||
@ -372,6 +372,9 @@ function LoadProducts(position, issubcat) {
|
|||||||
|
|
||||||
function MoreProducts(moreorless) {
|
function MoreProducts(moreorless) {
|
||||||
console.log("MoreProducts");
|
console.log("MoreProducts");
|
||||||
|
|
||||||
|
if ($('#search_pagination').val() != '') return Search2('<?php echo $keyCodeForEnter; ?>', moreorless);
|
||||||
|
|
||||||
var maxproduct = <?php echo ($MAXPRODUCT - 2); ?>;
|
var maxproduct = <?php echo ($MAXPRODUCT - 2); ?>;
|
||||||
|
|
||||||
if (moreorless=="more"){
|
if (moreorless=="more"){
|
||||||
@ -556,12 +559,20 @@ function New() {
|
|||||||
* @param {int} keyCodeForEnter Key code for "enter"
|
* @param {int} keyCodeForEnter Key code for "enter"
|
||||||
* return {void}
|
* return {void}
|
||||||
*/
|
*/
|
||||||
function Search2(keyCodeForEnter) {
|
function Search2(keyCodeForEnter, moreorless) {
|
||||||
console.log("Search2 Call ajax search to replace products keyCodeForEnter="+keyCodeForEnter);
|
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 search = false;
|
||||||
var eventKeyCode = window.event.keyCode;
|
var eventKeyCode = window.event.keyCode;
|
||||||
if (typeof keyCodeForEnter === 'undefined' || eventKeyCode == keyCodeForEnter) {
|
if (keyCodeForEnter == '' || eventKeyCode == keyCodeForEnter) {
|
||||||
search = true;
|
search = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -576,7 +587,8 @@ function Search2(keyCodeForEnter) {
|
|||||||
|
|
||||||
pageproducts = 0;
|
pageproducts = 0;
|
||||||
jQuery(".wrapper2 .catwatermark").hide();
|
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++) {
|
for (i = 0; i < <?php echo $MAXPRODUCT ?>; i++) {
|
||||||
if (typeof (data[i]) == "undefined") {
|
if (typeof (data[i]) == "undefined") {
|
||||||
$("#prodesc" + i).text("");
|
$("#prodesc" + i).text("");
|
||||||
@ -615,6 +627,7 @@ function Search2(keyCodeForEnter) {
|
|||||||
}
|
}
|
||||||
$("#prodiv" + i).data("rowid", data[i]['rowid']);
|
$("#prodiv" + i).data("rowid", data[i]['rowid']);
|
||||||
$("#prodiv" + i).data("iscat", 0);
|
$("#prodiv" + i).data("iscat", 0);
|
||||||
|
nbsearchresults++;
|
||||||
}
|
}
|
||||||
}).always(function (data) {
|
}).always(function (data) {
|
||||||
// If there is only 1 answer
|
// If there is only 1 answer
|
||||||
@ -639,6 +652,24 @@ function Search2(keyCodeForEnter) {
|
|||||||
}
|
}
|
||||||
else ClearSearch();
|
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
|
}, 500); // 500ms delay
|
||||||
}
|
}
|
||||||
@ -915,7 +946,7 @@ if (empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
|
|||||||
</div>
|
</div>
|
||||||
<div class="topnav-right">
|
<div class="topnav-right">
|
||||||
<div class="login_block_other">
|
<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 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 -->
|
<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>
|
<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)) {
|
if (!empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
|
||||||
print '<!-- Show the search input text -->'."\n";
|
print '<!-- Show the search input text -->'."\n";
|
||||||
print '<div class="margintoponly">';
|
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 '<a class="marginleftonly hideonsmartphone" onclick="ClearSearch();">'.img_picto('', 'searchclear').'</a>';
|
||||||
print '</div>';
|
print '</div>';
|
||||||
}
|
}
|
||||||
@ -1243,10 +1274,10 @@ if (!empty($conf->global->TAKEPOS_WEIGHING_SCALE)) {
|
|||||||
<?php
|
<?php
|
||||||
if ($count == ($MAXCATEG - 2)) {
|
if ($count == ($MAXCATEG - 2)) {
|
||||||
//echo '<img class="imgwrapper" src="img/arrow-prev-top.png" height="100%" id="catimg'.$count.'" />';
|
//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)) {
|
} elseif ($count == ($MAXCATEG - 1)) {
|
||||||
//echo '<img class="imgwrapper" src="img/arrow-next-top.png" height="100%" id="catimg'.$count.'" />';
|
//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 {
|
} else {
|
||||||
if (!getDolGlobalString('TAKEPOS_HIDE_CATEGORY_IMAGES')) {
|
if (!getDolGlobalString('TAKEPOS_HIDE_CATEGORY_IMAGES')) {
|
||||||
echo '<img class="imgwrapper" height="100%" id="catimg'.$count.'" />';
|
echo '<img class="imgwrapper" height="100%" id="catimg'.$count.'" />';
|
||||||
@ -1285,10 +1316,10 @@ if (!empty($conf->global->TAKEPOS_WEIGHING_SCALE)) {
|
|||||||
<?php
|
<?php
|
||||||
if ($count == ($MAXPRODUCT - 2)) {
|
if ($count == ($MAXPRODUCT - 2)) {
|
||||||
//echo '<img class="imgwrapper" src="img/arrow-prev-top.png" height="100%" id="proimg'.$count.'" />';
|
//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)) {
|
} elseif ($count == ($MAXPRODUCT - 1)) {
|
||||||
//echo '<img class="imgwrapper" src="img/arrow-next-top.png" height="100%" id="proimg'.$count.'" />';
|
//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 {
|
} else {
|
||||||
if (getDolGlobalString('TAKEPOS_HIDE_PRODUCT_IMAGES')) {
|
if (getDolGlobalString('TAKEPOS_HIDE_PRODUCT_IMAGES')) {
|
||||||
echo '<button type="button" id="probutton'.$count.'" class="productbutton" style="display: none;"></button>';
|
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++;
|
$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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user