-
Notifications
You must be signed in to change notification settings - Fork 348
/
answer-area-editor.jsx
95 lines (87 loc) · 3.36 KB
/
answer-area-editor.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/** @jsx React.DOM */
var React = require('react');
var Editor = require("./editor.jsx");
var InfoTip = require("react-components/info-tip.jsx");
var Widgets = require("./widgets.js");
var AnswerAreaEditor = React.createClass({
getDefaultProps: function() {
return {
type: "input-number",
options: {},
calculator: false
};
},
render: function() {
var cls;
if (this.props.type === "multiple") {
cls = Editor;
} else {
cls = Widgets.getEditor(this.props.type);
}
var editor = <cls
ref="editor"
placeholder={"This answer area is being deprecated. " +
"Please use the widgets in the question area for your answer."}
onChange={(newProps, cb) => {
var options = _.extend({}, this.props.options, newProps);
this.props.onChange({options: options}, cb);
}}
{...this.props.options} />;
return <div className="perseus-answer-editor">
<div className="perseus-answer-options">
<div><label>
{' '}Show calculator:{' '}
<input type="checkbox" checked={this.props.calculator}
onChange={e => {
this.props.onChange({calculator: e.target.checked});
}} />
</label>
<InfoTip>
<p>Use the calculator when completing difficult calculations is
NOT the intent of the question. DON’T use the calculator when
testing the student’s ability to complete different types of
computations.</p>
</InfoTip>
</div>
<div><label>
{' '}Answer type:{' '}
<select value={this.props.type}
onChange={e => {
this.props.onChange({
type: e.target.value,
options: {}
}, () => {
this.refs.editor.focus();
});
}}>
<option value="radio">Multiple choice</option>
<option value="table">Table of values</option>
<option value="input-number">Text input (number)</option>
<option value="expression">Expression / Equation</option>
<option value="multiple">Custom format</option>
</select>
</label>
<InfoTip>
<p>Use the custom format if the question is in the question
area, and tell the students how to complete the problem.</p>
</InfoTip></div>
</div>
<div className={cls !== Editor ? "perseus-answer-widget" : ""}>
{editor}
</div>
</div>;
},
getSaveWarnings: function() {
var issuesFunc = this.refs.editor.getSaveWarnings();
return issuesFunc ? issuesFunc() : [];
},
serialize: function() {
// could be _.pick(this.props, "type", "options", "calculator");
return {
type: this.props.type,
options: this.refs.editor.serialize(),
calculator: this.props.calculator
};
}
});
module.exports = AnswerAreaEditor;