NEW Can select dynamicaly number of lines to show on page

This commit is contained in:
Laurent Destailleur
2016-02-10 19:28:10 +01:00
parent ab2ac26f17
commit 9b41e11a1e
4 changed files with 62 additions and 34 deletions

View File

@@ -695,6 +695,7 @@ if ($resql)
}
$param='&socid='.$socid;
if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
if ($month) $param.='&month='.$month;
if ($year) $param.='&year=' .$year;
if ($search_ref) $param.='&search_ref=' .$search_ref;

View File

@@ -2961,25 +2961,26 @@ function load_fiche_titre($titre, $mesg='', $picto='title_generic.png', $pictois
* @param string $options parametres complementaires lien ('' par defaut)
* @param string $sortfield champ de tri ('' par defaut)
* @param string $sortorder ordre de tri ('' par defaut)
* @param string $center chaine du centre ('' par defaut)
* @param string $center chaine du centre ('' par defaut). We often find here string $massaction comming from $form->selectMassAction()
* @param int $num number of records found by select with limit+1
* @param int $totalnboflines Total number of records/lines for all pages (if known)
* @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 string $morehtml More html to show
* @param string $morecss More css to the table
* @param int $limit Max number of lines
* @param int $limit Max number of lines (-1 = use default, 0 = no limit, > 0 = limit)
* @return void
*/
function print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $center='', $num=-1, $totalnboflines=0, $picto='title_generic.png', $pictoisfullpath=0, $morehtml='', $morecss='', $limit=0)
function print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $center='', $num=-1, $totalnboflines=0, $picto='title_generic.png', $pictoisfullpath=0, $morehtml='', $morecss='', $limit=-1)
{
global $conf,$langs;
$savlimit = $limit;
if ($picto == 'setup') $picto='title_setup.png';
if (($conf->browser->name == 'ie') && $picto=='title_generic.png') $picto='title.gif';
if ($limit < 1) $limit = $conf->liste_limit;
if (($num > $limit) || ($num == -1))
if ($limit < 0) $limit = $conf->liste_limit;
if ($savlimit >= 0 && (($num > $limit) || ($num == -1) || ($limit == 0)))
{
$nextpage = 1;
}
@@ -3012,13 +3013,14 @@ function print_barre_liste($titre, $page, $file, $options='', $sortfield='', $so
if ($sortorder) $options .= "&amp;sortorder=".$sortorder;
// Show navigation bar
$pagelist = '';
if ($page > 0 || $num > $limit)
if ($savlimit != 0 && ($page > 0 || $num > $limit))
{
if ($totalnboflines) // If we know total nb of lines
{
$maxnbofpage=(empty($conf->dol_optimize_smallscreen) ? 6 : 3); // page nb before and after selected page + ... + first or last
$maxnbofpage=(empty($conf->dol_optimize_smallscreen) ? 4 : 2); // page nb before and after selected page + ... + first or last
$nbpages=ceil($totalnboflines/$limit);
if ($limit > 0) $nbpages=ceil($totalnboflines/$limit);
else $nbpages=1;
$cpt=($page-$maxnbofpage);
if ($cpt < 0) { $cpt=0; }
@@ -3055,7 +3057,7 @@ function print_barre_liste($titre, $page, $file, $options='', $sortfield='', $so
$pagelist.= '<li'.(empty($conf->dol_use_jmobile)?' class="pagination"':'').'><span '.(empty($conf->dol_use_jmobile)?'class="active"':'data-role="button"').'>'.($page+1)."</li>";
}
}
print_fleche_navigation($page, $file, $options, $nextpage, $pagelist, $morehtml, $limit, $totalnboflines); // output the div and ul for previous/last completed with page numbers into $pagelist
print_fleche_navigation($page, $file, $options, $nextpage, $pagelist, $morehtml, $savlimit, $totalnboflines); // output the div and ul for previous/last completed with page numbers into $pagelist
print '</td>';
print '</tr></table>'."\n";
@@ -3071,22 +3073,30 @@ function print_barre_liste($titre, $page, $file, $options='', $sortfield='', $so
* @param integer $nextpage Do we show a next page button
* @param string $betweenarrows HTML content to show between arrows. MUST contains '<li> </li>' tags or '<li><span> </span></li>'.
* @param string $afterarrows HTML content to show after arrows. Must NOT contains '<li> </li>' tags.
* @param string $limit Max nb of record to show ('' = unknown = default, '0' = no limit, 'x' = limit)
* @param int $limit Max nb of record to show (-1 = no combo with limit, 0 = no limit, > 0 = limit)
* @param int $totalnboflines Total number of records/lines for all pages (if known)
* @return void
*/
function print_fleche_navigation($page, $file, $options='', $nextpage=0, $betweenarrows='', $afterarrows='', $limit='', $totalnboflines=0)
function print_fleche_navigation($page, $file, $options='', $nextpage=0, $betweenarrows='', $afterarrows='', $limit=-1, $totalnboflines=0)
{
global $conf, $langs;
print '<div class="pagination"><ul>';
if ($limit != '')
if ((int) $limit >= 0)
{
$pagesizechoices='10:10,20:20,30:30,50:50,100:100,250:250,500:500,1000:1000,0:'.$langs->trans("All");
$pagesizechoices='10:10,20:20,30:30,40:40,50:50,100:100,250:250,500:500,1000:1000,5000:5000';
//$pagesizechoices.=',0:'.$langs->trans("All"); // Not yet supported
//$pagesizechoices.=',2:2';
if (! empty($conf->global->MAIN_PAGESIZE_CHOICES)) $pagesizechoices=$conf->global->MAIN_PAGESIZE_CHOICES;
print '<li class="pagination"><select class="flat selectlimit" name="limit">';
print '<li class="pagination">';
print '<select class="flat selectlimit" name="limit">';
$tmpchoice=explode(',',$pagesizechoices);
$tmpkey=$limit.':'.$limit;
if (! in_array($tmpkey, $tmpchoice)) $tmpchoice[]=$tmpkey;
$tmpkey=$conf->liste_limit.':'.$conf->liste_limit;
if (! in_array($tmpkey, $tmpchoice)) $tmpchoice[]=$tmpkey;
asort($tmpchoice, SORT_NUMERIC);
$found=false;
foreach($tmpchoice as $val)
{
@@ -3096,7 +3106,7 @@ function print_fleche_navigation($page, $file, $options='', $nextpage=0, $betwee
$val=$tmp[1];
if ($key != '' && $val != '')
{
if ($key == $limit)
if ((int) $key == (int) $limit)
{
$selected = ' selected="selected"';
$found = true;
@@ -3105,6 +3115,19 @@ function print_fleche_navigation($page, $file, $options='', $nextpage=0, $betwee
}
}
print '</select>';
if ($conf->use_javascript_ajax)
{
print '<!-- JS CODE TO ENABLE select limit to launch submit of page -->
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery(".selectlimit").change(function() {
console.log("Change limit. Send submit");
$(this).parents(\'form:first\').submit();
});
});
</script>
';
}
print '</li>';
}
if ($page > 0)

View File

@@ -144,7 +144,8 @@ $nav.=$form->select_date($dateselect, 'dateselect', 0, 0, 1, '', 1, 0, 1);
$nav.=' <input type="submit" name="submitdateselect" class="button" value="'.$langs->trans("Refresh").'">';
$nav.='</form>';
print_barre_liste('Title of my list', 3, $_SERVER["PHP_SELF"], '', '', '', 'Text in middle', 20, 5000, '', 0, $nav);
$limit=10;
print_barre_liste('Title of my list', 12, $_SERVER["PHP_SELF"], '', '', '', 'Text in middle', 20, 500, '', 0, $nav, '', $limit);
$moreforfilter.='<div class="divsearchfield">';
@@ -190,6 +191,7 @@ if (! empty($moreforfilter))
</tr>
<tr class="pair"><td><?php echo $productspecimen->getNomUrl(1); ?></td><td align="right">b1</td><td class="tdlineupdown" align="left">c1</td></tr>
<tr class="impair"><td>a2</td><td align="right">b2</td><td class="tdlineupdown" align="left">c2</td></tr>
<tr class="pair"><td>a3</td><td align="right">b3</td><td class="tdlineupdown" align="left">c3</td></tr>
</table>
<br>

View File

@@ -149,7 +149,7 @@ $arrayfields=array(
's.code_compta_fournisseur'=>array('label'=>$langs->trans("SupplierAccountancyCodeShort"), 'checked'=>$checkedsupplieraccountcode, 'enabled'=>(! empty($conf->fournisseur->enabled))),
's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>1),
's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1),
'state.state_name'=>array('label'=>$langs->trans("State"), 'checked'=>0),
'state.nom'=>array('label'=>$langs->trans("State"), 'checked'=>0),
'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0),
'typent.code'=>array('label'=>$langs->trans("ThirdPartyType"), 'checked'=>$checkedtypetiers),
's.siren'=>array('label'=>$langs->trans("ProfId1Short"), 'checked'=>$checkedprofid1),
@@ -427,7 +427,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
}
$sql.= $db->order($sortfield,$sortorder);
$sql.= $db->plimit($conf->liste_limit+1, $offset);
$sql.= $db->plimit($limit+1, $offset);
$resql = $db->query($sql);
if ($resql)
@@ -435,7 +435,9 @@ if ($resql)
$num = $db->num_rows($resql);
$i = 0;
if ($sall != '') $param = "&amp;sall=".urlencode($sall);
$param='';
if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
if ($sall != '') $param .= "&amp;sall=".urlencode($sall);
if ($search_categ != '') $param.='&amp;search_categ='.urlencode($search_categ);
if ($search_sale > 0) $param.='&amp;search_sale='.urlencode($search_sale);
if ($search_nom != '') $param.= "&amp;search_nom=".urlencode($search_nom);
@@ -470,14 +472,21 @@ if ($resql)
if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val);
}
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_companies');
// Show delete result message
if (GETPOST('delsoc'))
{
setEventMessages($langs->trans("CompanyDeleted",GETPOST('delsoc')), null, 'mesgs');
}
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_companies', 0, '', '', $limit);
$langs->load("other");
$textprofid=array();
foreach(array(1,2,3,4,5,6) as $key)
@@ -491,13 +500,6 @@ if ($resql)
}
}
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
if ($search_all)
{
foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
@@ -560,7 +562,7 @@ if ($resql)
if (! empty($arrayfields['s.code_compta_fournisseur']['checked'])) print_liste_field_titre($arrayfields['s.code_compta_fournisseur']['label'],$_SERVER["PHP_SELF"],"s.code_compta_fournisseur","",$param,'',$sortfield,$sortorder);
if (! empty($arrayfields['s.town']['checked'])) print_liste_field_titre($langs->trans("Town"),$_SERVER["PHP_SELF"],"s.town","",$param,'',$sortfield,$sortorder);
if (! empty($arrayfields['s.zip']['checked'])) print_liste_field_titre($langs->trans("Zip"),$_SERVER["PHP_SELF"],"s.zip","",$param,'',$sortfield,$sortorder);
if (! empty($arrayfields['state.state_name']['checked'])) print_liste_field_titre($langs->trans("StateShort"),$_SERVER["PHP_SELF"],"state.state_name","",$param,'',$sortfield,$sortorder);
if (! empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($langs->trans("StateShort"),$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
if (! empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($langs->trans("Country"),$_SERVER["PHP_SELF"],"country.code_iso","",$param,'align="center"',$sortfield,$sortorder);
if (! empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($langs->trans("ThirdPartyType"),$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
if (! empty($arrayfields['s.siren']['checked'])) print_liste_field_titre($form->textwithpicto($langs->trans("ProfId1Short"),$textprofid[1],1,0),$_SERVER["PHP_SELF"],"s.siren","",$param,'class="nowrap"',$sortfield,$sortorder);
@@ -653,7 +655,7 @@ if ($resql)
print '</td>';
}
// State
if (! empty($arrayfields['state.state_name']['checked']))
if (! empty($arrayfields['state.nom']['checked']))
{
print '<td class="liste_titre">';
print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
@@ -872,7 +874,7 @@ if ($resql)
print "<td>".$obj->zip."</td>\n";
}
// State
if (! empty($arrayfields['state.state_name']['checked']))
if (! empty($arrayfields['state.nom']['checked']))
{
print "<td>".$obj->state_name."</td>\n";
}