NEW : Rework of the webportal list for more flexibility and more templating

This commit is contained in:
Kamel Khelifa 2025-09-29 14:19:11 +02:00
parent efd5e48f78
commit 297818c775
11 changed files with 1046 additions and 690 deletions

View file

@ -0,0 +1,39 @@
<!-- file list-additional-filters.tpl.php -->
<?php
/* Copyright (C) 2025 Open-Dsi <support@open-dsi.fr>
*/
// Protection to avoid direct call of template
if (empty($context) || !is_object($context)) {
print "Error, template page can't be called as URL";
exit(1);
}
'@phan-var-force Context $context';
/**
* @var Conf $conf
* @var HookManager $hookmanager
* @var Translate $langs
* @var Context $context
* @var Controller $this
* @var FormListWebPortal $formList
*/
$formList = $this->formList;
// Filters
$moreforfilter = '';
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $context);
if (empty($reshook)) {
$moreforfilter .= $hookmanager->resPrint;
} else {
$moreforfilter = $hookmanager->resPrint;
}
?>
<?php if (!empty($moreforfilter)) { ?>
<div id="webportal-<?php print dolPrintHTMLForAttribute($formList->object->element) ?>-additional-filters" class="centpercent">
<?php print $moreforfilter ?>
</div>
<?php } ?>

View file

@ -0,0 +1,64 @@
<!-- file list-filters.tpl.php -->
<?php
/* Copyright (C) 2025 Open-Dsi <support@open-dsi.fr>
*/
// Protection to avoid direct call of template
if (empty($context) || !is_object($context)) {
print "Error, template page can't be called as URL";
exit(1);
}
'@phan-var-force Context $context';
/**
* @var Conf $conf
* @var HookManager $hookmanager
* @var Translate $langs
* @var Context $context
* @var Controller $this
* @var FormListWebPortal $formList
*/
$formList = $this->formList;
?>
<tr role="search-row">
<td data-col="row-checkbox">
<button class="btn-filter-icon btn-search-filters-icon" type="submit" name="button_search_x" value="x" aria-label="<?php print dolPrintHTMLForAttribute((string) $langs->trans('Search')) ?>"></button>
<button class="btn-filter-icon btn-remove-search-filters-icon" type="submit" name="button_removefilter_x" value="x" aria-label="<?php print dolPrintHTMLForAttribute((string) $langs->trans('RemoveSearchFilters')) ?>"></button>
</td>
<?php foreach ($formList->object->fields as $key => $val) {
$alias = $val['alias'] ?? 't.';
if (array_key_exists($alias . $key, $formList->arrayfields) && !empty($formList->arrayfields[$alias . $key]['checked'])) {
$cssforfield = $formList->getClasseCssList($key, $val);
if ($key == 'status') $cssforfield .= ' parentonrightofpage';
?>
<td <?php print empty($cssforfield) ? '' : 'class="' . dolPrintHTMLForAttribute($cssforfield) . '" ' ?>data-label="<?php print dolPrintHTMLForAttribute((string) $formList->arrayfields[$alias . $key]['label']) ?>" data-col="<?php print dolPrintHTMLForAttribute((string) $key) ?>">
<?php print $formList->printSearchInput($key, $val) ?>
</td>
<?php }
}
// Fields from hook
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $context);
print $hookmanager->resPrint;
// Remain to pay
if (array_key_exists('remain_to_pay', $formList->arrayfields) && !empty($formList->arrayfields['remain_to_pay']['checked'])) { ?>
<td data-label="<?php print dolPrintHTMLForAttribute((string) $formList->arrayfields['remain_to_pay']['label']) ?>">
</td>
<?php }
// Download link
if (array_key_exists('download_link', $formList->arrayfields) && !empty($formList->arrayfields['download_link']['checked'])) { ?>
<td data-label="<?php print dolPrintHTMLForAttribute((string) $formList->arrayfields['download_link']['label']) ?>">
</td>
<?php }
// Signature link
if (array_key_exists('signature_link', $formList->arrayfields) && !empty($formList->arrayfields['signature_link']['checked'])) { ?>
<td data-label="<?php print dolPrintHTMLForAttribute((string) $formList->arrayfields['signature_link']['label']) ?>">
</td>
<?php } ?>
</tr>

View file

@ -0,0 +1,24 @@
<!-- file list-footer.tpl.php -->
<?php
/* Copyright (C) 2025 Open-Dsi <support@open-dsi.fr>
*/
// Protection to avoid direct call of template
if (empty($context) || !is_object($context)) {
print "Error, template page can't be called as URL";
exit(1);
}
'@phan-var-force Context $context';
/**
* @var Conf $conf
* @var HookManager $hookmanager
* @var Translate $langs
* @var Context $context
* @var Controller $this
* @var FormListWebPortal $formList
*/
$formList = $this->formList;
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $context); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;

