NEW Another way to navigate between pages for some lists

This commit is contained in:
Laurent Destailleur 2020-03-13 12:53:22 +01:00
parent 893ae21d3a
commit 52290b002a
5 changed files with 62 additions and 31 deletions

View File

@ -4281,14 +4281,15 @@ function load_fiche_titre($titre, $morehtmlright = '', $picto = 'generic', $pict
* @param int|string $totalnboflines Total number of records/lines for all pages (if known). Use a negative value of number to not show number. Use '' if unknown. * @param int|string $totalnboflines Total number of records/lines for all pages (if known). Use a negative value of number to not show number. Use '' if unknown.
* @param string $picto Icon to use before title (should be a 32x32 transparent png file) * @param string $picto Icon to use before title (should be a 32x32 transparent png file)
* @param int $pictoisfullpath 1=Icon name is a full absolute url of image * @param int $pictoisfullpath 1=Icon name is a full absolute url of image
* @param string $morehtmlright More html to show * @param string $morehtmlright More html to show
* @param string $morecss More css to the table * @param string $morecss More css to the table
* @param int $limit Max number of lines (-1 = use default, 0 = no limit, > 0 = limit). * @param int $limit Max number of lines (-1 = use default, 0 = no limit, > 0 = limit).
* @param int $hideselectlimit Force to hide select limit * @param int $hideselectlimit Force to hide select limit
* @param int $hidenavigation Force to hide all navigation tools * @param int $hidenavigation Force to hide all navigation tools
* @param int $pagenavastextinput 1=Do not suggest list of pages to navigate but suggest the page number into an input field.
* @return void * @return void
*/ */
function print_barre_liste($titre, $page, $file, $options = '', $sortfield = '', $sortorder = '', $morehtmlcenter = '', $num = -1, $totalnboflines = '', $picto = 'generic', $pictoisfullpath = 0, $morehtmlright = '', $morecss = '', $limit = -1, $hideselectlimit = 0, $hidenavigation = 0) function print_barre_liste($titre, $page, $file, $options = '', $sortfield = '', $sortorder = '', $morehtmlcenter = '', $num = -1, $totalnboflines = '', $picto = 'generic', $pictoisfullpath = 0, $morehtmlright = '', $morecss = '', $limit = -1, $hideselectlimit = 0, $hidenavigation = 0, $pagenavastextinput = 0)
{ {
global $conf, $langs; global $conf, $langs;
@ -4347,30 +4348,47 @@ function print_barre_liste($titre, $page, $file, $options = '', $sortfield = '',
if ($cpt >= 1) if ($cpt >= 1)
{ {
$pagelist .= '<li class="pagination"><a href="'.$file.'?page=0'.$options.'">1</a></li>'; if (empty($pagenavastextinput)) {
if ($cpt > 2) $pagelist .= '<li class="pagination"><span class="inactive">...</span></li>'; $pagelist .= '<li class="pagination"><a href="'.$file.'?page=0'.$options.'">1</a></li>';
elseif ($cpt == 2) $pagelist .= '<li class="pagination"><a href="'.$file.'?page=1'.$options.'">2</a></li>'; if ($cpt > 2) $pagelist .= '<li class="pagination"><span class="inactive">...</span></li>';
elseif ($cpt == 2) $pagelist .= '<li class="pagination"><a href="'.$file.'?page=1'.$options.'">2</a></li>';
}
} }
do do
{ {
if ($cpt == $page) if ($pagenavastextinput) {
{ if ($cpt == $page)
$pagelist .= '<li class="pagination"><span class="active">'.($page + 1).'</span></li>'; {
} $pagelist .= '<li class="pagination"><input type="text" class="width25 center pageplusone" name="pageplusone" value="'.($page + 1).'"></li>';
else if (($cpt + 1) < $nbpages) $pagelist .= '/';
{ }
$pagelist .= '<li class="pagination"><a href="'.$file.'?page='.$cpt.$options.'">'.($cpt + 1).'</a></li>'; } else {
if ($cpt == $page)
{
$pagelist .= '<li class="pagination"><span class="active">'.($page + 1).'</span></li>';
}
else
{
$pagelist .= '<li class="pagination"><a href="'.$file.'?page='.$cpt.$options.'">'.($cpt + 1).'</a></li>';
}
} }
$cpt++; $cpt++;
} }
while ($cpt < $nbpages && $cpt <= $page + $maxnbofpage); while ($cpt < $nbpages && $cpt <= ($page + $maxnbofpage));
if ($cpt < $nbpages) if (empty($pagenavastextinput)) {
{ if ($cpt < $nbpages)
if ($cpt < $nbpages - 2) $pagelist .= '<li class="pagination"><span class="inactive">...</span></li>'; {
elseif ($cpt == $nbpages - 2) $pagelist .= '<li class="pagination"><a href="'.$file.'?page='.($nbpages - 2).$options.'">'.($nbpages - 1).'</a></li>'; if ($cpt < $nbpages - 2) $pagelist .= '<li class="pagination"><span class="inactive">...</span></li>';
$pagelist .= '<li class="pagination"><a href="'.$file.'?page='.($nbpages - 1).$options.'">'.$nbpages.'</a></li>'; elseif ($cpt == $nbpages - 2) $pagelist .= '<li class="pagination"><a href="'.$file.'?page='.($nbpages - 2).$options.'">'.($nbpages - 1).'</a></li>';
$pagelist .= '<li class="pagination"><a href="'.$file.'?page='.($nbpages - 1).$options.'">'.$nbpages.'</a></li>';
}
} else {
//var_dump($page.' '.$cpt.' '.$nbpages);
if (($page + 1) < $nbpages) {
$pagelist .= '<li class="pagination"><a href="'.$file.'?page='.($nbpages - 1).$options.'">'.$nbpages.'</a></li>';
}
} }
} }
else else
@ -4383,6 +4401,11 @@ function print_barre_liste($titre, $page, $file, $options = '', $sortfield = '',
print_fleche_navigation($page, $file, $options, $nextpage, $pagelist, $morehtmlright, $savlimit, $totalnboflines, $hideselectlimit); // output the div and ul for previous/last completed with page numbers into $pagelist print_fleche_navigation($page, $file, $options, $nextpage, $pagelist, $morehtmlright, $savlimit, $totalnboflines, $hideselectlimit); // output the div and ul for previous/last completed with page numbers into $pagelist
} }
// js to autoselect page field on focus
if ($pagenavastextinput) {
print ajax_autoselect('.pageplusone');
}
print '</td>'; print '</td>';
print '</tr></table>'."\n"; print '</tr></table>'."\n";
@ -8019,7 +8042,7 @@ function getAdvancedPreviewUrl($modulepart, $relativepath, $alldata = 0, $param
/** /**
* Make content of an input box selected when we click into input field. * Make content of an input box selected when we click into input field.
* *
* @param string $htmlname Id of html object * @param string $htmlname Id of html object ('#idvalue' or '.classvalue')
* @param string $addlink Add a 'link to' after * @param string $addlink Add a 'link to' after
* @return string * @return string
*/ */
@ -8028,7 +8051,7 @@ function ajax_autoselect($htmlname, $addlink = '')
global $langs; global $langs;
$out = '<script> $out = '<script>
jQuery(document).ready(function () { jQuery(document).ready(function () {
jQuery("#'.$htmlname.'").click(function() { jQuery(this).select(); } ); jQuery("'.((strpos($htmlname, '.') === 0 ? '' : '#').$htmlname).'").click(function() { jQuery(this).select(); } );
}); });
</script>'; </script>';
if ($addlink) $out .= ' <a href="'.$addlink.'" target="_blank">'.$langs->trans("Link").'</a>'; if ($addlink) $out .= ' <a href="'.$addlink.'" target="_blank">'.$langs->trans("Link").'</a>';

View File

@ -85,8 +85,8 @@ $id = GETPOST('id', 'int');
$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'alpha'); $sortfield = GETPOST('sortfield', 'alpha');
$sortorder = GETPOST('sortorder', 'alpha'); $sortorder = GETPOST('sortorder', 'alpha');
$page = GETPOST('page', 'int'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters
$offset = $limit * $page; $offset = $limit * $page;
$pageprev = $page - 1; $pageprev = $page - 1;
$pagenext = $page + 1; $pagenext = $page + 1;
@ -372,7 +372,7 @@ print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
$newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/mymodule/myobject_card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd); $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/mymodule/myobject_card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_companies', 0, $newcardbutton, '', $limit); print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_companies', 0, $newcardbutton, '', $limit, 0, 0, 1);
// Add code for pre mass action (confirmation or email presend form) // Add code for pre mass action (confirmation or email presend form)
$topicmail = "SendMyObjectRef"; $topicmail = "SendMyObjectRef";

