forked from Public/pics
Merge branch 'inline-forms'
This commit is contained in:
commit
2b8b12e065
@ -18,8 +18,7 @@ class ManageAlbums extends HTMLController
|
||||
'form' => [
|
||||
'action' => BASEURL . '/editalbum/',
|
||||
'method' => 'get',
|
||||
'class' => 'col-md-6 text-end',
|
||||
'buttons' => [
|
||||
'controls' => [
|
||||
'add' => [
|
||||
'type' => 'submit',
|
||||
'caption' => 'Add new album',
|
||||
@ -58,7 +57,6 @@ class ManageAlbums extends HTMLController
|
||||
'title' => 'Manage albums',
|
||||
'no_items_label' => 'No albums meet the requirements of the current filter.',
|
||||
'items_per_page' => 9999,
|
||||
'index_class' => 'col-md-6',
|
||||
'base_url' => BASEURL . '/managealbums/',
|
||||
'get_data' => function($offset, $limit, $order, $direction) {
|
||||
return Tag::getOffset($offset, $limit, $order, $direction, true);
|
||||
|
@ -23,9 +23,8 @@ class ManageAssets extends HTMLController
|
||||
'form' => [
|
||||
'action' => BASEURL . '/manageassets/?' . Session::getSessionTokenKey() . '=' . Session::getSessionToken(),
|
||||
'method' => 'post',
|
||||
'class' => 'col-md-6 text-end',
|
||||
'is_embed' => true,
|
||||
'buttons' => [
|
||||
'controls' => [
|
||||
'deleteChecked' => [
|
||||
'type' => 'submit',
|
||||
'caption' => 'Delete checked',
|
||||
@ -113,7 +112,6 @@ class ManageAssets extends HTMLController
|
||||
'title' => 'Manage assets',
|
||||
'no_items_label' => 'No assets meet the requirements of the current filter.',
|
||||
'items_per_page' => 30,
|
||||
'index_class' => 'col-md-6',
|
||||
'base_url' => BASEURL . '/manageassets/',
|
||||
'get_data' => 'Asset::getOffset',
|
||||
'get_count' => 'Asset::getCount',
|
||||
|
@ -29,8 +29,7 @@ class ManageErrors extends HTMLController
|
||||
'form' => [
|
||||
'action' => BASEURL . '/manageerrors/?' . Session::getSessionTokenKey() . '=' . Session::getSessionToken(),
|
||||
'method' => 'post',
|
||||
'class' => 'col-md-6 text-end',
|
||||
'buttons' => [
|
||||
'controls' => [
|
||||
'clear' => [
|
||||
'type' => 'submit',
|
||||
'caption' => 'Delete all',
|
||||
@ -95,7 +94,6 @@ class ManageErrors extends HTMLController
|
||||
'sort_direction' => $_GET['dir'] ?? '',
|
||||
'no_items_label' => "No errors to display -- we're all good!",
|
||||
'items_per_page' => 20,
|
||||
'index_class' => 'col-md-6',
|
||||
'base_url' => BASEURL . '/manageerrors/',
|
||||
'get_count' => 'ErrorLog::getCount',
|
||||
'get_data' => 'ErrorLog::getOffset',
|
||||
|
@ -20,8 +20,7 @@ class ManageTags extends HTMLController
|
||||
'form' => [
|
||||
'action' => BASEURL . '/edittag/',
|
||||
'method' => 'get',
|
||||
'class' => 'col-md-6 text-end',
|
||||
'buttons' => [
|
||||
'controls' => [
|
||||
'add' => [
|
||||
'type' => 'submit',
|
||||
'caption' => 'Add new tag',
|
||||
@ -70,8 +69,7 @@ class ManageTags extends HTMLController
|
||||
'sort_direction' => $_GET['dir'] ?? '',
|
||||
'title' => 'Manage tags',
|
||||
'no_items_label' => 'No tags meet the requirements of the current filter.',
|
||||
'items_per_page' => 30,
|
||||
'index_class' => 'col-md-6',
|
||||
'items_per_page' => 9999,
|
||||
'base_url' => BASEURL . '/managetags/',
|
||||
'get_data' => function($offset, $limit, $order, $direction) {
|
||||
return Tag::getOffset($offset, $limit, $order, $direction, false);
|
||||
|
@ -20,8 +20,7 @@ class ManageUsers extends HTMLController
|
||||
'form' => [
|
||||
'action' => BASEURL . '/edituser/',
|
||||
'method' => 'get',
|
||||
'class' => 'col-md-6 text-end',
|
||||
'buttons' => [
|
||||
'controls' => [
|
||||
'add' => [
|
||||
'type' => 'submit',
|
||||
'caption' => 'Add new user',
|
||||
@ -86,7 +85,6 @@ class ManageUsers extends HTMLController
|
||||
'title' => 'Manage users',
|
||||
'no_items_label' => 'No users meet the requirements of the current filter.',
|
||||
'items_per_page' => 30,
|
||||
'index_class' => 'col-md-6',
|
||||
'base_url' => BASEURL . '/manageusers/',
|
||||
'get_data' => 'Member::getOffset',
|
||||
'get_count' => 'Member::getCount',
|
||||
|
105
templates/InlineFormView.php
Normal file
105
templates/InlineFormView.php
Normal file
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
/*****************************************************************************
|
||||
* InlineFormView.php
|
||||
* Contains the template that renders inline forms.
|
||||
*
|
||||
* Kabuki CMS (C) 2013-2025, Aaron van Geffen
|
||||
*****************************************************************************/
|
||||
|
||||
class InlineFormView
|
||||
{
|
||||
public static function renderInlineForm($form)
|
||||
{
|
||||
if (!isset($form['is_embed']))
|
||||
echo '
|
||||
<form action="', $form['action'], '" method="', $form['method'], '" class="', $form['class'] ?? '', '">';
|
||||
else
|
||||
echo '
|
||||
<div class="', $form['class'] ?? '', '">';
|
||||
|
||||
if (!empty($form['is_group']))
|
||||
echo '
|
||||
<div class="input-group">';
|
||||
|
||||
foreach ($form['controls'] as $name => $control)
|
||||
{
|
||||
if ($control['type'] === 'select')
|
||||
self::renderSelectBox($control, $name);
|
||||
elseif ($control['type'] === 'submit')
|
||||
self::renderSubmitButton($control, $name);
|
||||
else
|
||||
self::renderInputBox($control, $name);
|
||||
}
|
||||
|
||||
echo '
|
||||
<input type="hidden" name="', Session::getSessionTokenKey(), '" value="', Session::getSessionToken(), '">';
|
||||
|
||||
if (!empty($form['is_group']))
|
||||
echo '
|
||||
</div>';
|
||||
|
||||
if (!isset($form['is_embed']))
|
||||
echo '
|
||||
</form>';
|
||||
else
|
||||
echo '
|
||||
</div>';
|
||||
}
|
||||
|
||||
private static function renderInputBox(array $field, $name)
|
||||
{
|
||||
echo '
|
||||
<input name="', $name, '" id="field_', $name, '" type="', $field['type'], '" ',
|
||||
'class="form-control', isset($field['class']) ? ' ' . $field['class'] : '', '"',
|
||||
isset($field['placeholder']) ? ' placeholder="' . $field['placeholder'] . '"' : '',
|
||||
isset($field['value']) ? ' value="' . htmlspecialchars($field['value']) . '"' : '', '>';
|
||||
}
|
||||
|
||||
private static function renderSelectBox(array $field, $name)
|
||||
{
|
||||
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>';
|
||||
}
|
||||
|
||||
private static function renderSubmitButton(array $button, $name)
|
||||
{
|
||||
echo '
|
||||
<button class="btn ', isset($button['class']) ? $button['class'] : 'btn-primary', '" ',
|
||||
'type="', $button['type'], '" name="', $name, '"';
|
||||
|
||||
if (isset($button['onclick']))
|
||||
echo ' onclick="', $button['onclick'], '"';
|
||||
|
||||
echo '>', $button['caption'], '</button>';
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
* TabularData.php
|
||||
* Contains the template that displays tabular data.
|
||||
*
|
||||
* Kabuki CMS (C) 2013-2023, Aaron van Geffen
|
||||
* Kabuki CMS (C) 2013-2025, Aaron van Geffen
|
||||
*****************************************************************************/
|
||||
|
||||
class TabularData extends SubTemplate
|
||||
@ -68,18 +68,34 @@ class TabularData extends SubTemplate
|
||||
}
|
||||
}
|
||||
|
||||
protected function renderPaginationForm($pager, $form, $class='row')
|
||||
protected function renderPaginationForm($pager, $form)
|
||||
{
|
||||
echo '
|
||||
<div class="', $class, ' clearfix justify-content-end">';
|
||||
<div class="row clearfix justify-content-end">';
|
||||
|
||||
// Page index?
|
||||
if (!empty($pager))
|
||||
{
|
||||
echo '
|
||||
<div class="col-md">';
|
||||
|
||||
PageIndexWidget::paginate($pager);
|
||||
|
||||
echo '
|
||||
</div>';
|
||||
}
|
||||
|
||||
// Form controls?
|
||||
if (isset($form))
|
||||
$this->renderInlineForm($form);
|
||||
{
|
||||
echo '
|
||||
<div class="col-md-auto">';
|
||||
|
||||
InlineFormView::renderInlineForm($form);
|
||||
|
||||
echo '
|
||||
</div>';
|
||||
}
|
||||
|
||||
echo '
|
||||
</div>';
|
||||
@ -146,94 +162,4 @@ class TabularData extends SubTemplate
|
||||
echo '
|
||||
</tbody>';
|
||||
}
|
||||
|
||||
protected function renderInlineForm($form)
|
||||
{
|
||||
if (!isset($form['is_embed']))
|
||||
echo '
|
||||
<form action="', $form['action'], '" method="', $form['method'], '" class="', $form['class'], '">';
|
||||
else
|
||||
echo '
|
||||
<div class="', $form['class'], '">';
|
||||
|
||||
if (!empty($form['is_group']))
|
||||
echo '
|
||||
<div class="input-group">';
|
||||
|
||||
if (!empty($form['fields']))
|
||||
{
|
||||
foreach ($form['fields'] as $name => $field)
|
||||
{
|
||||
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 '
|
||||
<button class="btn ', isset($button['class']) ? $button['class'] : 'btn-primary', '" type="', $button['type'], '" name="', $name, '"';
|
||||
|
||||
if (isset($button['onclick']))
|
||||
echo ' onclick="', $button['onclick'], '"';
|
||||
|
||||
echo '>', $button['caption'], '</button>';
|
||||
|
||||
if (isset($button['html_after']))
|
||||
echo $button['html_after'];
|
||||
}
|
||||
|
||||
if (!empty($form['is_group']))
|
||||
echo '
|
||||
</div>';
|
||||
|
||||
if (!isset($form['is_embed']))
|
||||
echo '
|
||||
</form>';
|
||||
else
|
||||
echo '
|
||||
</div>';
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user