From a0592079dd01b7bc37da91606243de446847ba28 Mon Sep 17 00:00:00 2001 From: Zog Date: Mon, 16 Apr 2018 10:40:23 +0200 Subject: Refs #6551; Add CustomFields to JourneyPatterns --- app/javascript/helpers/CustomFieldsInputs.js | 76 ++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 app/javascript/helpers/CustomFieldsInputs.js (limited to 'app/javascript/helpers') diff --git a/app/javascript/helpers/CustomFieldsInputs.js b/app/javascript/helpers/CustomFieldsInputs.js new file mode 100644 index 000000000..abc8097d5 --- /dev/null +++ b/app/javascript/helpers/CustomFieldsInputs.js @@ -0,0 +1,76 @@ +import _ from 'lodash' +import Select2 from 'react-select2-wrapper' +import React, { Component } from 'react' +import PropTypes from 'prop-types' + +export default class CustomFieldsInputs extends Component { + constructor(props) { + super(props) + } + + listInput(cf){ + return( + { + return {id: k, text: (v.length > 0 ? v : '\u00A0')} + })} + ref={'custom_fields.' + cf.code} + className='form-control' + defaultValue={cf.value} + disabled={this.props.disabled} + options={{ + theme: 'bootstrap', + width: '100%' + }} + onSelect={(e) => this.props.onUpdate(cf.code, e.params.data.id) } + /> + ) + } + + stringInput(cf){ + return( + {this.props.onUpdate(cf.code, e.target.value); this.forceUpdate()} } + /> + ) + } + + integerInput(cf){ + return( + {this.props.onUpdate(cf.code, e.target.value); this.forceUpdate()} } + /> + ) + } + + render() { + return ( +
+ {_.map(this.props.values, (cf, code) => +
+
+ + {this[cf.field_type + "Input"](cf)} +
+
+ )} +
+ ) + } +} + +CustomFieldsInputs.propTypes = { + onUpdate: PropTypes.func.isRequired, + values: PropTypes.object.isRequired, + disabled: PropTypes.bool.isRequired +} -- cgit v1.2.3