Jake Vanderwerf
2026-06-29 4089ba01e0881c89a72332e13bc3a80b6bddec2a
inc/ui/CRUDSkeleton.php
@@ -578,14 +578,17 @@
   protected function renderUploader(): void {
      ?>
      <details open class="uploader">
         <summary class="row btw"><?= esc_html($this->uploaderConfig['label'] ?? 'Upload Files') ?></summary>
         <?php
         echo Form::render(
            'new_' . $this->dataType,
            '',
            $this->uploaderConfig
         );
         ?>
         <summary class="row x-btw"><?= esc_html($this->uploaderConfig['label'] ?? 'Upload Files') ?></summary>
         <form id="uploader" data-form-id="upload_new_<?=$this->dataType ?>">
            <?php
            echo jvbFormRestore();
            echo Form::render(
               'new_' . $this->dataType,
               '',
               $this->uploaderConfig
            );
            ?>
         </form>
      </details>
      <?php
   }
@@ -597,7 +600,7 @@
      $dataIgnore = $this->useCRUDjs ? '' : ' data-ignore';
      ?>
      <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">
         <div id="item-wrap">
            <?php
            $this->renderControlsAndFilters();
@@ -621,7 +624,7 @@
         return;
      }
      ?>
      <details class="all-filters col start" data-ignore>
      <details class="all-filters col top" data-ignore>
         <summary>Filters</summary>
         <?php
@@ -646,7 +649,7 @@
         return;
      }
      ?>
      <div class="search row start nowrap">
      <div class="search row left nowrap">
         <span class="label">Search:</span>
         <?= jvbSearch() ?>
      </div>
@@ -659,7 +662,7 @@
         return;
      }
      ?>
      <div class="radio-options view row">
      <div class="radio-options view row left">
         <span class="label">View:</span>
         <?php
         $views = [
@@ -680,7 +683,7 @@
            <label for="view-<?=$view?>"
               title="<?=$views[$view]['label']?>">
               <?= jvbDashIcon($views[$view]['icon']) ?>
               <span class="screen-reader-text"><?=$views[$view]['label']?></span>
               <span class="label"><?=$views[$view]['label']?></span>
            </label>
            <?php
         }
@@ -695,7 +698,7 @@
         return;
      }
      ?>
      <div class="radio-options status row">
      <div class="radio-options status row left">
         <span class="label">Status:</span>
         <?php
         $i = 1;
@@ -710,6 +713,7 @@
            <input type="radio" class="btn" data-filter="status" value="<?=$status?>" name="status" id="<?=$status?>"<?=$checked?>>
            <label for="<?=$status?>" title="<?=$config['label']?>">
               <?= jvbDashIcon($config['icon']) ?>
               <span class="label"><?= $config['label'] ?></span>
            </label>
            <?php
            $i++;
