Skip to content

Commit

Permalink
Correct directionality of Identify the Champion sample fields.
Browse files Browse the repository at this point in the history
And use `sample_view`, not `instantiate`.
  • Loading branch information
kohler committed Aug 31, 2023
1 parent 68359c4 commit 2ee5d69
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 44 deletions.
61 changes: 31 additions & 30 deletions etc/reviewfieldlibrary.json
Original file line number Diff line number Diff line change
@@ -1,64 +1,63 @@
[
{
"legend": "Score",
"instantiate": {"name": "", "values": []},
"name": "Field name",
"type": "radio",
"values": [
"Option 1",
"Option 2"
],
"required": true,
"visibility": "au"
"visibility": "au",
"sample_view": {
"values": [
"Option 1",
"Option 2"
]
}
},
{
"legend": "Text field",
"instantiate": {"name": ""},
"name": "Field name",
"type": "text",
"visibility": "au"
},
{
"legend": "Dropdown score",
"instantiate": {"name": "", "values": []},
"name": "Field name",
"type": "dropdown",
"values": [
"Option 1",
"Option 2"
],
"required": true,
"visibility": "au"
"visibility": "au",
"sample_view": {
"values": [
"Option 1",
"Option 2"
]
}
},
{
"legend": "Checkbox",
"instantiate": {"name": ""},
"name": "Checkbox field",
"type": "checkbox",
"visibility": "au"
},
{
"legend": "Attestation",
"instantiate": {"name": "", "description": ""},
"name": "Attestation",
"description": "The reviewer must check this box before submitting the review.",
"type": "checkbox",
"visibility": "au",
"required": true
"required": true,
"sample_view": {
"name": "Attestation",
"description": "The reviewer must check this box before submitting the review."
}
},
{
"legend": "Checkboxes",
"instantiate": {"name": "", "description": "", "values": []},
"name": "Field name",
"type": "checkboxes",
"description": "Select zero or more options.",
"values": [
"Option 1",
"Option 2",
"Option 3"
],
"start": "A",
"visibility": "au"
"visibility": "au",
"scheme": "catx",
"sample_view": {
"description": "Select zero or more options.",
"values": [
"Option 1",
"Option 2",
"Option 3"
]
}
},
{
"legend": "Overall merit (1–5, Reject through Strong Accept)",
Expand All @@ -85,6 +84,7 @@
"Good paper, I will champion it"
],
"start": "A",
"flip": true,
"required": true,
"visibility": "au",
"scheme": "svr"
Expand Down Expand Up @@ -141,6 +141,7 @@
"I am an expert in this area"
],
"start": "X",
"flip": true,
"required": true,
"visibility": "au",
"scheme": "orbu"
Expand Down
2 changes: 1 addition & 1 deletion scripts/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -5905,7 +5905,7 @@ ReviewField.prototype.render_in = function (fv, rrow, fe) {
function DiscreteValues_ReviewField(fj) {
var i, n, step, sym, ch;
ReviewField.call(this, fj);
this.values = fj.values;
this.values = fj.values || [];
this.symbols = fj.symbols;
this.start = fj.start || null;
this.scheme = fj.scheme || "sv";
Expand Down
26 changes: 15 additions & 11 deletions scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -835,11 +835,12 @@ function rf_visibility_text(visibility) {
return "";
}

function rf_render_view(fld) {
function rf_render_view(fld, example) {
var frag = document.createDocumentFragment(), labele, e, ve, t;

// header
labele = $e("label", "revfn" + (fld.required ? " field-required" : ""), fld.name || "<unnamed>");
labele = $e("label", "revfn" + (fld.required ? " field-required" : ""),
fld.name || (example ? "Field name" : "<unnamed>"));
frag.append((e = $e("h3", "rfehead", labele)));
if ((t = rf_visibility_text(fld.visibility))) {
e.append($e("div", "field-visibility", t));
Expand Down Expand Up @@ -923,13 +924,11 @@ var rfproperties = {
}

function rf_make(fj) {
var fld = hotcrp.make_review_field(fj);
const fld = hotcrp.make_review_field(fj);
if (fj.id != null)
fld.id = fj.id;
if (fj.legend != null)
fld.legend = fj.legend;
if (fj.instantiate != null)
fld.instantiate = fj.instantiate;
if (fj.configurable != null)
fld.configurable = fj.configurable;
return fld;
Expand Down Expand Up @@ -1036,15 +1035,20 @@ demand_load.review_field_library = demand_load.make(function (resolve) {
$.get(hoturl("api/reviewfieldlibrary"), null, resolve);
});

function rf_make_sample(fj) {
const xj = Object.assign({}, fj);
fj.sample_view && Object.assign(xj, fj.sample_view);
const fld = rf_make(xj);
fld.__base = fj;
return fld;
}

function add_dialog() {
var $d, grid, samples;
function submit(evt) {
var samp = samples[+grid.getAttribute("data-selected-index")],
fld = Object.assign({}, samp);
fld = Object.assign({}, samp.__base);
delete fld.id;
for (const i in fld.instantiate || {}) {
fld[i] = fld.instantiate[i];
}
rf_add(fld);
$$("rf/" + fieldorder.length + "/name").focus();
$d.close();
Expand All @@ -1065,12 +1069,12 @@ function add_dialog() {
grid = $d[0].querySelector(".grid-select");
for (i = 0; i !== samples.length; ++i) {
if (!samples[i].parse_value) {
samples[i] = rf_make(samples[i]);
samples[i] = rf_make_sample(samples[i]);
}
grid.append($e("fieldset", {"class": "grid-option", "data-index": i, role: "option", tabindex: 0, "aria-selected": "false"},
$e("legend", null, samples[i].legend),
$e("div", {"class": "settings-xf-view", role: "presentation"},
rf_render_view(samples[i]))));
rf_render_view(samples[i], true))));
}
settings_disable_children(grid);
grid_select_event.call(grid, 0);
Expand Down
3 changes: 2 additions & 1 deletion src/api/api_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ static function make_field_library($xtp, $defaults, $optname) {

$l = [];
foreach ($m as $name => $list) {
if (($j = $xtp->search_list($list)))
if (($j = $xtp->search_list($list))) {
$l[] = $j;
}
}

usort($l, "Conf::xt_pure_order_compare");
Expand Down
2 changes: 1 addition & 1 deletion src/reviewfield.php
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ function __construct(Conf $conf, ReviewFieldInfo $finfo, $j) {
if (isset($j->symbols) && !isset($j->values)) {
$this->values = array_fill(0, count($j->symbols), "");
} else {
$this->values = $j->values ?? $j->options ?? [];
$this->values = $j->values ?? $j->options /* XXX */ ?? [];
}
$nvalues = count($this->values);
if (isset($j->symbols) && count($j->symbols) === $nvalues) {
Expand Down

0 comments on commit 2ee5d69

Please sign in to comment.