Skip to content

Commit

Permalink
Change display of anonymity paper option on web form
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Jan 20, 2025
1 parent a532a3d commit f08b6df
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 34 deletions.
2 changes: 1 addition & 1 deletion etc/intrinsicoptions.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"configurable": true, "properties": ["name", "description", "edit_condition", "editable_if", "max"]
},
{
"name": "Anonymous submission", "id": -1002,
"name": "Anonymity", "id": -1002,
"type": "nonblind", "include_empty": true,
"json_key": "nonblind",
"form_order": 3002,
Expand Down
2 changes: 1 addition & 1 deletion etc/msgs.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
]
},
["sfdescription_contacts", "<0>These users can view and edit the {submission}. All listed authors with site accounts are contacts. You can add contacts who aren’t in the author list or create accounts for authors who haven’t yet signed in."],
["sfdescription_nonblind", "<0>Check this to submit anonymously (reviewers won’t be shown the author list). Make sure you also remove your name from the submission itself!"],
["sfdescription_nonblind", "<0>Select whether the {submission} is anonymous. Your choice should also be reflected in the {submission} itself."],
{
"in": "sfdescription_topics", "m": [
["<0>Select any topics that apply to your {submission}."],
Expand Down
40 changes: 29 additions & 11 deletions src/options/o_nonblind.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
// o_nonblind.php -- HotCRP helper class for blindness selection intrinsic
// Copyright (c) 2006-2023 Eddie Kohler; see LICENSE.
// Copyright (c) 2006-2025 Eddie Kohler; see LICENSE.

class Nonblind_PaperOption extends PaperOption {
function __construct(Conf $conf, $args) {
Expand All @@ -26,7 +26,15 @@ function value_save(PaperValue $ov, PaperStatus $ps) {
return true;
}
function parse_qreq(PaperInfo $prow, Qrequest $qreq) {
return PaperValue::make($prow, $this, $qreq->blind ? null : 1);
if ($qreq->nonblind === "blind") {
return PaperValue::make($prow, $this, null);
} else if ($qreq->nonblind === "nonblind") {
return PaperValue::make($prow, $this, 1);
} else if ($prow->is_new()) {
return PaperValue::make_estop($prow, $this, "<0>Entry required");
} else {
return PaperValue::make($prow, $this, $prow->blind ? null : 1);
}
}
function parse_json(PaperInfo $prow, $j) {
if (is_bool($j) || $j === null) {
Expand All @@ -36,15 +44,25 @@ function parse_json(PaperInfo $prow, $j) {
}
}
function print_web_edit(PaperTable $pt, $ov, $reqov) {
if ($ov->prow->phase() !== PaperInfo::PHASE_FINAL) {
$cb = Ht::checkbox("blind", 1, !$reqov->value, [
"id" => false,
"data-default-checked" => !$ov->value
]);
$pt->print_editable_option_papt($this,
'<span class="checkc">' . $cb . '</span>' . $pt->edit_title_html($this),
["for" => "checkbox", "tclass" => "ui js-click-child", "id" => $this->formid]);
echo "</div>\n\n";
if ($ov->prow->phase() === PaperInfo::PHASE_FINAL) {
return;
}
$pt->print_editable_option_papt($this, null, ["id" => $this->formid, "for" => false, "required" => true]);
if ($ov->prow->is_new()) {
$oval = $reqval = null;
} else {
$oval = $reqval = $ov->value ? "nonblind" : "blind";
}
if ($reqov !== $ov && !$reqov->has_error()) {
$reqval = $reqov->value ? "nonblind" : "blind";
}
echo '<div class="papev">';
foreach (["blind" => "Anonymous submission", "nonblind" => "Open (non-anonymous) submission"] as $k => $s) {
echo '<div class="checki"><label><span class="checkc">',
Ht::radio($this->formid, $k, $k === $reqval,
["data-default-checked" => $k === $oval]),
'</span>', $s, '</label></div>';
}
echo "</div></div>\n\n";
}
}
36 changes: 17 additions & 19 deletions src/paperoption.php
Original file line number Diff line number Diff line change
Expand Up @@ -695,19 +695,18 @@ static function basic_value_compare($av, $bv) {
}
/** @return bool */
function value_check_required(PaperValue $ov) {
if ($this->test_required($ov->prow)
&& !$this->value_present($ov)
&& !$ov->prow->allow_absent()) {
if ($this->required === self::REQ_SUBMIT) {
$m = $this->conf->_("<0>Entry required to complete {submission}");
$ov->msg($m, $ov->prow->want_submitted() ? MessageSet::ERROR : MessageSet::WARNING);
} else {
$ov->error("<0>Entry required");
}
return false;
} else {
if (!$this->test_required($ov->prow)
|| $this->value_present($ov)
|| $ov->prow->allow_absent()) {
return true;
}
if ($this->required === self::REQ_SUBMIT) {
$m = $this->conf->_("<0>Entry required to complete {submission}");
$ov->msg($m, $ov->prow->want_submitted() ? MessageSet::ERROR : MessageSet::WARNING);
} else {
$ov->error("<0>Entry required");
}
return false;
}
function value_check(PaperValue $ov, Contact $user) {
$this->value_check_required($ov);
Expand Down Expand Up @@ -1259,15 +1258,14 @@ function parse_qreq(PaperInfo $prow, Qrequest $qreq) {
$v = trim((string) $qreq[$this->formid]);
if ($v === "" || $v === "0") {
return PaperValue::make($prow, $this);
}
$iv = ctype_digit($v) ? intval($v) : -1;
if ($iv > 0 && isset($this->values[$iv - 1])) {
return PaperValue::make($prow, $this, $iv);
} else if (($idx = array_search($v, $this->values)) !== false) {
return PaperValue::make($prow, $this, $idx + 1);
} else {
$iv = ctype_digit($v) ? intval($v) : -1;
if ($iv > 0 && isset($this->values[$iv - 1])) {
return PaperValue::make($prow, $this, $iv);
} else if (($idx = array_search($v, $this->values)) !== false) {
return PaperValue::make($prow, $this, $idx + 1);
} else {
return PaperValue::make_estop($prow, $this, "<0>Value doesn’t match any of the options");
}
return PaperValue::make_estop($prow, $this, "<0>Value doesn’t match any of the options");
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/papertable.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
// papertable.php -- HotCRP helper class for producing paper tables
// Copyright (c) 2006-2024 Eddie Kohler; see LICENSE.
// Copyright (c) 2006-2025 Eddie Kohler; see LICENSE.

class PaperTable {
/** @var Conf
Expand Down Expand Up @@ -513,7 +513,8 @@ function print_editable_option_papt(PaperOption $opt, $heading = null, $rest = [
}
echo '">';
$heading = $heading ?? $this->edit_title_html($opt);
$klass = Ht::add_tokens("field-title", $opt->required ? "field-required" : "");
$required = $rest["required"] ?? $opt->required;
$klass = Ht::add_tokens("field-title", $required ? "field-required" : "");
if ($for) {
echo Ht::label($heading, $for === "checkbox" ? null : $for, ["class" => $klass]);
} else {
Expand Down

0 comments on commit f08b6df

Please sign in to comment.