@@ -722,34 +726,52 @@
   protected function renderOrderControls():void
   {
      ?>
      <div class="radio-options order row btw w-full">
      <div class="radio-options order row x-btw w-full">
         <?php
         $order = [
            'orderby' => [
               'date' => 'Order by date created',
               'alphabetical' => 'Order alphabetically'
               [
                  'slug'   => 'date',
                  'label'  => 'Date Created',
                  'icon'   => 'calendar'
               ],
               [
                  'slug'   => 'alphabetical',
                  'label'  => 'Alphabetically',
                  'icon'   => 'alphabetical',
               ],
               [
                  'slug'   => 'date_modified',
                  'icon'   => 'clock-clockwise',
                  'label'  => 'Date Modified',
               ],
            ],
            'order' => [
               'sort-ascending' => 'In ascending order (Z-A, oldest to newest)',
               'sort-descending' => 'In descending order (A-Z, newest to oldest)'
               [
                  'slug'   => 'desc',
                  'icon'   => 'sort-descending',
                  'label'  => 'Descending (A-Z, 1-10)'
               ],
               [
                  'slug'   => 'asc',
                  'icon'   => 'sort-ascending',
                  'label'  => 'Ascending (Z-A, 10-1)'
               ]
            ]
         ];
         foreach ($order as $o => $option) {
            ?>
            <div class="row start">
            <div class="row left">
               <span class="label"><?= ucfirst($o)?>:</span>
               <?php
               $title = $o === 'orderby' ? 'Order by ' : 'Sort ';
               $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;
               foreach ($option as $conf) {
                  ?>
                  <input id="<?=$opt?>" class="btn" type="radio" name="<?=$o?>" data-filter="<?=$o?>" value="<?=$value?>"<?=$i===0 ? ' checked':''?>>
                  <input id="<?=$o.'-'.$conf['slug'] ?>" class="btn" type="radio" name="<?=$o?>" data-filter="<?=$o?>" value="<?=$conf['slug']?>"<?=$i===0 ? ' checked':''?>>
                  <label for="<?=$opt?>" title="<?=$label?>"><?=jvbDashIcon($icon)?></label>
                  <label for="<?=$o.'-'.$conf['slug']?>" title="<?=$title.' '.$conf['label']?>"><?=jvbDashIcon($conf['icon'])?><span class="label"><?= $conf['label'] ?></span></label>
                  <?php
                  $i++;
               }
@@ -767,7 +789,7 @@
         return;
      }
      ?>
      <div class="filters row start">
      <div class="filters row left">
         <span class="label">Filters:</span>
         <?php
         foreach ($this->filters as $key => $config) {
@@ -847,6 +869,7 @@
            $form = ob_get_clean();
            echo jvbNewModal(
               'date-range',
            'date-range',
            'Filter Results by Date:',
               $form
            );
@@ -925,7 +948,7 @@
      ob_start();
      ?>
      <details class="multi-select" title="Select columns" hidden>
         <summary class="row start nowrap">
         <summary class="row left nowrap">
            <?= jvbDashIcon('columns') ?>
            <span class="labels">Toggle Columns</span>
         </summary>
@@ -958,7 +981,7 @@
         return;
      }
      ?>
      <div class="bulk-controls row nowrap btw">
      <div class="bulk-controls row nowrap x-btw">
         <div class="bulk-select">
            <input type="checkbox" id="select-all" class="select-all">
            <label for="select-all" class="row"><span>Select All</span><span class="selected-count" hidden></span></label>
@@ -1129,7 +1152,7 @@
      }
      ob_start();
      ?>
      <div class="item-actions row btw abs">
      <div class="item-actions row x-btw abs">
         <?php
         foreach ($this->itemActions as $action) {
            $config = $this->defaultItemActions[$action];
@@ -1170,7 +1193,7 @@
         <div class="item <?=esc_attr($this->dataType)?> row nowrap">
            <?= $this->renderItemSelect()?>
            <?=$this->renderImage() ?>
            <div class="col start w-full">
            <div class="col top w-full">
               <h3 data-field="post_title"></h3>
               <p data-attr="date"></p>
               <p data-field="price"></p>
@@ -1195,7 +1218,6 @@
      ?>
      <template class="contentTable">
         <form class="table"
            data-save="content"
            data-content="<?= esc_attr($this->dataType) ?>"
            data-form-id="content-table-<?= esc_attr($this->dataType) ?>"
            <?= $permissions?>>
@@ -1233,9 +1255,9 @@
               <?= $this->renderItemSelect() ?>
            </td>
            <?php
               if (array_key_exists('status', $this->fields)){
               if (array_key_exists('post_status', $this->fields)){
                  ?>
                  <td class="status" data-field="post_status">
                  <td class="post_status" data-field="post_status" data-field-type="radio">
                     <?= $this->renderStatusRadios() ?>
                  </td>
                  <?php
@@ -1249,7 +1271,7 @@
               'radio'
            ];
            foreach ($this->fields as $name => $config):
               if (array_key_exists('hidden', $config) || $name === 'status'){
               if ((array_key_exists('hidden', $config) && $config['hidden'] === true) || $name === 'post_status'){
                  continue;
               }
               $makeThisDetailed = (in_array($config['type'], $makeDetails));
@@ -1257,7 +1279,7 @@
               <td class="field show-<?= esc_attr($name) ?>" data-field="<?= esc_attr($name) ?>" data-field-type="<?=$config['type']?>"<?=(in_array($name, $this->stuck)) ? ' data-stuck':''?>>
                  <?php
                  if (in_array('edit', $this->caps)) {
                     echo $makeThisDetailed ? '<details><summary class="row btw">See Value</summary>' : '';
                     echo $makeThisDetailed ? '<details><summary class="row x-btw">See Value</summary>' : '';
                     if (in_array($config['type'], ['selector', 'taxonomy', 'post'])) {
                        $config['autocomplete'] = true;
                     }
@@ -1289,7 +1311,6 @@
      ?>
      <template class="contentTable">
         <form class="table"
              data-save="content"
              data-content="<?= esc_attr($this->dataType) ?>"
              data-form-id="content-table-<?= esc_attr($this->dataType) ?>">
            <?= jvbFormStatus() ?>
@@ -1339,7 +1360,7 @@
               $makeThisDetailed = (in_array($config['type'], $makeDetails));
               ?>
               <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>' : '' ?>
                  <?= $makeThisDetailed ? '<details><summary class="row x-btw">See Value</summary>' : '' ?>
                  <?php
                  if (in_array($config['type'], ['selector', 'taxonomy', 'post'])) {
                     $config['autocomplete'] = true;
@@ -1362,7 +1383,7 @@
            </td>
            <?php
            foreach ($this->fields as $name => $config) {
               if(array_key_exists('hidden', $config) || $name === 'post_status') {
               if((array_key_exists('hidden', $config) && $config['hidden'] === true) || $name === 'post_status') {
                  continue;
               }
               if (!in_array($name, $this->timelineUniqueFields)) {
@@ -1372,7 +1393,7 @@
               $makeThisDetailed = (in_array($config['type'], $makeDetails));
               ?>
               <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>' : '' ?>
                  <?= $makeThisDetailed ? '<details><summary class="row x-btw">See Value</summary>' : '' ?>
                  <?= Form::render($name, '', $config); ?>
                  <?= $makeThisDetailed ? '</details>' : '' ?>
               </td>
@@ -1389,64 +1410,59 @@
    * Render table header
    */
   protected function renderTableHeader(): string {
      ob_start();
      ?>
      <tr>
      $out = '<tr>
         <th scope="col" class="select-header">
            <input type="checkbox" id="select-all" name="select-all">
            <label for="select-all">All</label>
         </th>
         <?php if (array_key_exists('status', $this->fields)) { ?>
            <th scope="col" class="status-header">Status</th>
         <?php } ?>
         <?php foreach ($this->fields as $name => $config):
            if (array_key_exists('hidden', $config) || $name === 'status'){
               continue;
            }
            ?>
            <th scope="col" class="show-<?= esc_attr($name) ?>"<?= (in_array($name, $this->stuck)) ? ' data-stuck':''?>>
               <?= esc_html($config['label']) ?>
            </th>
         <?php endforeach;
         if (!empty($this->itemActions)) {
            ?>
            <th scope="col" class="show-actions">
               Actions
            </th>
            <?php
         }
         ?>
         </th>';
      </tr>
      <?php
      return ob_get_clean();
      if (array_key_exists('post_status', $this->fields)){
         $out .= '<th scope="col" class="status-header">Status</th>';
      }
      foreach ($this->fields as $name => $config) {
         if ($name === 'post_status' || (array_key_exists('hidden', $config) && $config['hidden'] === true)) {
            continue;
         }
         $out .= sprintf(
            '<th scope="col" class="show-%s"%s>%s</th>',
            esc_attr($name),
            in_array($name, $this->stuck) ? ' data-stuck' : '',
            esc_html($config['label'])
         );
      }
      if (!empty($this->itemActions)) {
         $out .= '<th scope="col" class="show-actions">Actions</th>';
      }
      $out .= '</tr>';
      return $out;
   }
   protected function renderTimelineTableHeader(): string {
      ob_start();
      ?>
      <tr>
      $out = '<tr>
         <th scope="col" class="select-header">
            <input type="checkbox" id="select-all" name="select-all">
            <label for="select-all">All</label>
         </th>
         <th scope="col" class="show-post_status">
            Status
         </th>
         <?php foreach ($this->fields as $name => $config):
            if (array_key_exists('hidden', $config) || $name === 'post_status'){
               continue;
            }
            ?>
            <th scope="col" class="show-<?= esc_attr($name) ?>"<?= (in_array($name, $this->stuck)) ? ' data-stuck':''?>>
               <?= esc_html($config['label']) ?>
            </th>
         <?php endforeach; ?>
      </tr>
      <?php
      return ob_get_clean();
         </th>';
      foreach ($this->fields as $name => $config) {
         if ($name === 'post_status' || (array_key_exists('hidden', $config) && $config['hidden'] === true)) {
            continue;
         }
         $out .= sprintf(
            '<th scope="col" class="show-%s"%s>%s</th>th>',
            esc_attr($name),
            in_array($name, $this->stuck) ? ' data-stuck':'',
            esc_html($config['label'])
         );
      }
      $out .= '</tr>';
      return $out;
   }
   /**
@@ -1455,7 +1471,7 @@
   protected function renderTableActions(): string {
      ob_start();
      ?>
      <div class="table-actions row btw nowrap">
      <div class="table-actions row x-btw nowrap">
         <?php if (count(array_intersect(['create', 'edit'], $this->caps)) > 0) { ?>
            <?= jvbRenderToggleTextField(
               'vertical',
@@ -1474,29 +1490,35 @@
      return ob_get_clean();
   }
   protected function renderStatusRadios(): string {
      ob_start();
      ?>
      <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 (!array_key_exists($status, $this->allowedStatuses)) continue;
            $config = $this->allowedStatuses[$status];
            ?>
   protected function renderStatusRadios(): string
   {
      $out = '<div class="radio-options status-options row">';
      foreach ($this->statuses as $status) {
         if ($status === 'all' || !array_key_exists($status, $this->allowedStatuses)) continue;
         $config = $this->allowedStatuses[$status];
            <input type="radio"
         $out .= sprintf(
            '<input type="radio"
                  name="post_status"
                  id="status-<?= esc_attr($status) ?>"
                  value="<?= esc_attr($status) ?>">
            <label for="status-<?= esc_attr($status) ?>">
               <?= jvbDashIcon($config['icon']) ?>
               <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();
                  id="post_status-%s"
                  class="btn"
                  value="%s">
            <label for="post_status-%s" title="%s">
               %s
               <span class="screen-reader-text">%s</span>
            </label>',
            esc_attr($status),
            esc_attr($status),
            esc_attr($status),
            esc_html($config['label']),
            jvbDashIcon($config['icon']),
            esc_html($config['label'])
         );
      }
      $out .= '<span class="validation-message" hidden role="alert"></span>
      </div>';
      return $out;
   }
@@ -1542,6 +1564,7 @@
   {
      echo jvbNewModal(
         'create',
         'create',
         'Creating <span class="count"></span> New '.$this->singular,
         str_replace('edit-form"', 'create-form" data-noautosave', $this->editForm())
      );
@@ -1550,14 +1573,16 @@
   protected function editForm():string
   {
      ob_start();
/*    <form class="edit-form" data-save="content" data-form-id="edit-<?=$this->dataType?>" data-autosave<?= ($this->isTimeline) ? ' data-timeline' : ''*/
      ?>
      <form class="edit-form" data-save="content" data-form-id="edit-<?=$this->dataType?>" data-autosave<?= ($this->isTimeline) ? ' data-timeline' : ''?>>
      <form class="edit-form" data-form-id="edit-<?=$this->dataType?>" data-autosave<?= ($this->isTimeline) ? ' data-timeline' : ''?>>
         <?= jvbFormStatus() ?>
         <input type="hidden" name="form-id" value="<?=uniqid('new-')?>" />
         <input type="hidden" name="content" value="<?=$this->dataType?>" />
         <div class="fields">
            <?php
            if (!empty($this->statuses)) {
            if (empty($this->sections) && !empty($this->statuses)) {
               echo Form::render('post_status', '', $this->getStatusFieldConfig('edit-'));
            }
@@ -1571,8 +1596,9 @@
                        'icon'   => $config['icon']
                     ];
                  }
                  $tabs[$slug] = array_merge([
                     'title'  => $config['label'],
                     'title'  => $config['title'],
                     'content' => '',
                     'description' => $config['description']??'',
                  ], $section);
@@ -1582,13 +1608,18 @@
            }
            $fields = $this->fields;
            if (!$this->isTimeline) {
               $first = ['post_thumbnail', 'post_title', 'price'];
               $first = $this->registrar->getType() === 'post' ?
                  ['post_thumbnail', 'post_title', 'price'] :
                  ( $this->registrar->getType() === 'term' ?
                     ['name', 'thumbnail', 'description'] :
                     ['username', 'display_name', 'description']);
               foreach ($first as $f) {
                  if (array_key_exists($f, $fields)) {
                     if ($tabs) {
                        $tabs['basic']['content'] .= Form::render($f, '', $fields[$f]);
                        $tabs['main']['content'] .= Form::render($f, '', $fields[$f]);
                     } else {
                        echo Form::render($f, '', $fields[$f]);
                     }
@@ -1633,12 +1664,13 @@
               $fields = $this->nonTimelineFields;
            }
            foreach ($fields as $n => $config) {
               if (in_array($config['type'], ['taxonomy', 'selector'])) {
                  $config = array_merge($config, $this->taxConfig($config['taxonomy'], $config['label']));
               }
               if ($tabs) {
                  $section = (array_key_exists('section', $config)) ? $config['section'] : 'basic';
                  $section = (array_key_exists('section', $config)) && !empty($config['section']) ? $config['section'] : 'main';
                  $tabs[$section]['content'] .= Form::render($n, '', $config);
               } else {
                  echo Form::render($n, '', $config);
@@ -1660,6 +1692,7 @@
   {
      echo jvbNewModal(
         'edit',
         'edit',
         'Edit your '.$this->singular,
         $this->editForm()
      );
@@ -1669,8 +1702,10 @@
   {
      if (empty($this->bulkActions)) return;
      ob_start();
/*    <form class="bulk-edit-form" data-save="content" data-form-id="bulk-edit-<?=$this->dataType?>">*/
      ?>
      <form class="bulk-edit-form" data-save="content" data-form-id="bulk-edit-<?=$this->dataType?>">
      <form class="bulk-edit-form" data-form-id="bulk-edit-<?=$this->dataType?>">
         <?= jvbFormStatus() ?>
         <div class="selected"></div>
         <p class="description">You can unselect items by clicking the image here.</p>
@@ -1710,6 +1745,7 @@
      $form = ob_get_clean();
      echo jvbNewModal(
         'bulkEdit',
         'bulkEdit',
         'Bulk Edit <span class="selected"></span> '.$this->plural,
         $form
      );
@@ -1787,4 +1823,31 @@
      $out = ob_get_clean();
      echo Form::fieldWrap('post_status', $out, ['type'=>'group']);
   }
   public static function searchFilter():string
   {
      $self = new self();
      $self->hasSearch = true;
      ob_start();
      $self->renderSearch();
      return ob_get_clean();
   }
   public static function viewFilter(array $views):string
   {
      $self = new self();
      $self->views = $views;
      ob_start();
      $self->renderViewControls();
      return ob_get_clean();
   }
   public static function orderFilter(bool $random = false):string
   {
      $self = new self();
      ob_start();
      $self->renderOrderControls();
      return ob_get_clean();
   }
}