View file

@ -0,0 +1,112 @@
<!-- file list-lines.tpl.php -->
<?php
/* Copyright (C) 2025 Open-Dsi <support@open-dsi.fr>
*/
// Protection to avoid direct call of template
if (empty($context) || !is_object($context)) {
print "Error, template page can't be called as URL";
exit(1);
}
'@phan-var-force Context $context';
/**
* @var Conf $conf
* @var HookManager $hookmanager
* @var Translate $langs
* @var Context $context
* @var Controller $this
* @var FormListWebPortal $formList
*/
$formList = $this->formList;
if (!empty($formList->records)) {
$totalarray = [
'nbfield' => 0,
'totalizable' => [],
];
foreach ($formList->records as $i => $record) {
// Store properties in $object
$formList->setVarsFromFetchObj($record); ?>
<tr data-rowid="<?php print dolPrintHTMLForAttribute((string) $formList->object->id) ?>">
<td></td>
<?php $formList->setTotalValue('', [], $record, $i, $totalarray) ?>
<?php foreach ($formList->object->fields as $key => $val) {
$alias = $val['alias'] ?? 't.';
if (array_key_exists($alias . $key, $formList->arrayfields) && !empty($formList->arrayfields[$alias . $key]['checked'])) {
$cssforfield = $formList->getClasseCssList($key, $val, true);
if (preg_match('/tdoverflow/', $cssforfield)) $cssforfield .= ' classfortooltip';
$title = '';
if (preg_match('/tdoverflow/', $cssforfield) && !is_numeric($formList->object->$key)) {
$title = ' title="' . dolPrintHTMLForAttribute((string) $formList->object->$key) . '"';
}
?>
<td <?php print (empty($cssforfield) ? '' : 'class="' . dolPrintHTMLForAttribute($cssforfield) . '" '); print $title ?>data-label="<?php print dolPrintHTMLForAttribute((string) $formList->arrayfields[$alias . $key]['label']) ?>" data-col="<?php print dolPrintHTMLForAttribute((string) $key) ?>">
<?php print $formList->printValue($key, $val, $record, $i, $totalarray);
$formList->setTotalValue($key, $val, $record, $i, $totalarray) ?>
</td>
<?php }
}
// Fields from hook
$parameters = array('record' => $record, 'i' => $i, 'totalarray' => &$totalarray);
$reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $context);
print $hookmanager->resPrint;
// Remain to pay
if (array_key_exists('remain_to_pay', $formList->arrayfields) && !empty($formList->arrayfields['remain_to_pay']['checked'])) { ?>
<td class="nowraponall" data-label="<?php print dolPrintHTMLForAttribute((string) $formList->arrayfields['remain_to_pay']['label']) ?>" data-col="remain_to_pay">
<?php print $formList->printValue('remain_to_pay', [], $record, $i, $totalarray);
$formList->setTotalValue('remain_to_pay', [], $record, $i, $totalarray) ?>
</td>
<?php }
// Download link
if (array_key_exists('download_link', $formList->arrayfields) && !empty($formList->arrayfields['download_link']['checked'])) { ?>
<td data-label="<?php print dolPrintHTMLForAttribute((string) $formList->arrayfields['download_link']['label']) ?>" data-col="download_link">
<?php print $formList->printValue('download_link', [], $record, $i, $totalarray);
$formList->setTotalValue('download_link', [], $record, $i, $totalarray) ?>
</td>
<?php }
// Signature link
if (array_key_exists('signature_link', $formList->arrayfields) && !empty($formList->arrayfields['signature_link']['checked'])) { ?>
<td data-label="<?php print dolPrintHTMLForAttribute((string) $formList->arrayfields['signature_link']['label']) ?>" data-col="signature_link">
<?php print $formList->printValue('signature_link', [], $record, $i, $totalarray);
$formList->setTotalValue('signature_link', [], $record, $i, $totalarray) ?>
</td>
<?php } ?>
</tr>
<?php }
// Move fields of totalizable into the common array pos and val
if (!empty($totalarray['totalizable']) && is_array($totalarray['totalizable'])) {
foreach ($totalarray['totalizable'] as $keytotalizable => $valtotalizable) {
$totalarray['pos'][$valtotalizable['pos']] = $keytotalizable;
$totalarray['val'][$keytotalizable] = isset($valtotalizable['total']) ? $valtotalizable['total'] : 0;
}
}
// Show total line
if (isset($totalarray['pos'])) { ?>
<tr>
<?php $i = 0;
while ($i < $totalarray['nbfield']) {
$i++;
if (!empty($totalarray['pos'][$i])) { ?>
<td class="nowraponall essai">
<?php print price(!empty($totalarray['val'][$totalarray['pos'][$i]]) ? $totalarray['val'][$totalarray['pos'][$i]] : 0) ?>
</td>
<?php } else {
if ($i == 1) { ?>
<td><?php print $langs->trans("Total") ?></td>
<?php } else { ?>
<td></td>
<?php }
}
} ?>
</tr>
<?php }
} else { // If no record found ?>
<tr><td colspan="<?php print $formList->nbColumn ?>"><span class="opacitymedium"><?php print $langs->trans("NoRecordFound") ?></span></td></tr>
<?php } ?>

