From 474109a5df0a06f5343ab184838fe2d80e3872a8 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 11 Jan 2026 19:23:20 +0000
Subject: [PATCH] =Fixed timeline CRUD.js issue where this.activeItem was set null when we still needed it

---
 inc/ui/CRUDSkeleton.php |   90 +++++++++++++++++++++++++++-----------------
 1 files changed, 55 insertions(+), 35 deletions(-)

diff --git a/inc/ui/CRUDSkeleton.php b/inc/ui/CRUDSkeleton.php
index 8390fc3..ecef889 100644
--- a/inc/ui/CRUDSkeleton.php
+++ b/inc/ui/CRUDSkeleton.php
@@ -36,7 +36,7 @@
 	protected string $dataType = '';
 	protected string $singular = '';
 	protected string $plural = '';
-	protected string $icon = 'triangle';
+	protected string $icon;
 
 	// Capabilities
 	protected array $caps = [];
@@ -134,6 +134,7 @@
 	protected array $additionalClasses = [];
 
 	public function __construct() {
+		$this->icon = jvbDefaultIcon();
 		$this->user = wp_get_current_user();
 		$this->user_id = $this->user->ID;
 	}
@@ -229,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;
@@ -238,7 +253,7 @@
 	/**
 	 * Add a view type (grid, table, list, timeline)
 	 */
-	public function addViews(?array $views):self
+	public function addViews(?array $views = null):self
 	{
 		if (!$views) {
 			$views = $this->defaultViews;
@@ -589,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
 	}
@@ -612,7 +629,8 @@
 			return;
 		}
 		?>
-		<div class="all-filters col start" data-ignore>
+		<details class="all-filters col start" data-ignore>
+			<summary>Filters <button hidden data-action="clear-filters" data-ignore><?=jvbIcon('x')?><span>Clear Filters</span></span></button></summary>
 			<?php
 
 			$this->renderSearch();
@@ -624,7 +642,8 @@
 				$this->renderColumnSelector();
 			}
 			?>
-		</div>
+			<button data-action="refresh" data-ignore><?=jvbIcon('arrows-clockwise')?><span>Hard Refresh</span></span></button>
+		</details>
 		<?php
 	}
 
@@ -731,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
@@ -806,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>
@@ -854,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,
@@ -970,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
 				}
 				?>
@@ -1111,7 +1133,7 @@
 		}
 		ob_start();
 		?>
-		<div class="item-actions">
+		<div class="item-actions row btw abs">
 			<?php
 			foreach ($this->itemActions as $action) {
 				$config = $this->defaultItemActions[$action];
@@ -1153,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>
@@ -1583,7 +1605,6 @@
 					$temp = array_filter($fields, function ($field) {
 						return in_array($field, $this->timelineUniqueFields);
 					}, ARRAY_FILTER_USE_KEY);
-
 					$config = [
 						'type'		=> 'gallery',
 						'subtype'	=> 'timeline',
@@ -1594,6 +1615,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);
 						}
 					}
@@ -1609,6 +1633,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);
 					}
 				}
@@ -1654,17 +1681,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'
 							);
 						}
 						?>
@@ -1698,7 +1719,7 @@
 
 	protected function getApplicableStatuses(string $prefix) {
 		foreach ($this->statuses as $status) {
-			if ($status === 'all' || !in_array($status, $this->allowedStatuses)) {
+			if ($status === 'all' || !array_key_exists($status, $this->allowedStatuses)) {
 				continue;
 			}
 			$config = $this->allowedStatuses[$status];
@@ -1721,9 +1742,8 @@
 				   value="<?= esc_attr($status)?>"
 				   id="<?=$prefix?>set-<?= esc_attr($status) ?>"
 				<?= $disabled?>>
-			<label for="<?=$prefix?>set-<?=esc_attr($status)?>">
-				<?= jvbDashIcon($config['icon'], ['title' => $config['label']]) ?>
-				<span><?= esc_html($config['label'])?></span>
+			<label for="<?=$prefix?>set-<?=esc_attr($status)?>" title="<?=esc_html($config['label'])?>">
+				<?= jvbDashIcon($config['icon']) ?>
 			</label>
 			<?php
 		}

--
Gitblit v1.10.0