More MicroHTML
This commit is contained in:
parent
84d232ca0d
commit
91710f4c59
4 changed files with 50 additions and 34 deletions
|
@ -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)
|
||||
|
|
|
@ -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 "<input type='text' name='bulk_pool_new' placeholder='New pool' required='required' value='".(implode(" ", $search_terms))."' />";
|
||||
return INPUT(
|
||||
[
|
||||
"type"=>"text",
|
||||
"name"=>"bulk_pool_new",
|
||||
"placeholder"=>"New Pool",
|
||||
"required"=>"",
|
||||
"value"=>implode(" ", $search_terms)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function get_help_html(): string
|
||||
|
|
|
@ -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: ["?"]));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 = "
|
||||
<tr>
|
||||
<th>Rating</th>
|
||||
<td>
|
||||
".($can_rate ? "
|
||||
<span class='view'>$human_rating</span>
|
||||
<span class='edit'>
|
||||
".$this->get_selection_rater_html([$rating])."
|
||||
</span>
|
||||
" : "
|
||||
$human_rating
|
||||
")."
|
||||
</td>
|
||||
</tr>
|
||||
";
|
||||
|
||||
$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"))."<table class='form'>";
|
||||
|
||||
$html .= "<tr><th>Change</th><td>" . $this->build_selector("rating_old", $current_ratings, required: true) . "</td></tr>";
|
||||
$html .= "<tr><th>To</th><td>" . $this->build_selector("rating_new", Ratings::get_ratings_dict(), required: true) . "</td></tr>";
|
||||
$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 .= "<tr><td colspan='2'><input type='submit' value='Update'></td></tr></table>
|
||||
</form>\n";
|
||||
$html .= TR(TD(["colspan"=>"2"], INPUT(["type"=>"submit", "value"=>"Update"])));
|
||||
$html .= "</table></form>\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 = '<p>Search for posts with one or more possible ratings.</p>
|
||||
|
@ -89,7 +92,7 @@ class RatingsTheme extends Themelet
|
|||
<tbody>
|
||||
<tr><td>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.</td></tr>
|
||||
<tr><td>
|
||||
".$this->get_selection_rater_html($selected_ratings, true, $available_ratings)."
|
||||
".$this->build_selector("ratings", selected_options: $selected_ratings, multiple: true, options: $available_ratings)."
|
||||
</td></tr>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
|
|
Reference in a new issue