View file

@ -0,0 +1,73 @@
<!-- file list-nav.tpl.php -->
<?php
/* Copyright (C) 2025 Open-Dsi <support@open-dsi.fr>
*/
// Protection to avoid direct call of template
if (empty($context) || !is_object($context)) {
print "Error, template page can't be called as URL";
exit(1);
}
'@phan-var-force Context $context';
/**
* @var Conf $conf
* @var HookManager $hookmanager
* @var Translate $langs
* @var Context $context
* @var Controller $this
* @var FormListWebPortal $formList
*/
$formList = $this->formList;
// Get nb pages
$nbPages = 0;
if ($formList->limit > 0) {
$nbPages = ceil($formList->nbtotalofrecords / $formList->limit);
}
if ($nbPages <= 0) {
$nbPages = 1;
}
$maxPaginationItem = min($nbPages, 5);
$minPageNum = max(1, $formList->page - 3);
$maxPageNum = min($nbPages, $formList->page + 3);
$params = $formList->params . '&amp;sortfield=' . $formList->sortfield . '&amp;sortorder=' . $formList->sortorder;
$params = preg_replace('/^(&|&amp;)/i', '', $params); // remove first & or &amp;
$url = $context->getControllerUrl($context->controller);
$url .= (preg_match('/\?/', $url) ? '&amp;' : '?') . $params;
?>
<input type="hidden" name="page" value="<?php print dolPrintHTMLForAttribute((string) $formList->page) ?>">
<nav id="webportal-<?php print dolPrintHTMLForAttribute($formList->object->element) ?>-pagination">
<ul>
<li><strong><?php print $langs->trans($formList->titleKey) ?></strong> (<?php print $formList->nbtotalofrecords ?>)</li>
</ul>
<?php if ($nbPages > 1) { ?>
<ul class="pages-nav-list">
<?php if ($formList->page > 1) { ?>
<li><a class="pages-nav-list__icon --prev" aria-label="<?php print dolPrintHTMLForAttribute((string) $langs->trans('AriaPrevPage')) ?>" href="<?php print $url . '&amp;page=' . ($formList->page - 1) ?>"<?php // print ($formList->page <= 1 ? ' disabled' : '') ?>></a></li>
<?php } ?>
<?php if ($minPageNum > 1) { ?>
<li><a class="pages-nav-list__link <?php print ($formList->page == 1 ? '--active' : '') ?>" aria-label="<?php print dolPrintHTMLForAttribute((string) $langs->trans('AriaPageX', 1)) ?>" href="<?php print $url . '&amp;page=1' ?>">1</a></li>
<li>&hellip;</li>
<?php } ?>
<?php for ($p = $minPageNum; $p <= $maxPageNum; $p++) { ?>
<li><a class="pages-nav-list__link <?php print ($formList->page === $p ? '--active' : '') ?>" aria-label="<?php print dolPrintHTMLForAttribute((string) $langs->trans('AriaPageX', $p)) ?>" href="<?php print $url . '&amp;page=' . $p ?>"><?php print $p ?></a></li>
<?php } ?>
<?php if ($maxPaginationItem < $nbPages) { ?>
<li>&hellip;</li>
<li><a class="pages-nav-list__link <?php print ($formList->page == $nbPages ? '--active' : '') ?>" aria-label="<?php print dolPrintHTMLForAttribute((string) $langs->trans('AriaPageX', $nbPages)) ?>" href="<?php print $url . '&amp;page=' . $nbPages ?>"><?php print $nbPages ?></a></li>
<?php } ?>
<?php if ($formList->page < $nbPages) { ?>
<li><a class="pages-nav-list__icon --next" aria-label="<?php print dolPrintHTMLForAttribute((string) $langs->trans('AriaNextPage')) ?>" href="<?php print $url . '&amp;page=' . ($formList->page + 1) ?>"<?php // print ($formList->page >= $nbPages ? ' disabled' : '') ?>></a></li>
<?php } ?>
</ul>
<?php } ?>
</nav>

