use MicroHTML

This commit is contained in:
Luana 2023-06-25 21:31:11 -03:00 committed by Shish
parent 9cbddd629e
commit ca88b28b1e
3 changed files with 21 additions and 11 deletions

View file

@ -6,7 +6,7 @@ namespace Shimmie2;
use MicroHTML\HTMLElement;
use function MicroHTML\{A,B,BR,IMG,emptyHTML};
use function MicroHTML\{A,B,BR,IMG,OPTION,SELECT,emptyHTML};
/**
* Class BaseThemelet
@ -201,22 +201,32 @@ class BaseThemelet
* @param bool $empty_option Whether the first option should be an empty one.
* @param array $selected_options The values of options that should be pre-selected.
*/
protected function build_selector(string $name, array $options, string $attributes="", bool $empty_option=false, array $selected_options=[]): string
protected function build_selector(string $name, array $options, bool $required=false, bool $multiple=false, bool $empty_option=false, array $selected_options=[]): string
{
$output = "<select name='" . $name . "' " . $attributes . ">";
$attrs = [];
if ($required) {
$attrs["required"] = "";
}
if ($multiple) {
$name = $name . "[]";
$attrs["multiple"] = "";
}
$attrs["name"] = $name;
$s = SELECT($attrs);
if ($empty_option) {
$output .= "<option></option>";
$s->appendChild(OPTION());
}
foreach ($options as $value => $op) {
if (in_array($value, $selected_options)) {
$output .= "<option value='" . $value . "' selected>" . html_escape($op) . "</option>";
$s->appendChild(OPTION(["value"=>$value, "selected"=>""], $op));
} else {
$output .= "<option value='" . $value . "' >" . html_escape($op) . "</option>";
$s->appendChild(OPTION(["value"=>$value], $op));
}
}
return $output . "</select>";
return (string)$s;
}
}

View file

@ -388,7 +388,7 @@ class PoolsTheme extends Themelet
public function get_bulk_pool_selector(array $options): string
{
return $this->build_selector("bulk_pool_select", $options, "required", true);
return $this->build_selector("bulk_pool_select", $options, required: true, empty_option: true);
}
public function get_bulk_pool_input(array $search_terms): string

View file

@ -33,8 +33,8 @@ 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</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><td colspan='2'><input type='submit' value='Update'></td></tr></table>
</form>\n";
@ -44,7 +44,7 @@ class RatingsTheme extends Themelet
public function get_selection_rater_html(array $selected_options, bool $multiple = false): string
{
return $this->build_selector($multiple ? "rating[]" : "rating", Ratings::get_ratings_dict(), ($multiple ? "multiple" : ""), false, $selected_options);
return $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