pref-prefs: switch to new control shorthand in a few places

This commit is contained in:
Andrew Dolgov 2021-02-21 23:18:32 +03:00
parent 861a632ac7
commit f6bfb89b29
2 changed files with 38 additions and 30 deletions

View File

@ -712,59 +712,50 @@ class Pref_Prefs extends Handler_Protected {
array_push($listed_boolean_prefs, $pref_name); array_push($listed_boolean_prefs, $pref_name);
$is_checked = ($value == "true") ? "checked=\"checked\"" : "";
if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) { if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) {
$is_disabled = "disabled=\"1\""; $is_disabled = true;
$is_checked = "checked=\"checked\""; $is_checked = true;
} else { } else {
$is_disabled = ""; $is_disabled = false;
$is_checked = ($value == "true");
} }
print "<input type='checkbox' name='$pref_name' $is_checked $is_disabled print \Controls\checkbox_tag($pref_name, $is_checked, "true",
dojoType='dijit.form.CheckBox' id='CB_$pref_name' value='1'>"; ["disabled" => $is_disabled], "CB_$pref_name");
} else if (in_array($pref_name, ['FRESH_ARTICLE_MAX_AGE', } else if (in_array($pref_name, ['FRESH_ARTICLE_MAX_AGE',
'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT'])) { 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT'])) {
$regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) { if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) {
$is_disabled = "disabled='1'"; $attributes = ["disabled" => true, "required" => true];
$value = FORCE_ARTICLE_PURGE; $value = FORCE_ARTICLE_PURGE;
} else { } else {
$is_disabled = ""; $attributes = ["required" => true];
} }
if ($type_name == 'integer') if ($type_name == 'integer')
print "<input dojoType=\"dijit.form.NumberSpinner\" print \Controls\number_spinner_tag($pref_name, $value, $attributes);
required='1' $is_disabled
name=\"$pref_name\" value=\"$value\">";
else else
print "<input dojoType=\"dijit.form.TextBox\" print \Controls\input_tag($pref_name, $value, "text", $attributes);
required='1' $regexp $is_disabled
name=\"$pref_name\" value=\"$value\">";
} else if ($pref_name == "SSL_CERT_SERIAL") { } else if ($pref_name == "SSL_CERT_SERIAL") {
print "<input dojoType='dijit.form.ValidationTextBox' print \Controls\input_tag($pref_name, $value, "text", ["readonly" => true], "SSL_CERT_SERIAL");
id='SSL_CERT_SERIAL' readonly='1'
name=\"$pref_name\" value=\"$value\">";
$cert_serial = htmlspecialchars(get_ssl_certificate_id()); $cert_serial = htmlspecialchars(get_ssl_certificate_id());
$has_serial = ($cert_serial) ? "false" : "true"; $has_serial = ($cert_serial) ? true : false;
print "<button dojoType='dijit.form.Button' disabled='$has_serial' print \Controls\button_tag(__('Register'), "", [
onclick=\"dijit.byId('SSL_CERT_SERIAL').attr('value', '$cert_serial')\">" . "disabled" => !$has_serial,
__('Register') . "</button>"; "onclick" => "dijit.byId('SSL_CERT_SERIAL').attr('value', '$cert_serial')"]);
print "<button dojoType='dijit.form.Button' class='alt-danger' print \Controls\button_tag(__('Clear'), "", [
onclick=\"dijit.byId('SSL_CERT_SERIAL').attr('value', '')\">" . "class" => "alt-danger",
__('Clear') . "</button>"; "onclick" => "dijit.byId('SSL_CERT_SERIAL').attr('value', '')"]);
print "<button dojoType='dijit.form.Button' class='alt-info' print \Controls\button_tag(\Controls\icon("help") . " " . __("More info..."), "", [
onclick='window.open(\"https://tt-rss.org/wiki/SSL%20Certificate%20Authentication\")'> "class" => "alt-info",
<i class='material-icons'>help</i> ".__("More info...")."</button>"; "onclick" => "window.open('https://tt-rss.org/wiki/SSL%20Certificate%20Authentication')"]);
} else if ($pref_name == 'DIGEST_PREFERRED_TIME') { } else if ($pref_name == 'DIGEST_PREFERRED_TIME') {
print "<input dojoType=\"dijit.form.ValidationTextBox\" print "<input dojoType=\"dijit.form.ValidationTextBox\"

View File

@ -5,6 +5,11 @@
$rv = ""; $rv = "";
foreach ($attributes as $k => $v) { foreach ($attributes as $k => $v) {
// special handling for "disabled"
if ($k === "disabled" && !sql_bool_to_bool($v))
continue;
$rv .= "$k=\"" . htmlspecialchars($v) . "\""; $rv .= "$k=\"" . htmlspecialchars($v) . "\"";
} }
@ -30,6 +35,18 @@
return "<button dojoType=\"dijit.form.Button\" ".attributes_to_string($attributes)." type=\"$type\">$value</button>"; return "<button dojoType=\"dijit.form.Button\" ".attributes_to_string($attributes)." type=\"$type\">$value</button>";
} }
function input_tag(string $name, string $value, string $type = "text", array $attributes = [], string $id = "") {
$attributes_str = attributes_to_string($attributes);
$dojo_type = strpos($attributes_str, "dojoType") === false ? "dojoType='dijit.form.TextBox'" : "";
return "<input name=\"".htmlspecialchars($name)."\" $dojo_type ".attributes_to_string($attributes)." id=\"".htmlspecialchars($id)."\"
type=\"$type\" value=\"".htmlspecialchars($value)."\">";
}
function number_spinner_tag(string $name, string $value, array $attributes = [], string $id = "") {
return input_tag($name, $value, "text", array_merge(["dojoType" => "dijit.form.NumberSpinner"], $attributes), $id);
}
function submit_tag(string $value, array $attributes = []) { function submit_tag(string $value, array $attributes = []) {
return button_tag($value, "submit", array_merge(["class" => "alt-primary"], $attributes)); return button_tag($value, "submit", array_merge(["class" => "alt-primary"], $attributes));
} }