diff --git a/ext/pools/main.php b/ext/pools/main.php index 60c7528a..93e395f2 100644 --- a/ext/pools/main.php +++ b/ext/pools/main.php @@ -555,8 +555,9 @@ class Pools extends Extension $options = $database->get_pairs("SELECT id,title FROM pools ORDER BY title"); - $event->add_action("bulk_pool_add_existing", "Add To (P)ool", "p", "", $this->theme->get_bulk_pool_selector($options)); - $event->add_action("bulk_pool_add_new", "Create Pool", "", "", $this->theme->get_bulk_pool_input($event->search_terms)); + // TODO: Don't cast into strings, make BABBE accept HTMLElement instead. + $event->add_action("bulk_pool_add_existing", "Add To (P)ool", "p", "", (string)$this->theme->get_bulk_pool_selector($options)); + $event->add_action("bulk_pool_add_new", "Create Pool", "", "", (string)$this->theme->get_bulk_pool_input($event->search_terms)); } public function onBulkAction(BulkActionEvent $event) diff --git a/ext/pools/theme.php b/ext/pools/theme.php index f0c0eca1..50c83516 100644 --- a/ext/pools/theme.php +++ b/ext/pools/theme.php @@ -4,6 +4,10 @@ declare(strict_types=1); namespace Shimmie2; +use MicroHTML\HTMLElement; + +use function MicroHTML\INPUT; + class PoolsTheme extends Themelet { /** @@ -385,14 +389,22 @@ class PoolsTheme extends Themelet $this->display_paginator($page, "pool/updated", null, $pageNumber, $totalPages); } - public function get_bulk_pool_selector(array $options): string + public function get_bulk_pool_selector(array $options): HTMLElement { - return (string)$this->build_selector("bulk_pool_select", $options, required: true, empty_option: true); + return $this->build_selector("bulk_pool_select", $options, required: true, empty_option: true); } - public function get_bulk_pool_input(array $search_terms): string + public function get_bulk_pool_input(array $search_terms): HTMLElement { - return ""; + return INPUT( + [ + "type"=>"text", + "name"=>"bulk_pool_new", + "placeholder"=>"New Pool", + "required"=>"", + "value"=>implode(" ", $search_terms) + ] + ); } public function get_help_html(): string diff --git a/ext/rating/main.php b/ext/rating/main.php index bcf3aef7..cb7228d5 100644 --- a/ext/rating/main.php +++ b/ext/rating/main.php @@ -203,7 +203,7 @@ class Ratings extends Extension { global $user; $event->add_part( - $this->theme->get_rater_html( + (string)$this->theme->get_rater_html( $event->image->id, $event->image->rating, $user->can(Permissions::EDIT_IMAGE_RATING) @@ -345,7 +345,7 @@ class Ratings extends Extension global $user; if ($user->can(Permissions::BULK_EDIT_IMAGE_RATING)) { - $event->add_action("bulk_rate", "Set (R)ating", "r", "", $this->theme->get_selection_rater_html(["?"])); + $event->add_action("bulk_rate", "Set (R)ating", "r", "", (string)$this->theme->get_selection_rater_html(selected_options: ["?"])); } } diff --git a/ext/rating/theme.php b/ext/rating/theme.php index f33ed906..4881fcde 100644 --- a/ext/rating/theme.php +++ b/ext/rating/theme.php @@ -4,26 +4,34 @@ declare(strict_types=1); namespace Shimmie2; +use MicroHTML\HTMLElement; + +use function MicroHTML\{TR,TH,TD,SPAN,INPUT}; + class RatingsTheme extends Themelet { - public function get_rater_html(int $image_id, string $rating, bool $can_rate): string + public function get_selection_rater_html(string $name = "rating", array $ratings = [], array $selected_options = []): HTMLElement + { + return $this->build_selector($name, !empty($ratings) ? $ratings : Ratings::get_ratings_dict(), required: true, selected_options: $selected_options); + } + + public function get_rater_html(int $image_id, string $rating, bool $can_rate): HTMLElement { $human_rating = Ratings::rating_to_human($rating); - $html = " - - Rating - - ".($can_rate ? " - $human_rating - - ".$this->get_selection_rater_html([$rating])." - - " : " - $human_rating - ")." - - - "; + + $html = TR(TH("Rating")); + + if ($can_rate) { + $selector = $this->get_selection_rater_html(selected_options: [$rating]); + + $html->appendChild(TD( + SPAN(["class"=>"view"], $human_rating), + SPAN(["class"=>"edit"], $selector) + )); + } else { + $html->appendChild(TD($human_rating)); + } + return $html; } @@ -33,20 +41,15 @@ class RatingsTheme extends Themelet $html = make_form(make_link("admin/update_ratings")).""; - $html .= ""; - $html .= ""; + $html .= TR(TH("Change"), TD($this->get_selection_rater_html("rating_old", $current_ratings))); + $html .= TR(TH("To"), TD($this->get_selection_rater_html("rating_new"))); - $html .= "
Change" . $this->build_selector("rating_old", $current_ratings, required: true) . "
To" . $this->build_selector("rating_new", Ratings::get_ratings_dict(), required: true) . "
- \n"; + $html .= TR(TD(["colspan"=>"2"], INPUT(["type"=>"submit", "value"=>"Update"]))); + $html .= "\n"; $page->add_block(new Block("Update Ratings", $html)); } - public function get_selection_rater_html(array $selected_options, bool $multiple = false): string - { - return (string)$this->build_selector("rating", Ratings::get_ratings_dict(), multiple: $multiple, empty_option: false, selected_options: $selected_options); - } - public function get_help_html(array $ratings): string { $output = '

Search for posts with one or more possible ratings.

@@ -89,7 +92,7 @@ class RatingsTheme extends Themelet This controls the default rating search results will be filtered by, and nothing else. To override in your search results, add rating:* to your search. - ".$this->get_selection_rater_html($selected_ratings, true, $available_ratings)." + ".$this->build_selector("ratings", selected_options: $selected_ratings, multiple: true, options: $available_ratings)."