-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
307 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
import React from 'react'; | ||
|
||
import Configuration from '../../model/Configuration'; | ||
import FormUtils from '../../util/FormUtils'; | ||
|
||
const CheckboxAnswer = (props) => { | ||
var question = props.question; | ||
return React.createElement(Configuration.inputComponent, { | ||
type: 'checkbox', | ||
label: props.label, | ||
title: props.title, | ||
checked: props.value === true || props.value === 'true', | ||
onChange: (e) => { | ||
props.onChange(e.target.checked); | ||
}, | ||
disabled: FormUtils.isDisabled(question), | ||
}); | ||
}; | ||
|
||
CheckboxAnswer.propTypes = { | ||
question: React.PropTypes.object.isRequired, | ||
label: React.PropTypes.string.isRequired, | ||
title: React.PropTypes.string, | ||
value: React.PropTypes.oneOfType([React.PropTypes.string, React.PropTypes.bool]), | ||
onChange: React.PropTypes.func.isRequired | ||
}; | ||
|
||
export default CheckboxAnswer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
import React from "react"; | ||
import moment from "moment"; | ||
import DateTimePicker from "kbss-react-bootstrap-datetimepicker"; | ||
import Configuration from "../../model/Configuration"; | ||
import Utils from "../../util/Utils"; | ||
|
||
const DateTimeAnswer = (props) => { | ||
var mode = Utils.resolveDateTimeMode(props.question), | ||
value = Utils.resolveDateTimeValue(props.question, props.value); | ||
if (!value.isValid()) { | ||
value = moment(); | ||
} | ||
return <div style={{position: 'relative'}}> | ||
<label className='control-label'>{props.label}</label> | ||
<DateTimePicker mode={mode} inputFormat={Configuration.dateTimeFormat} | ||
inputProps={{title: props.title, bsSize: 'small'}} | ||
onChange={(date) => { | ||
props.onChange(Number(date)) | ||
}} dateTime={value.format(Configuration.dateTimeFormat)}/> | ||
</div> | ||
}; | ||
|
||
DateTimeAnswer.propTypes = { | ||
question: React.PropTypes.object.isRequired, | ||
label: React.PropTypes.string.isRequired, | ||
title: React.PropTypes.string, | ||
value: React.PropTypes.string, | ||
onChange: React.PropTypes.func.isRequired | ||
}; | ||
|
||
export default DateTimeAnswer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
|
||
import React from 'react'; | ||
import JsonLdUtils from 'jsonld-utils'; | ||
|
||
import Configuration from '../../model/Configuration'; | ||
import Constants from '../../constants/Constants'; | ||
import FormUtils from '../../util/FormUtils'; | ||
|
||
const InputAnswer = (props) => { | ||
var question = props.question, | ||
answer = props.answer, | ||
value = props.value; | ||
// When the value is an object_value, but the layout does not specify neither typeahead nor select, | ||
// show at least the value's label | ||
if (answer[Constants.HAS_OBJECT_VALUE] && answer[Constants.HAS_OBJECT_VALUE][JsonLdUtils.RDFS_LABEL]) { | ||
value = JsonLdUtils.getJsonAttValue(answer[Constants.HAS_OBJECT_VALUE], JsonLdUtils.RDFS_LABEL); | ||
} | ||
var inputType = FormUtils.isTextarea(question, value) ? 'textarea' : 'text'; | ||
return React.createElement(Configuration.inputComponent, { | ||
type: inputType, | ||
label: props.label, | ||
title: props.title, | ||
value: value, | ||
onChange: (e) => { | ||
props.onChange(e.target.value) | ||
}, | ||
disabled: FormUtils.isDisabled(question), | ||
rows: 5 | ||
}); | ||
}; | ||
|
||
InputAnswer.propTypes = { | ||
question: React.PropTypes.object.isRequired, | ||
answer: React.PropTypes.object.isRequired, | ||
label: React.PropTypes.string.isRequired, | ||
title: React.PropTypes.string, | ||
value: React.PropTypes.string, | ||
onChange: React.PropTypes.func.isRequired | ||
}; | ||
|
||
export default InputAnswer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use strict'; | ||
|
||
import React from 'react'; | ||
import JsonLdUtils from 'jsonld-utils'; | ||
|
||
import Configuration from '../../model/Configuration'; | ||
import Constants from '../../constants/Constants'; | ||
import FormUtils from '../../util/FormUtils'; | ||
|
||
export default class SelectAnswer extends React.Component { | ||
static propTypes = { | ||
question: React.PropTypes.object.isRequired, | ||
label: React.PropTypes.string.isRequired, | ||
title: React.PropTypes.string, | ||
value: React.PropTypes.string, | ||
onChange: React.PropTypes.func.isRequired | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
} | ||
|
||
_generateSelectOptions(options) { | ||
var rendered = []; | ||
options.sort(function (a, b) { | ||
var aLabel = JsonLdUtils.getJsonAttValue(a, JsonldUtils.RDFS_LABEL), | ||
bLabel = JsonLdUtils.getJsonAttValue(b, JsonldUtils.RDFS_LABEL); | ||
if (aLabel < bLabel) { | ||
return -1; | ||
} | ||
if (aLabel > bLabel) { | ||
return 1; | ||
} | ||
return 0; | ||
}); | ||
for (var i = 0, len = options.length; i < len; i++) { | ||
rendered.push(<option value={JsonLdUtils.getJsonAttValue(options[i], JsonldUtils.RDFS_LABEL)} | ||
key={'opt-' + i}>{JsonLdUtils.getJsonAttValue(options[i], JsonldUtils.RDFS_LABEL)}</option>); | ||
} | ||
return rendered; | ||
} | ||
|
||
render() { | ||
return React.createElement(Configuration.inputComponent, { | ||
type: 'select', | ||
label: this.props.label, | ||
value: this.props.value, | ||
title: this.props.title, | ||
onChange: (e) => {this.props.onChange(e.target.value)}, | ||
disabled: FormUtils.isDisabled(question) | ||
}, this._generateSelectOptions(question[Constants.HAS_OPTION]) | ||
); | ||
} | ||
} |
Oops, something went wrong.