Replace generic alert, form and table templates with new Bootstrap equivalents
This commit is contained in:
@@ -3,56 +3,73 @@
|
||||
* TabularData.php
|
||||
* Contains the template that displays tabular data.
|
||||
*
|
||||
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
|
||||
* Global Data Lab code (C) Radboud University Nijmegen
|
||||
* Programming (C) Aaron van Geffen, 2015-2022
|
||||
*****************************************************************************/
|
||||
|
||||
class TabularData extends SubTemplate
|
||||
{
|
||||
private Pagination $pager;
|
||||
private GenericTable $_t;
|
||||
|
||||
public function __construct(GenericTable $table)
|
||||
{
|
||||
$this->_t = $table;
|
||||
|
||||
$pageIndex = $table->getPageIndex();
|
||||
if ($pageIndex)
|
||||
$this->pager = new Pagination($pageIndex);
|
||||
}
|
||||
|
||||
protected function html_content()
|
||||
{
|
||||
echo '
|
||||
<div class="admin_box">';
|
||||
|
||||
$title = $this->_t->getTitle();
|
||||
if (!empty($title))
|
||||
{
|
||||
$titleclass = $this->_t->getTitleClass();
|
||||
echo '
|
||||
<h2>', $title, '</h2>';
|
||||
<div class="generic-table', !empty($titleclass) ? ' ' . $titleclass : '', '">
|
||||
<h1>', htmlspecialchars($title), '</h1>';
|
||||
}
|
||||
|
||||
// Showing a page index?
|
||||
if (isset($this->pager))
|
||||
$this->pager->html_content();
|
||||
foreach ($this->_subtemplates as $template)
|
||||
$template->html_main();
|
||||
|
||||
// Maybe even a small form?
|
||||
if (isset($this->_t->form_above))
|
||||
$this->showForm($this->_t->form_above);
|
||||
// Showing an inline form?
|
||||
$pager = $this->_t->getPageIndex();
|
||||
if (!empty($pager) || isset($this->_t->form_above))
|
||||
{
|
||||
echo '
|
||||
<div class="row clearfix justify-content-end">';
|
||||
|
||||
// Page index?
|
||||
if (!empty($pager))
|
||||
PageIndexWidget::paginate($pager);
|
||||
|
||||
// Form controls?
|
||||
if (isset($this->_t->form_above))
|
||||
$this->showForm($this->_t->form_above);
|
||||
|
||||
echo '
|
||||
</div>';
|
||||
}
|
||||
|
||||
$tableClass = $this->_t->getTableClass();
|
||||
if ($tableClass)
|
||||
echo '
|
||||
<div class="', $tableClass, '">';
|
||||
|
||||
// Build the table!
|
||||
echo '
|
||||
<table class="table table-striped">
|
||||
<table class="table table-striped table-condensed">
|
||||
<thead>
|
||||
<tr>';
|
||||
|
||||
// Show the table's headers.
|
||||
foreach ($this->_t->getHeader() as $th)
|
||||
// Show all headers in their full glory!
|
||||
$header = $this->_t->getHeader();
|
||||
foreach ($header as $th)
|
||||
{
|
||||
echo '
|
||||
<th', (!empty($th['width']) ? ' width="' . $th['width'] . '"' : ''), (!empty($th['class']) ? ' class="' . $th['class'] . '"' : ''), ($th['colspan'] > 1 ? ' colspan="' . $th['colspan'] . '"' : ''), ' scope="', $th['scope'], '">',
|
||||
$th['href'] ? '<a href="' . $th['href'] . '">' . $th['label'] . '</a>' : $th['label'];
|
||||
|
||||
if ($th['sort_mode'] )
|
||||
echo ' ', $th['sort_mode'] === 'up' ? '↑' : '↓';
|
||||
if ($th['sort_mode'])
|
||||
echo ' <i class="bi bi-caret-' . ($th['sort_mode'] === 'down' ? 'down' : 'up') . '-fill"></i>';
|
||||
|
||||
echo '</th>';
|
||||
}
|
||||
@@ -62,7 +79,7 @@ class TabularData extends SubTemplate
|
||||
</thead>
|
||||
<tbody>';
|
||||
|
||||
// Show the table's body.
|
||||
// The body is what we came to see!
|
||||
$body = $this->_t->getBody();
|
||||
if (is_array($body))
|
||||
{
|
||||
@@ -72,51 +89,134 @@ class TabularData extends SubTemplate
|
||||
<tr', (!empty($tr['class']) ? ' class="' . $tr['class'] . '"' : ''), '>';
|
||||
|
||||
foreach ($tr['cells'] as $td)
|
||||
{
|
||||
echo '
|
||||
<td', (!empty($td['width']) ? ' width="' . $td['width'] . '"' : ''), '>', $td['value'], '</td>';
|
||||
<td', (!empty($td['width']) ? ' width="' . $td['width'] . '"' : ''), '>';
|
||||
|
||||
if (!empty($td['class']))
|
||||
echo '<span class="', $td['class'], '">', $td['value'], '</span>';
|
||||
else
|
||||
echo $td['value'];
|
||||
|
||||
echo '</td>';
|
||||
}
|
||||
|
||||
echo '
|
||||
</tr>';
|
||||
}
|
||||
}
|
||||
// !!! Sum colspan!
|
||||
else
|
||||
echo '
|
||||
<tr>
|
||||
<td colspan="', count($this->_t->getHeader()), '">', $body, '</td>
|
||||
<td colspan="', count($header), '" class="fullwidth">', $body, '</td>
|
||||
</tr>';
|
||||
|
||||
echo '
|
||||
</tbody>
|
||||
</table>';
|
||||
|
||||
// Maybe another small form?
|
||||
if (isset($this->_t->form_below))
|
||||
$this->showForm($this->_t->form_below);
|
||||
if ($tableClass)
|
||||
echo '
|
||||
</div>';
|
||||
|
||||
// Showing a page index?
|
||||
if (isset($this->pager))
|
||||
$this->pager->html_content();
|
||||
// Showing an inline form?
|
||||
if (!empty($pager) || isset($this->_t->form_below))
|
||||
{
|
||||
echo '
|
||||
<div class="row clearfix justify-content-end">';
|
||||
|
||||
echo '
|
||||
// Page index?
|
||||
if (!empty($pager))
|
||||
PageIndexWidget::paginate($pager);
|
||||
|
||||
// Form controls?
|
||||
if (isset($this->_t->form_below))
|
||||
$this->showForm($this->_t->form_below);
|
||||
|
||||
echo '
|
||||
</div>';
|
||||
}
|
||||
|
||||
if (!empty($title))
|
||||
echo '
|
||||
</div>';
|
||||
}
|
||||
|
||||
protected function showForm($form)
|
||||
{
|
||||
echo '
|
||||
<form action="', $form['action'], '" method="', $form['method'], '" class="table_form ', $form['class'], '">';
|
||||
<form action="', $form['action'], '" method="', $form['method'], '" class="', $form['class'], '">';
|
||||
|
||||
if (!empty($form['is_group']))
|
||||
echo '
|
||||
<div class="input-group">';
|
||||
|
||||
if (!empty($form['fields']))
|
||||
{
|
||||
foreach ($form['fields'] as $name => $field)
|
||||
echo '
|
||||
<input name="', $name, '" type="', $field['type'], '" placeholder="', $field['placeholder'], '"', isset($field['class']) ? ' class="' . $field['class'] . '"' : '', isset($field['value']) ? ' value="' . $field['value'] . '"' : '', '>';
|
||||
{
|
||||
if ($field['type'] === 'select')
|
||||
{
|
||||
echo '
|
||||
<select class="form-select" name="', $name, '"', (isset($field['onchange']) ? ' onchange="' . $field['onchange'] . '"' : ''), '>';
|
||||
|
||||
foreach ($field['values'] as $value => $caption)
|
||||
{
|
||||
if (!is_array($caption))
|
||||
{
|
||||
echo '
|
||||
<option value="', $value, '"', $value === $field['selected'] ? ' selected' : '', '>', $caption, '</option>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$label = $value;
|
||||
$options = $caption;
|
||||
|
||||
echo '
|
||||
<optgroup label="', $label, '">';
|
||||
|
||||
foreach ($options as $value => $caption)
|
||||
{
|
||||
echo '
|
||||
<option value="', $value, '"', $value === $field['selected'] ? ' selected' : '', '>', $caption, '</option>';
|
||||
}
|
||||
|
||||
echo '
|
||||
</optgroup>';
|
||||
}
|
||||
}
|
||||
|
||||
echo '
|
||||
</select>';
|
||||
}
|
||||
else
|
||||
echo '
|
||||
<input name="', $name, '" id="field_', $name, '" type="', $field['type'], '" placeholder="', $field['placeholder'], '" class="form-control', isset($field['class']) ? ' ' . $field['class'] : '', '"', isset($field['value']) ? ' value="' . htmlspecialchars($field['value']) . '"' : '', '>';
|
||||
|
||||
if (isset($field['html_after']))
|
||||
echo $field['html_after'];
|
||||
}
|
||||
}
|
||||
|
||||
echo '
|
||||
<input type="hidden" name="', Session::getSessionTokenKey(), '" value="', Session::getSessionToken(), '">';
|
||||
|
||||
if (!empty($form['buttons']))
|
||||
foreach ($form['buttons'] as $name => $button)
|
||||
{
|
||||
echo '
|
||||
<input name="', $name, '" type="', $button['type'], '" value="', $button['caption'], '" class="btn', isset($button['class']) ? ' ' . $button['class'] . '' : '', '">';
|
||||
<button class="btn ', isset($button['class']) ? $button['class'] : 'btn-primary', '" type="', $button['type'], '" name="', $name, '">', $button['caption'], '</button>';
|
||||
|
||||
if (isset($button['html_after']))
|
||||
echo $button['html_after'];
|
||||
}
|
||||
|
||||
if (!empty($form['is_group']))
|
||||
echo '
|
||||
</div>';
|
||||
|
||||
echo '
|
||||
</form>';
|
||||
</form>';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user