Template/Update (Part 9)

* convert filter handler
This commit is contained in:
Sarjuuk
2025-08-06 18:05:49 +02:00
parent e17cbfe51f
commit d03f482864
3 changed files with 66 additions and 73 deletions

View File

@@ -0,0 +1,64 @@
<?php
namespace Aowow;
if (!defined('AOWOW_REVISION'))
die('illegal access');
class FilterBaseResponse extends TextResponse
{
private array $catg = [];
private string $page = '';
private ?Filter $filter = null;
public function __construct(string $pageParam)
{
if (!$pageParam)
return;
parent::__construct($pageParam);
$catg = null;
if (strstr($pageParam, '='))
[$this->page, $catg] = explode('=', $pageParam);
else
$this->page = $pageParam;
if ($catg !== null)
$this->catg = explode('.', $catg);
$opts = ['parentCats' => $this->catg];
// so usually the page call is just the DBTypes file string with a plural 's' .. but then there are currencies
$fileStr = match ($this->page)
{
'currencies' => 'currency',
default => substr($this->page, 0, -1)
};
// yes, the whole _POST! .. should the input fields be exposed and static so they can be evaluated via BaseResponse::initRequestData() ?
$this->filter = Type::newFilter($fileStr, $_POST, $opts);
}
protected function generate() : void
{
$url = '?'.$this->page;
$this->filter?->mergeCat($this->catg);
if ($this->catg)
$url .= '='.implode('.', $this->catg);
if ($x = $this->filter?->buildGETParam())
$url .= '&filter='.$x;
if ($this->filter?->error)
$_SESSION['error']['fi'] = $this->filter::class;
// do get request
$this->redirectTo = $url;
}
}
?>

View File

@@ -1,71 +0,0 @@
<?php
namespace Aowow;
if (!defined('AOWOW_REVISION'))
die('illegal access');
class AjaxFilter extends AjaxHandler
{
public $doRedirect = true;
private $cat = [];
private $page = '';
private $filter = null;
public function __construct(array $params)
{
if (!$params)
return;
parent::__construct($params);
$p = explode('=', $params[0]);
$this->page = $p[0];
if (isset($p[1]))
$this->cat[] = $p[1];
if (count($params) > 1)
for ($i = 1; $i < count($params); $i++)
$this->cat[] = $params[$i];
$opts = ['parentCats' => $this->cat];
// so usually the page call is just the DBTypes file string with a plural 's' .. but then there are currencies
$fileStr = match ($this->page)
{
'currencies' => 'currency',
default => substr($this->page, 0, -1)
};
// yes, the whole _POST! .. should the input fields be exposed and static so they can be evaluated via BaseResponse::initRequestData() ?
$this->filter = Type::newFilter($fileStr, $_POST, $opts);
// always this one
$this->handler = 'handleFilter';
}
protected function handleFilter() : string
{
$url = '?'.$this->page;
$this->filter?->mergeCat($this->cat);
if ($this->cat)
$url .= '='.implode('.', $this->cat);
if ($x = $this->filter?->buildGETParam())
$url .= '&filter='.$x;
if ($this->filter?->error)
$_SESSION['error']['fi'] = get_class($this->filter);
// do get request
return $url;
}
}
?>

View File

@@ -601,14 +601,14 @@ function fi_toggle() {
// Set focus on first textbox
d.firstChild.nodeValue = LANG.fihide;
c = (c.parentNode.tagName == 'FORM' ? c.parentNode : $WH.gE(c, 'form')[0]);
c = c.elements.na ? c.elements.na: c.elements.ti;
c = c.elements.na ? c.elements.na : c.elements.ti;
c.focus();
c.select();
}
else {
d.firstChild.nodeValue = LANG.fishow;
}
d.className = 'disclosure-' + (b ? 'on': 'off');
d.className = 'disclosure-' + (b ? 'on' : 'off');
return false;
}