Skip to content
This repository has been archived by the owner on Aug 3, 2022. It is now read-only.

Commit

Permalink
[#834] Pending submissions are public and readonly.
Browse files Browse the repository at this point in the history
The entry form for pending submission is now viewable for non-reviewers,
with form fields set to readonly and submit controls removed.
  • Loading branch information
brew committed Nov 11, 2016
1 parent 345ba3c commit c1aea3e
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 35 deletions.
10 changes: 6 additions & 4 deletions census/controllers/census.js
Expand Up @@ -290,15 +290,17 @@ var pending = function(req, res) {
reviewComments: entry.reviewComments
};

let reviewersData = {place: place, dataset: dataset};
let reviewers = utils.getReviewers(req, reviewersData);
let canReview = utils.canReview(reviewers, req.user);
let initialHTML = renderToString(<EntryForm questions={questions}
qsSchema={qsSchema}
context={datasetContext}
answers={formData}
place={entry.place}
dataset={entry.dataset}
isReview={true} />);
let reviewersData = {place: place, dataset: dataset};
let reviewers = utils.getReviewers(req, reviewersData);
isReview={true}
canReview={canReview} />);
let entryStatus = 'pending';
if (entry.isCurrent) {
entryStatus = 'accepted';
Expand All @@ -321,7 +323,7 @@ var pending = function(req, res) {
isReview: true,
entryStatus: entryStatus,
entry: entry,
canReview: utils.canReview(reviewers, req.user),
canReview: canReview,
reviewClosed: entry.reviewResult ||
(entry.year !== req.app.get('year'))
});
Expand Down
15 changes: 12 additions & 3 deletions census/ui_app/EntryForm.jsx
Expand Up @@ -129,6 +129,9 @@ const EntryForm = React.createClass({
},

render() {
let readonly = (this.props.isReview && !this.props.canReview);
let readOnlyOpts = {};
if (readonly) readOnlyOpts.readOnly = 'readonly';
return (<div>
<section>
<div className="container">
Expand All @@ -141,6 +144,7 @@ const EntryForm = React.createClass({
qsSchema={this.yourKnowledgeQSSchema}
questions={this.yourKnowledgeQuestions}
answers={this.props.answers.aboutYouAnswers}
readonly={readonly}
labelPrefix={'A'}
ref={'yourKnowledgeQuestions'} />
</div>
Expand All @@ -156,6 +160,7 @@ const EntryForm = React.createClass({
qsSchema={this.props.qsSchema}
questions={this.props.questions}
answers={this.props.answers.answers}
readonly={readonly}
labelPrefix={'B'}
ref={'questions'} />
</div>
Expand All @@ -177,7 +182,8 @@ const EntryForm = React.createClass({
<div className="answer-wrapper">
<div className="answer">
<textarea name="details" rows="5"
defaultValue={this.props.answers.details}></textarea>
defaultValue={this.props.answers.details}
{...readOnlyOpts}></textarea>
</div>
</div>
</div>
Expand All @@ -204,14 +210,16 @@ const EntryForm = React.createClass({
<input type="radio" name="anonymous"
id="anonymousNo"
value="No"
defaultChecked={this.props.answers.anonymous === 'No'} />
defaultChecked={this.props.answers.anonymous === 'No'}
{...readOnlyOpts} />
<label htmlFor="anonymousNo">
<span>No</span>
</label>
<input type="radio" name="anonymous"
id="anonymousYes"
value="Yes"
defaultChecked={this.props.answers.anonymous === 'Yes'} />
defaultChecked={this.props.answers.anonymous === 'Yes'}
{...readOnlyOpts} />
<label htmlFor="anonymousYes">
<span>Yes</span>
</label>
Expand All @@ -223,6 +231,7 @@ const EntryForm = React.createClass({
</div>

<helpers.SubmitActions isReview={this.props.isReview}
canReview={this.props.canReview}
onSubmitHandler={this.onSubmitHandler}
reviewComments={this.props.answers.reviewComments} />

Expand Down
9 changes: 7 additions & 2 deletions census/ui_app/HelperFields.jsx
Expand Up @@ -17,7 +17,7 @@ const CurrentEntry = props => {
};

const SubmitActions = props => {
if (props.isReview) {
if (props.isReview && props.canReview) {
return (<div>
<div className="text question">
<div className="main">
Expand Down Expand Up @@ -66,6 +66,8 @@ const SubmitActions = props => {
<div className="comments"></div>
</div>
</div>);
} else if (props.isReview && !props.canReview) {
return null;
} else {
return (<div className="submit continuation question">
<div className="main">
Expand Down Expand Up @@ -113,6 +115,8 @@ const QuestionInstructions = props => {

const QuestionComments = React.createClass({
render() {
let readOnlyOpts = {};
if (this.props.readonly) readOnlyOpts.readOnly = 'readonly';
return (<div className="comments">
<label htmlFor={this.props.id + '_comment'}>Comments</label>
<textarea placeholder={this.props.placeholder || 'Add comments' }
Expand All @@ -121,7 +125,8 @@ const QuestionComments = React.createClass({
name={this.props.id + '_comment'}
value={this.props.commentValue}
onChange={this.handler}
disabled={this.props.disabled}></textarea>
disabled={this.props.disabled}
{...readOnlyOpts}></textarea>
</div>);
},

Expand Down
80 changes: 57 additions & 23 deletions census/ui_app/QuestionFields.jsx
Expand Up @@ -38,6 +38,8 @@ const baseQuestionField = QuestionField => {

let QuestionFieldText = React.createClass({
render() {
let readOnlyOpts = {};
if (this.props.readonly) readOnlyOpts.readOnly = 'readonly';
return (<div className={'text question ' + this.props.getClassValues()}>
<div className="main">
<div>
Expand All @@ -55,7 +57,8 @@ let QuestionFieldText = React.createClass({
value={this.props.value}
name={this.props.id}
onChange={this.handler}
disabled={!this.props.visibleProps.enabled} />
disabled={!this.props.visibleProps.enabled}
{...readOnlyOpts} />
</div>
</div>
</div>
Expand All @@ -64,7 +67,8 @@ let QuestionFieldText = React.createClass({
placeholder={this.props.placeholder}
commentValue={this.props.commentValue}
onCommentChange={this.props.onCommentChange}
disabled={!this.props.visibleProps.enabled} />
disabled={!this.props.visibleProps.enabled}
readonly={this.props.readonly} />
</div>);
},

Expand All @@ -76,6 +80,8 @@ QuestionFieldText = baseQuestionField(QuestionFieldText);

let QuestionFieldYesNo = React.createClass({
render() {
let readOnlyOpts = {};
if (this.props.readonly) readOnlyOpts.readOnly = 'readonly';
return (<div className={'yes-no question ' + this.props.getClassValues()}>
<div className="main">
<div>
Expand All @@ -95,7 +101,8 @@ let QuestionFieldYesNo = React.createClass({
value="No"
checked={(this.props.value === 'No')}
disabled={!this.props.visibleProps.enabled}
onChange={this.handler} />
onChange={this.handler}
{...readOnlyOpts} />
<label htmlFor={this.props.id + '1'}>
<span>No</span>
</label>
Expand All @@ -105,7 +112,8 @@ let QuestionFieldYesNo = React.createClass({
value="Yes"
checked={(this.props.value === 'Yes')}
disabled={!this.props.visibleProps.enabled}
onChange={this.handler} />
onChange={this.handler}
{...readOnlyOpts} />
<label htmlFor={this.props.id + '2'}>
<span>Yes</span>
</label>
Expand All @@ -117,17 +125,22 @@ let QuestionFieldYesNo = React.createClass({
placeholder={this.props.placeholder}
commentValue={this.props.commentValue}
onCommentChange={this.props.onCommentChange}
disabled={!this.props.visibleProps.enabled} />
disabled={!this.props.visibleProps.enabled}
readonly={this.props.readonly} />
</div>);
},

handler(e) {
this.props.onChange(this, e.target.value);
if (!this.props.readonly) {
this.props.onChange(this, e.target.value);
}
}
});
QuestionFieldYesNo = baseQuestionField(QuestionFieldYesNo);

const QuestionFieldLikertOption = props => {
let readOnlyOpts = {};
if (props.readonly) readOnlyOpts.readOnly = 'readonly';
return (
<span>
<input type="radio"
Expand All @@ -136,7 +149,8 @@ const QuestionFieldLikertOption = props => {
value={props.value}
onChange={props.handler}
checked={props.checked}
disabled={props.disabled} />
disabled={props.disabled}
{...readOnlyOpts} />
<label htmlFor={props.id + props.value}>
<span>{props.value}</span> <em className="description">{props.description}</em>
</label>
Expand All @@ -154,7 +168,8 @@ let QuestionFieldLikert = React.createClass({
key={this.props.id + option.value}
handler={this.handler}
checked={this.props.value === option.value}
disabled={!this.props.visibleProps.enabled} />;
disabled={!this.props.visibleProps.enabled}
readonly={this.props.readonly} />;
});
return (<div className={'scale question ' + this.props.getClassValues()}>
<div className="main">
Expand All @@ -178,17 +193,25 @@ let QuestionFieldLikert = React.createClass({
placeholder={this.props.placeholder}
commentValue={this.props.commentValue}
onCommentChange={this.props.onCommentChange}
disabled={!this.props.visibleProps.enabled} />
disabled={!this.props.visibleProps.enabled}
readonly={this.props.readonly} />
</div>);
},

handler(e) {
this.props.onChange(this, e.target.value);
if (!this.props.readonly) {
this.props.onChange(this, e.target.value);
}
}
});
QuestionFieldLikert = baseQuestionField(QuestionFieldLikert);

const QuestionFieldSourceLine = props => {
let commonOpts = {
onChange: props.onChange,
disabled: props.disabled
};
if (props.readonly) commonOpts.readOnly = 'readonly';
return (
<ul>
<li>
Expand All @@ -199,8 +222,7 @@ const QuestionFieldSourceLine = props => {
data-key={'urlValue'}
placeholder="http://"
value={props.urlValue}
onChange={props.onChange}
disabled={props.disabled} />
{...commonOpts} />
</li>
<li>
<label htmlFor={props.id + '_desc'}>Source description</label>
Expand All @@ -209,8 +231,7 @@ const QuestionFieldSourceLine = props => {
type="text"
data-key={'descValue'}
value={props.descValue}
onChange={props.onChange}
disabled={props.disabled} />
{...commonOpts} />
</li>
</ul>
);
Expand Down Expand Up @@ -246,6 +267,7 @@ let QuestionFieldSource = React.createClass({
descValue={sourceValue.descValue}
onChange={this.handler.bind(this, i)}
disabled={!this.props.visibleProps.enabled}
readonly={this.props.readonly}
/>;
sourceLines.push(node);
}
Expand All @@ -272,7 +294,8 @@ let QuestionFieldSource = React.createClass({
commentValue={this.props.commentValue}
onCommentChange={this.props.onCommentChange}
disabled={!this.props.visibleProps.enabled}
disabled={!this.props.visibleProps.enabled} />
disabled={!this.props.visibleProps.enabled}
readonly={this.props.readonly} />
</div>);
},

Expand All @@ -287,6 +310,8 @@ let QuestionFieldSource = React.createClass({
QuestionFieldSource = baseQuestionField(QuestionFieldSource);

const QuestionFieldMultipleChoiceOption = props => {
let readOnlyOpts = {};
if (props.readonly) readOnlyOpts.readOnly = 'readonly';
return (
<li>
<input type="checkbox"
Expand All @@ -295,7 +320,8 @@ const QuestionFieldMultipleChoiceOption = props => {
value="1"
checked={props.checked}
onChange={props.handler}
disabled={props.disabled} />
disabled={props.disabled}
{...readOnlyOpts} />
<label htmlFor={props.id}>
<span className="letter">{props.label}</span> <span className="description">{props.children.toString()}</span>
</label>
Expand All @@ -305,14 +331,17 @@ const QuestionFieldMultipleChoiceOption = props => {

const QuestionFieldMultipleChoiceOther = props => {
if (props.includeOther) {
let readOnlyOpts = {};
if (props.readonly) readOnlyOpts.readOnly = 'readonly';
return (
<div className="other text sub">
<h3>Other</h3>
<div className="answer">
<input name={props.id}
value={props.value}
type="text"
disabled={props.disabled} />
disabled={props.disabled}
{...readOnlyOpts} />
</div>
</div>
);
Expand Down Expand Up @@ -363,7 +392,8 @@ let QuestionFieldMultipleChoice = React.createClass({
checked={option.checked}
label={label}
handler={this.handler.bind(this, i)}
disabled={!this.props.visibleProps.enabled}>
disabled={!this.props.visibleProps.enabled}
readonly={this.props.readonly}>
{option.description}
</QuestionFieldMultipleChoiceOption>;
});
Expand All @@ -389,15 +419,17 @@ let QuestionFieldMultipleChoice = React.createClass({
</div>
<QuestionFieldMultipleChoiceOther includeOther={this.props.config.includeOther}
id={this.props.id + '_other'}
disabled={!this.props.visibleProps.enabled} />
disabled={!this.props.visibleProps.enabled}
readonly={this.props.readonly} />
</div>
</div>
</div>
<helpers.QuestionComments id={this.props.id}
placeholder={this.props.placeholder}
commentValue={this.props.commentValue}
onCommentChange={this.props.onCommentChange}
disabled={!this.props.visibleProps.enabled} />
disabled={!this.props.visibleProps.enabled}
readonly={this.props.readonly} />
</div>);
},

Expand All @@ -410,9 +442,11 @@ let QuestionFieldMultipleChoice = React.createClass({
},

handler(i, e) {
let newOptionValues = this.optionValues;
newOptionValues[i].checked = e.target.checked;
this.props.onChange(this, newOptionValues);
if (!this.props.readonly) {
let newOptionValues = this.optionValues;
newOptionValues[i].checked = e.target.checked;
this.props.onChange(this, newOptionValues);
}
}
});
QuestionFieldMultipleChoice = baseQuestionField(QuestionFieldMultipleChoice);
Expand Down
3 changes: 2 additions & 1 deletion census/ui_app/QuestionForm.jsx
Expand Up @@ -177,7 +177,8 @@ const QuestionForm = React.createClass({
config={
this.getValueForId(q.id, 'config')
}
context={this.props.context}>
context={this.props.context}
readonly={this.props.readonly || false}>
{this.getValueForId(q.id, 'text')}
</ComponentClass>
);
Expand Down

0 comments on commit c1aea3e

Please sign in to comment.