blob: 93611538e12d049ad128712fb59cc18771ce2ec9 (
plain)
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
|
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)
}
options(cf){
if(cf.options){
return cf.options
}
return {
default: ""
}
}
listInput(cf){
return(
<Select2
data={_.map(this.options(cf).list_values, (v, k) => {
return {id: k, text: (v.length > 0 ? v : '\u00A0')}
})}
ref={'custom_fields.' + cf.code}
className='form-control'
defaultValue={cf.value || this.options(cf).default}
disabled={this.props.disabled}
options={{
theme: 'bootstrap',
width: '100%'
}}
onSelect={(e) => this.props.onUpdate(cf.code, e.params.data.id) }
/>
)
}
stringInput(cf){
return(
<input
type='text'
ref={'custom_fields.' + cf.code}
className='form-control'
disabled={this.props.disabled}
value={cf.value || this.options(cf).default || ""}
onChange={(e) => {this.props.onUpdate(cf.code, e.target.value); this.forceUpdate()} }
/>
)
}
integerInput(cf){
return(
<input
type='number'
ref={'custom_fields.' + cf.code}
className='form-control'
disabled={this.props.disabled}
value={cf.value || this.options(cf).default || ""}
onChange={(e) => {this.props.onUpdate(cf.code, e.target.value); this.forceUpdate()} }
/>
)
}
render() {
return (
<div>
{_.map(this.props.values, (cf, code) =>
<div className='col-lg-6 col-md-6 col-sm-6 col-xs-12' key={code}>
<div className='form-group'>
<label className='control-label'>{cf.name}</label>
{this[cf.field_type + "Input"](cf)}
</div>
</div>
)}
</div>
)
}
}
CustomFieldsInputs.propTypes = {
onUpdate: PropTypes.func.isRequired,
values: PropTypes.object.isRequired,
disabled: PropTypes.bool.isRequired
}
|