@@ -131,7 +156,6 @@ class TemplateEditor extends PureComponent {
isProtected={this.state.isProtected}
isPristine={this.isPristine}
onChange={this.handleTemplateChange}
- onClear={this.handleTemplateClear}
onCopy={this.handleTemplateCopy}
onDelete={this.handleTemplateDelete}
onExport={this.props.onExport}
@@ -203,10 +227,13 @@ class TemplateEditor extends PureComponent {
datatypes={this.props.datatypes}
properties={this.props.properties}
isDisabled={this.state.isProtected || isPristine}
- onFieldAdd={this.props.onFieldAdd}
- onFieldOrder={this.props.onFieldOrder}
- onFieldRemove={this.props.onFieldRemove}
- onFieldSave={this.props.onFieldSave}/>
+ onInsert={this.handleFieldInsert}
+ onRemove={this.handleFieldRemove}
+ onSave={this.handleFieldSave}
+ onSort={this.handleSort}
+ onSortPreview={this.handleSortPreview}
+ onSortReset={this.handleSortReset}
+ onSortStart={this.handleSortStart}/>
)
@@ -236,10 +263,11 @@ class TemplateEditor extends PureComponent {
}
static defaultProps = {
- types: [TYPE.ITEM, TYPE.PHOTO]
+ types: [TYPE.ITEM, TYPE.PHOTO, TYPE.SELECTION]
}
}
+
module.exports = {
TemplateEditor: connect(
state => ({
diff --git a/src/components/template/field-list.js b/src/components/template/field-list.js
index f2ab5ef6f..96d87695d 100644
--- a/src/components/template/field-list.js
+++ b/src/components/template/field-list.js
@@ -1,154 +1,32 @@
'use strict'
const React = require('react')
-const { PureComponent } = React
const { TemplateField } = require('./field')
-const { insert, move, remove } = require('../../common/util')
-const { arrayOf, bool, func, object, shape, string } = require('prop-types')
-const { TEXT } = require('../../constants/type')
-
-
-let tmpId = -1
-
-const newField = () => ({
- id: tmpId--,
- value: '',
- hint: '',
- property: '',
- datatype: TEXT,
- isConstant: false,
- isRequired: false
-})
-
-const updateFields = (props) => (
- props.isDisabled || !props.template ?
- props.fields :
- props.fields.length > 0 ?
- [...props.fields] :
- [newField()]
-)
-
-
-class TemplateFieldList extends PureComponent {
- constructor(props) {
- super(props)
-
- this.state = {
- fields: updateFields(props)
- }
- }
-
- componentWillReceiveProps(props) {
- if (props.fields !== this.props.fields) {
- this.setState({
- fields: updateFields(props)
- })
- }
- }
-
- handleFieldSave = (id, data, idx) => {
- if (id < 0) {
- this.props.onFieldAdd({
- id: this.props.template,
- field: { datatype: TEXT, ...data }
- }, { idx })
- } else {
- this.props.onFieldSave({
- id: this.props.template,
- field: { id, ...data }
- })
- }
- }
-
- handleFieldInsert = (field, at) => {
- this.setState({
- fields: insert(this.state.fields, at, newField())
- })
- }
-
- handleFieldRemove = (field) => {
- if (field.id < 0) {
- this.setState({
- fields: remove(this.state.fields, field)
- })
- } else {
- this.props.onFieldRemove({
- id: this.props.template,
- field: field.id
- })
- }
- }
-
- handleSortStart = () => {
- this.originalFields = this.state.fields
- }
-
- handleSort = (field) => {
- this.originalFields = null
-
- if (field.id > 0) {
- this.props.onFieldOrder({
- id: this.props.template,
- fields: this.state.fields
- .map(f => f.id)
- .filter(id => id > 0)
- })
- }
- }
-
- handleSortPreview = (from, to, offset) => {
- this.setState({
- fields: move(this.state.fields, from, to, offset)
- })
- }
-
- handleSortReset = () => {
- this.setState({ fields: this.originalFields })
- this.originalFields = null
- }
-
- render() {
- if (this.props.template == null) return
- const isSingle = this.state.fields.length === 1
-
- return (
-