View file

@ -0,0 +1,74 @@
<!-- file list-titles.tpl.php -->
<?php
/* Copyright (C) 2025 Open-Dsi <support@open-dsi.fr>
*/
// Protection to avoid direct call of template
if (empty($context) || !is_object($context)) {
print "Error, template page can't be called as URL";
exit(1);
}
'@phan-var-force Context $context';
/**
* @var Conf $conf
* @var HookManager $hookmanager
* @var Translate $langs
* @var Context $context
* @var Controller $this
* @var FormListWebPortal $formList
*/
$formList = &$this->formList;
$url = $context->getControllerUrl($context->controller);
$url .= (preg_match('/\?/', $url) ? '&amp;' : '?') . preg_replace('/^(&|&amp;)/i', '', $formList->params/* . "&amp;page=" . urlencode($formList->page)*/);
// Make array[sort field => sort order] for this list
$sortList = array_combine(explode(",", $formList->sortfield), explode(",", $formList->sortorder));
$formList->nbColumn = 0;
?>
<!-- Fields title label -->
<tr>
<th data-col="row-checkbox"></th>
<?php $formList->nbColumn++ ?>
<?php foreach ($formList->object->fields as $key => $val) {
$alias = $val['alias'] ?? 't.';
if (array_key_exists($alias . $key, $formList->arrayfields) && !empty($formList->arrayfields[$alias . $key]['checked'])) {
$order = array_key_exists($alias . $key, $sortList) ? strtolower(trim($sortList[$alias . $key])) : '';
$link_url = $url . '&amp;sortfield=' . urlencode($alias . $key) . '&amp;sortorder=' . ($order == 'desc' ? 'asc' : 'desc');
$cssforfield = $formList->getClasseCssList($key, $val);
$cssforfield = preg_replace('/small\s*/', '', $cssforfield);
?>
<th <?php print empty($cssforfield) ? '' : 'class="' . dolPrintHTMLForAttribute($cssforfield) . '" ' ?>data-col="<?php print dolPrintHTMLForAttribute((string) $key) ?>" scope="col"<?php print (!empty($order) ? ' table-order="' . dolPrintHTMLForAttribute($order) . '"' : '') ?>>
<a href="<?php print dolPrintHTMLForAttribute($link_url) ?>"><?php print $langs->trans((string) $formList->arrayfields[$alias . $key]['label']) ?></a>
</th>
<?php $formList->nbColumn++;
}
}
// Hook fields
$parameters = array('sortList' => $sortList);
$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $context);
print $hookmanager->resPrint;
// Remain to pay
if (array_key_exists('remain_to_pay', $formList->arrayfields) && !empty($formList->arrayfields['remain_to_pay']['checked'])) { ?>
<th scope="col"><?php print $langs->trans((string) $formList->arrayfields['remain_to_pay']['label']) ?></th>
<?php $formList->nbColumn++;
}
// Download link
if (array_key_exists('download_link', $formList->arrayfields) && !empty($formList->arrayfields['download_link']['checked'])) { ?>
<th scope="col"><?php print $langs->trans((string) $formList->arrayfields['download_link']['label']) ?></th>
<?php $formList->nbColumn++;
}
// Signature link
if (array_key_exists('signature_link', $formList->arrayfields) && !empty($formList->arrayfields['signature_link']['checked'])) { ?>
<th scope="col"><?php print $langs->trans((string) $formList->arrayfields['signature_link']['label']) ?></th>
<?php $formList->nbColumn++;
} ?>
</tr>

View file

