Skip to content

Commit

Permalink
Add SettingValues::inputs_printed() machinery.
Browse files Browse the repository at this point in the history
Do not print 'Save changes' if no inputs were provided.
  • Loading branch information
kohler committed Sep 25, 2023
1 parent 79c6091 commit 2d14e66
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 17 deletions.
3 changes: 2 additions & 1 deletion etc/settinggroups.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
{
"name": "users/pc", "order": 10,
"title": "Program committee & system administrators",
"print_function": "Users_SettingRenderer::print"
"print_function": "Users_SettingRenderer::print",
"inputs": false
},


Expand Down
22 changes: 16 additions & 6 deletions src/componentset.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class ComponentSet {
private $_ctx;
/** @var list<ComponentContext> */
private $_ctxstack;
/** @var list<callable(object):(?bool)> */
private $_print_callbacks = [];
private $_annexes = [];
/** @var list<callable(string,object,XtParams):(?bool)> */
private $_xt_checkers = [];

static private $next_placeholder;

Expand Down Expand Up @@ -125,9 +125,18 @@ function root() {
}


/** @param callable(string,object,XtParams):(?bool) $checker */
/** @param callable(string,object,XtParams):(?bool) $checker
* @return $this */
function add_xt_checker($checker) {
$this->xtp->primitive_checkers[] = $checker;
return $this;
}

/** @param callable(object):(?bool) $f
* @return $this */
function add_print_callback($f) {
$this->_print_callbacks[] = $f;
return $this;
}


Expand Down Expand Up @@ -488,12 +497,13 @@ function print($gj) {
/** @param object $gj
* @return mixed */
private function _print_body($gj) {
foreach ($this->_print_callbacks as $f) {
if ($f($gj) === false)
return false;
}
$result = null;
if (isset($gj->print_function)) {
$result = $this->call_function($gj, $gj->print_function, $gj);
} else if (isset($gj->render_function)) {
error_log("deprecated render_function in " . json_encode($gj) . "\n" . debug_string_backtrace()); // XXX
$result = $this->call_function($gj, $gj->render_function, $gj);
} else if (isset($gj->html_content)) {
echo $gj->html_content;
}
Expand Down
10 changes: 6 additions & 4 deletions src/pages/p_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,12 @@ private function print_extant_group($group, $qreq) {
}
$sv->print_group(strtolower($group), true);

echo '<div class="aab aabig mt-7">',
'<div class="aabut">', Ht::submit("update", "Save changes", ["class" => "btn-primary"]), '</div>',
'<div class="aabut">', Ht::submit("cancel", "Cancel", ["formnovalidate" => true]), '</div>',
'<hr class="c"></div>';
if ($sv->inputs_printed()) {
echo '<div class="aab aabig mt-7">',
'<div class="aabut">', Ht::submit("update", "Save changes", ["class" => "btn-primary"]), '</div>',
'<div class="aabut">', Ht::submit("cancel", "Cancel", ["formnovalidate" => true]), '</div>',
'<hr class="c"></div>';
}
}

private function print_list() {
Expand Down
26 changes: 20 additions & 6 deletions src/settingvalues.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class SettingValues extends MessageSet {
private $_jpath;
/** @var ?JsonParser */
private $_jp;
/** @var bool */
private $_inputs_printed;

function __construct(Contact $user) {
parent::__construct();
Expand Down Expand Up @@ -299,7 +301,8 @@ function cs() {
$this->_cs->set_title_class("form-h")
->set_section_class("form-section")
->set_separator('<hr class="form-sep">')
->set_context_args($this);
->set_context_args($this)
->add_print_callback([$this, "_print_callback"]);
}
return $this->_cs;
}
Expand Down Expand Up @@ -359,11 +362,13 @@ function print_start_section($title, $hashid = null) {
$this->cs()->print_start_section($title, $hashid);
}

/** @param string $title
* @param ?string $hashid
* @deprecated */
function print_section($title, $hashid = null) {
$this->print_start_section($title, $hashid);
/** @param object $gj
* @return ?bool */
function _print_callback($gj) {
$inputs = $gj->inputs ?? null;
if ($inputs || (isset($gj->print_function) && $inputs === null)) {
$this->_inputs_printed = true;
}
}


Expand Down Expand Up @@ -1531,6 +1536,15 @@ function changed_keys() {
}


/** @return bool */
function inputs_printed() {
return $this->_inputs_printed;
}

function mark_inputs_printed() {
$this->_inputs_printed = true;
}

/** @param string $html
* @param string|Si $id
* @return string */
Expand Down
12 changes: 12 additions & 0 deletions stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,18 @@ label.checki {
padding-right: 0.5em !important;
padding-right: 0.5rem !important;
}
.pr-3 {
padding-right: 1em !important;
padding-right: 1rem !important;
}
.pr-4 {
padding-right: 1.5em !important;
padding-right: 1.5rem !important;
}
.pr-5 {
padding-right: 2.25em !important;
padding-right: 2.25rem !important;
}

.text-start {
text-align: start;
Expand Down

0 comments on commit 2d14e66

Please sign in to comment.