View File

@ -97,8 +97,6 @@ $search_type = GETPOST('search_type', 'alpha');
$search_level = GETPOST("search_level", "array"); $search_level = GETPOST("search_level", "array");
$search_stcomm = GETPOST('search_stcomm', 'int'); $search_stcomm = GETPOST('search_stcomm', 'int');
$search_import_key = GETPOST("search_import_key", "alpha"); $search_import_key = GETPOST("search_import_key", "alpha");
$search_btn = GETPOST('button_search', 'alpha');
$search_remove_btn = GETPOST('button_removefilter', 'alpha');
$search_parent_name = GETPOST('search_parent_name', 'alpha'); $search_parent_name = GETPOST('search_parent_name', 'alpha');
$type = GETPOST('type', 'alpha'); $type = GETPOST('type', 'alpha');
@ -110,10 +108,10 @@ $diroutputmassaction = $conf->societe->dir_output.'/temp/massgeneration/'.$user-
$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha'); $sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOST("page", 'int'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (!$sortorder) $sortorder = "ASC"; if (!$sortorder) $sortorder = "ASC";
if (!$sortfield) $sortfield = "s.nom"; if (!$sortfield) $sortfield = "s.nom";
if (empty($page) || $page == -1 || !empty($search_btn) || !empty($search_remove_btn) || (empty($toselect) && $massaction === '0')) { $page = 0; } if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
$offset = $limit * $page; $offset = $limit * $page;
$pageprev = $page - 1; $pageprev = $page - 1;
$pagenext = $page + 1; $pagenext = $page + 1;
@ -619,10 +617,10 @@ print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">'; print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">'; print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">'; print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
print '<input type="hidden" name="page" value="'.$page.'">'; //print '<input type="hidden" name="page" value="'.$page.'">';
print '<input type="hidden" name="contextpage" value="'.$contextpage.'">'; print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'building', 0, $newcardbutton, '', $limit); print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'building', 0, $newcardbutton, '', $limit, 0, 0, 1);
$langs->load("other"); $langs->load("other");
$textprofid = array(); $textprofid = array();

View File

@ -311,10 +311,15 @@ td.rightborder {
td.actionbuttons a { td.actionbuttons a {
padding-left: 6px; padding-left: 6px;
} }
select.flat, form.flat select { select.flat, form.flat select, .pageplusone {
font-weight: normal; font-weight: normal;
font-size: unset; font-size: unset;
} }
input.pageplusone {
padding-bottom: 4px;
padding-top: 4px;
}
.optionblue { .optionblue {
color: var(--colortextlink); color: var(--colortextlink);
} }

View File

@ -448,11 +448,16 @@ td.rightborder {
td.actionbuttons a { td.actionbuttons a {
padding-left: 6px; padding-left: 6px;
} }
select.flat, form.flat select { select.flat, form.flat select, .pageplusone {
font-weight: normal; font-weight: normal;
font-size: unset; font-size: unset;
height: 2em; height: 2em;
} }
input.pageplusone {
padding-bottom: 4px;
padding-top: 4px;
}
.optionblue { .optionblue {
color: rgb(<?php echo $colortextlink; ?>); color: rgb(<?php echo $colortextlink; ?>);
} }