@ -0,0 +1,51 @@
<!-- file list.tpl.php -->
<?php
/* Copyright (C) 2025 Open-Dsi <support@open-dsi.fr>
*/
// Protection to avoid direct call of template
if (empty($context) || !is_object($context)) {
print "Error, template page can't be called as URL";
exit(1);
}
'@phan-var-force Context $context';
/**
* @var Conf $conf
* @var HookManager $hookmanager
* @var Translate $langs
* @var Context $context
* @var Controller $this
* @var FormListWebPortal $formList
*/
$formList = $this->formList;
?>
<form method="POST" id="searchFormList" action="<?php print $context->getControllerUrl($context->controller) ?>">
<?php print $context->getFormToken() ?>
<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">
<input type="hidden" name="action" value="list">
<input type="hidden" name="sortfield" value="<?php print dolPrintHTMLForAttribute($formList->sortfield) ?>">
<input type="hidden" name="sortorder" value="<?php print dolPrintHTMLForAttribute($formList->sortorder) ?>">
<input type="hidden" name="contextpage" value="<?php print dolPrintHTMLForAttribute($formList->contextpage) ?>">
<?php $this->loadTemplate('list-nav') ?>
<?php $this->loadTemplate('list-additional-filters') ?>
<table id="webportal-<?php print dolPrintHTMLForAttribute($formList->object->element) ?>-list" responsive="scroll" role="grid">
<thead>
<?php $this->loadTemplate('list-filters') ?>
<?php $this->loadTemplate('list-titles') ?>
</thead>
<tbody>
<?php $this->loadTemplate('list-lines') ?>
</tbody>
<tfoot>
<?php $this->loadTemplate('list-footer') ?>
</tfoot>
</table>
</form>

File diff suppressed because it is too large Load diff

View file

@ -70,16 +70,25 @@ class InvoiceListController extends Controller
$context->menu_active[] = 'invoice_list';
// set form list
$formListWebPortal = new FormListWebPortal($this->db);
$formListWebPortal->init('invoice');
$this->formList = new FormListWebPortal($this->db);
$this->formList->init($this, 'invoice');
// hook for action
$hookRes = $this->hookDoAction();
if (empty($hookRes)) {
$formListWebPortal->doActions();
$this->formList->doActions();
}
$this->formList = $formListWebPortal;
$this->formList->setSqlRequest();
// filter on logged third-party
$this->formList->sql_body .= " AND t.fk_soc = " . ((int) $context->logged_thirdparty->id);
// discard record with status draft
$this->formList->sql_body .= " AND t.fk_statut <> 0";
$this->formList->loadRecords();
$this->formList->setParams();
$this->formList->setColumnsVisibility();
return 1;
}
@ -105,7 +114,7 @@ class InvoiceListController extends Controller
if (empty($hookRes)) {
print '<main class="container">';
//print '<figure>';
print $this->formList->elementList($context);
$this->loadTemplate('list');
//print '</figure>';
print '</main>';
}

View file

@ -71,16 +71,25 @@ class OrderListController extends Controller
$context->menu_active[] = 'order_list';
// set form list
$formListWebPortal = new FormListWebPortal($this->db);
$formListWebPortal->init('order');
$this->formList = new FormListWebPortal($this->db);
$this->formList->init($this, 'order');
// hook for action
$hookRes = $this->hookDoAction();
if (empty($hookRes)) {
$formListWebPortal->doActions();
$this->formList->doActions();
}
$this->formList = $formListWebPortal;
$this->formList->setSqlRequest();
// filter on logged third-party
$this->formList->sql_body .= " AND t.fk_soc = " . ((int) $context->logged_thirdparty->id);
// discard record with status draft
$this->formList->sql_body .= " AND t.fk_statut <> 0";
$this->formList->loadRecords();
$this->formList->setParams();
$this->formList->setColumnsVisibility();
return 1;
}
@ -106,7 +115,7 @@ class OrderListController extends Controller
if (empty($hookRes)) {
print '<main class="container">';
//print '<figure>';
print $this->formList->elementList($context);
$this->loadTemplate('list');
//print '</figure>';
print '</main>';
}

View file

@ -74,16 +74,25 @@ class PropalListController extends Controller
$context->menu_active[] = 'propal_list';
// set form list
$formListWebPortal = new FormListWebPortal($this->db);
$formListWebPortal->init('propal');
$this->formList = new FormListWebPortal($this->db);
$this->formList->init($this, 'propal');
// hook for action
$hookRes = $this->hookDoAction();
if (empty($hookRes)) {
$formListWebPortal->doActions();
$this->formList->doActions();
}
$this->formList = $formListWebPortal;
$this->formList->setSqlRequest();
// filter on logged third-party
$this->formList->sql_body .= " AND t.fk_soc = " . ((int) $context->logged_thirdparty->id);
// discard record with status draft
$this->formList->sql_body .= " AND t.fk_statut <> 0";
$this->formList->loadRecords();
$this->formList->setParams();
$this->formList->setColumnsVisibility();
return 1;
}
@ -109,7 +118,7 @@ class PropalListController extends Controller
if (empty($hookRes)) {
print '<main class="container">';
//print '<figure>';
print $this->formList->elementList($context);
$this->loadTemplate('list');
//print '</figure>';
print '</main>';
}