From 0113d2e9c9ff34a6ffb10707cc76d34b67a0c367 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Mon, 19 Jan 2026 16:29:41 +0000
Subject: [PATCH] =Refactored window.getTemplate into a full templating class window.jvbTemplates. Refactored CRUD.js, UploadManager.js, FormController.js, PopulateForm.js with that in mind
---
inc/ui/CRUDSkeleton.php | 93 ++++++++++++++++++++++++++++++----------------
1 files changed, 61 insertions(+), 32 deletions(-)
diff --git a/inc/ui/CRUDSkeleton.php b/inc/ui/CRUDSkeleton.php
index 7347c63..521de4f 100644
--- a/inc/ui/CRUDSkeleton.php
+++ b/inc/ui/CRUDSkeleton.php
@@ -230,6 +230,20 @@
return $this;
}
+ protected function taxConfig(string $taxonomy, string $label = ''):array
+ {
+ $isVerified = jvbUserIsVerified();
+ $label = ($label === '') ? JVB_TAXONOMY[$taxonomy]['plural'] : $label;
+ return [
+ 'type' => 'taxonomy',
+ 'label' => $label,
+ 'taxonomy' => $taxonomy,
+ 'createNew' => $isVerified,
+ 'multiple' => true,
+ 'mode' => 'append',
+ ];
+ }
+
public function addSearch():self
{
$this->hasSearch = true;
@@ -590,17 +604,19 @@
protected function renderContent(): void {
$dataIgnore = $this->useCRUDjs ? '' : ' data-ignore';
?>
- <section class="items-list <?= esc_attr($this->dataType) ?> crud" data-content="<?= esc_attr($this->dataType) ?>" data-view="<?= $this->defaultView?>"<?=$dataIgnore?>>
- <?php
- $this->renderControlsAndFilters();
+ <section class="items-list <?= esc_attr($this->dataType) ?> crud" data-content="<?= esc_attr($this->dataType) ?>" data-singular="<?=$this->singular?>" data-plural="<?=$this->plural?>" data-view="<?= $this->defaultView?>"<?=$dataIgnore?>>
+ <div class="wrap">
+ <?php
+ $this->renderControlsAndFilters();
- if ($this->showBulkControls) {
- $this->renderBulkActions();
- }
- ?>
+ if ($this->showBulkControls) {
+ $this->renderBulkActions();
+ }
+ ?>
- <div class="<?= esc_attr($this->dataType) ?> item-grid" role="grid"></div>
- <div class="scroll-sentinel" aria-hidden="true"></div>
+ <div class="<?= esc_attr($this->dataType) ?> item-grid" role="grid"></div>
+ <div class="scroll-sentinel" aria-hidden="true"></div>
+ </div>
</section>
<?php
}
@@ -614,7 +630,7 @@
}
?>
<details class="all-filters col start" data-ignore>
- <summary>Filters</summary>
+ <summary>Filters <button hidden data-action="clear-filters" data-ignore><?=jvbIcon('x')?><span>Clear Filters</span></span></button></summary>
<?php
$this->renderSearch();
@@ -626,6 +642,7 @@
$this->renderColumnSelector();
}
?>
+ <button data-action="refresh" data-ignore><?=jvbIcon('arrows-clockwise')?><span>Hard Refresh</span></span></button>
</details>
<?php
}
@@ -733,8 +750,11 @@
$i = 0;
foreach ($option as $opt => $label) {
$icon = $opt === 'date' ? 'calendar' : $opt;
+ $value = $opt;
+ $value = ($value === 'sort-ascending') ? 'asc' : $value;
+ $value = ($value === 'sort-descending') ? 'desc' : $value;
?>
- <input id="<?=$opt?>" class="btn" type="radio" name="<?=$o?>" data-filter="<?=$o?>" value="<?=$opt?>"<?=$i===0 ? ' checked':''?>>
+ <input id="<?=$opt?>" class="btn" type="radio" name="<?=$o?>" data-filter="<?=$o?>" value="<?=$value?>"<?=$i===0 ? ' checked':''?>>
<label for="<?=$opt?>" title="<?=$label?>"><?=jvbDashIcon($icon)?></label>
<?php
@@ -808,11 +828,11 @@
<label for="date-start" class="col">
From
</label>
- <input type="date" id="date-start" class="date-start">
+ <input type="date" id="date-start" class="date-start" name="date-start">
<label for="date-end" class="col">
To
</label>
- <input type="date" id="date-end" class="date-end">
+ <input type="date" id="date-end" class="date-end" name="date-end">
</div>
<div class="month-picker">
<label>
@@ -856,7 +876,7 @@
$out = '';
if (!empty($terms)) {
$out .= sprintf(
- '<div class="row nowrap"><label for="filter-%s">%s<span class="screen-reader-text">Filter by %s</span></label>
+ '<div class="row nowrap"><label class="m-0" for="filter-%s">%s<span class="screen-reader-text">Filter by %s</span></label>
<select id="filter-%s" class="filter %s" name="%s" data-filter="taxonomies" data-taxonomy="%s">
<option value="">by %s</option>',
$taxonomy,
@@ -972,7 +992,7 @@
}
foreach ($this->taxonomies as $taxonomy => $config) {
?>
- <option value="tax-<?=$taxonomy?>">Add to <?= JVB_TAXONOMY[$taxonomy]['singular']??$config['label'] ?></option>
+ <option value="tax-<?=$taxonomy?>" data-type="selector" data-single="<?=JVB_TAXONOMY[$taxonomy]['singular']?>" data-plural="<?=JVB_TAXONOMY[$taxonomy]['plural']?>" data-taxonomy="<?=$taxonomy?>">Add to <?= JVB_TAXONOMY[$taxonomy]['singular']??$config['label'] ?></option>
<?php
}
?>
@@ -1093,8 +1113,8 @@
ob_start();
?>
<div class="item-select">
- <input type="checkbox" class="select-item">
- <label class="select-item-label">
+ <input type="checkbox" class="select-item" name="select-item" id="item">
+ <label class="select-item-label" for="item">
<span class="screen-reader-text">Select this <?= $this->singular ?></span>
</label>
</div>
@@ -1155,11 +1175,11 @@
<?= $this->renderItemSelect()?>
<?=$this->renderImage() ?>
<div class="col start w-full">
- <?= $this->renderItemActions()?>
<h3 data-field="post_title"></h3>
<p data-attr="date"></p>
<p data-field="price"></p>
<div data-field="post_excerpt"></div>
+ <?= $this->renderItemActions()?>
</div>
</div>
</template>
@@ -1242,6 +1262,10 @@
<?php
if (in_array('edit', $this->caps)) {
echo $makeThisDetailed ? '<details><summary class="row btw">See Value</summary>' : '';
+ if (in_array($config['type'], ['selector', 'taxonomy', 'post'])) {
+ $config['autocomplete'] = true;
+ }
+
echo $this->meta->render('form', $name, $config);
echo $makeThisDetailed ? '</details>' : '';
} else {
@@ -1320,6 +1344,11 @@
?>
<td class="field show-<?= esc_attr($name) ?>" data-field="<?= esc_attr($name) ?>" data-field-type="<?=$config['type']?>"<?=(in_array($name, $this->stuck)) ? ' data-stuck':''?>>
<?= $makeThisDetailed ? '<details><summary class="row btw">See Value</summary>' : '' ?>
+ <?php
+ if (in_array($config['type'], ['selector', 'taxonomy', 'post'])) {
+ $config['autocomplete'] = true;
+ }
+ ?>
<?php $this->meta->render('form', $name, $config); ?>
<?= $makeThisDetailed ? '</details>' : '' ?>
</td>
@@ -1452,10 +1481,10 @@
protected function renderStatusRadios(): string {
ob_start();
?>
- <div class="radio-options status-options row">
+ <div class="radio-options status-options row" data-field="post_status" data-field-type="radio">
<?php foreach ($this->statuses as $status):
if ($status === 'all') continue;
- if (!in_array($status, $this->allowedStatuses)) continue;
+ if (!array_key_exists($status, $this->allowedStatuses)) continue;
$config = $this->allowedStatuses[$status];
?>
@@ -1468,6 +1497,7 @@
<span class="screen-reader-text"><?= esc_html($config['label']) ?></span>
</label>
<?php endforeach; ?>
+ <span class="validation-message" hidden role="alert"></span>
</div>
<?php
return ob_get_clean();
@@ -1530,7 +1560,7 @@
<input type="hidden" name="form-id" value="<?=uniqid('new-')?>" />
<input type="hidden" name="content" value="<?=$this->dataType?>" />
<div class="fields">
- <div class="field-group radio-options row">
+ <div class="field-group radio-options row" data-field="post_status" data-field-type="radio">
<span>Status:</span>
<?php
$this->getApplicableStatuses('edit');
@@ -1585,7 +1615,6 @@
$temp = array_filter($fields, function ($field) {
return in_array($field, $this->timelineUniqueFields);
}, ARRAY_FILTER_USE_KEY);
-
$config = [
'type' => 'gallery',
'subtype' => 'timeline',
@@ -1596,6 +1625,9 @@
$content = '';
foreach ($fields as $slug=> $field) {
if (in_array($slug, $this->timelineSharedFields)) {
+ if (in_array($field['type'], ['taxonomy', 'selector'])) {
+ $field = array_merge($field, $this->taxConfig($field['taxonomy'], $field['label']));
+ }
$content .= $this->form->render($slug, null, $field, false, true);
}
}
@@ -1611,6 +1643,9 @@
$section = (array_key_exists('section', $config)) ? $config['section'] : 'basic';
$tabs[$section]['content'] .= $this->meta->render('form', $n, $config, false, true);
} else {
+ if (in_array($config['type'], ['taxonomy', 'selector'])) {
+ $config = array_merge($config, $this->taxConfig($config['taxonomy'], $config['label']));
+ }
$this->meta->render('form', $n, $config);
}
}
@@ -1656,17 +1691,11 @@
<div class="taxonomies">
<?php
foreach ($this->taxonomies as $taxonomy => $config) {
- $this->meta->render(
- 'form',
+ $this->form->renderSelectorField(
'bulk-edit-'.$taxonomy,
- [
- 'type' => 'taxonomy',
- 'label' => $config['label'],
- 'taxonomy' => $taxonomy,
- 'createNew' => jvbUserIsVerified(),
- 'multiple' => true,
- 'mode' => 'append'
- ]
+ '',
+ $this->taxConfig($taxonomy, $config['label']),
+ 'taxonomy'
);
}
?>
--
Gitblit v1.10.0