From 16d848fb715ff3dfb01d4317d7bec969ffa3e290 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 10 Nov 2023 13:26:36 +0000 Subject: [PATCH] [alias_editor] search --- ext/alias_editor/main.php | 55 ++++++++++++++++++++++++++++++++++++++ ext/alias_editor/theme.php | 8 +++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/ext/alias_editor/main.php b/ext/alias_editor/main.php index c62286bfc..9eb0ccb54 100644 --- a/ext/alias_editor/main.php +++ b/ext/alias_editor/main.php @@ -8,8 +8,26 @@ use MicroCRUD\TextColumn; use MicroCRUD\Table; +use MicroHTML\HTMLElement; + +use function MicroHTML\emptyHTML; +use function MicroHTML\TABLE as html_TABLE; +use function MicroHTML\THEAD; +use function MicroHTML\TBODY; +use function MicroHTML\TFOOT; +use function MicroHTML\TR; +use function MicroHTML\TH; +use function MicroHTML\TD; +use function MicroHTML\INPUT; +use function MicroHTML\FORM; +use function MicroHTML\DIV; +use function MicroHTML\A; +use function MicroHTML\B; +use function MicroHTML\BR; + class AliasTable extends Table { + public $search_url = null; public function __construct(\FFSPHP\PDO $db) { parent::__construct($db); @@ -26,6 +44,33 @@ public function __construct(\FFSPHP\PDO $db) $this->order_by = ["oldtag"]; $this->table_attrs = ["class" => "zebra"]; } + + public function thead(): HTMLElement + { + $thead = THEAD(["id"=>"read"]); + + $tr = TR(); + foreach ($this->columns as $col) { + if ($col->sortable) { + $sort_name = (@$this->inputs["r__sort"] == $col->name) ? "-{$col->name}" : $col->name; + $sort = "?" . $this->modify_url(["r__sort"=>$sort_name]); + $tr->appendChild(TH(A(["href"=>$sort], $col->title))); + } else { + $tr->appendChild(TH($col->title)); + } + } + $thead->appendChild($tr); + + if ($this->create_url) { + $tr = TR(); + foreach ($this->columns as $col) { + $tr->appendChild(TD($col->read_input($this->inputs))); + } + } + $thead->appendChild(FORM(["method"=>"POST", 'action'=>$this->search_url], $tr)); + + return $thead; + } } class AddAliasEvent extends Event @@ -91,7 +136,17 @@ public function onPageRequest(PageRequestEvent $event) $t->token = $user->get_auth_token(); $t->inputs = $_GET; $t->size = $config->get_int('alias_items_per_page', 30); + $input = validate_input(["r_oldtag"=>"string,optional", "r_newtag"=>"string,optional"]); + $tag_inputs = []; + if (isset($_GET["r_oldtag"])) { + $tag_inputs["r_oldtag"] = $_GET["r_oldtag"]; + } + if (isset($_GET["r_newtag"])) { + $tag_inputs["r_newtag"] = $_GET["r_newtag"]; + } + $t->inputs = array_merge($t->inputs, $input, $tag_inputs); if ($user->can(Permissions::MANAGE_ALIAS_LIST)) { + $t->search_url = make_link("alias/list"); $t->create_url = make_link("alias/add"); $t->delete_url = make_link("alias/remove"); } diff --git a/ext/alias_editor/theme.php b/ext/alias_editor/theme.php index 14ece72e5..6548ac908 100644 --- a/ext/alias_editor/theme.php +++ b/ext/alias_editor/theme.php @@ -30,7 +30,13 @@ public function display_aliases(HTMLElement $table, HTMLElement $paginator): voi $page->set_title("Alias List"); $page->set_heading("Alias List"); $page->add_block(new NavBlock()); - $page->add_block(new Block("Aliases", $html)); + $block = new Block("Aliases", $html); + $block->body = str_replace( + ["name='c_oldtag'", "name='c_newtag'"], + ["name='c_oldtag' class='autocomplete_tags'", "name='c_newtag' class='autocomplete_tags'"], + $block->body + ); + $page->add_block($block); if ($user->can(Permissions::MANAGE_ALIAS_LIST)) { $page->add_block(new Block("Bulk Upload", $bulk_html, "main", 51));