@@ -5,8 +5,8 @@ import moment from 'moment';
5
5
6
6
7
7
const GenericInput = ( { category, collection = [ ] , collectionType,
8
- type , name, label, onChange, placeholder,
9
- value, error, permissions } ) => {
8
+ datatype , name, label, onChange, placeholder,
9
+ value, error, readOnly } ) => {
10
10
11
11
function onChangeDate ( name ) {
12
12
return function ( date , dateString ) {
@@ -36,7 +36,7 @@ const GenericInput = ({ category, collection = [], collectionType,
36
36
37
37
function onChangeSelect ( name ) {
38
38
return function ( value ) {
39
- onChange ( name , { _id : value , _class : type } ) ;
39
+ onChange ( name , { _id : value , _class : datatype } ) ;
40
40
} ;
41
41
}
42
42
@@ -62,55 +62,58 @@ const GenericInput = ({ category, collection = [], collectionType,
62
62
const dateFormat = 'YYYY-MM-DD' ;
63
63
const datetimeFormat = 'YYYY-MM-DD HH:mm:ss' ;
64
64
65
- switch ( type ) {
65
+ switch ( datatype ) {
66
66
case '%Library.String' :
67
- if ( permissions . includes ( 'U' ) ) {
68
- input = < Input value = { value } onChange = { onChangeString ( name ) } name = { name } /> ;
67
+ if ( readOnly ) {
68
+ input = < Input value = { value } readOnly name = { name } /> ;
69
69
}
70
70
else {
71
- input = < Input value = { value } readOnly name = { name } /> ;
71
+ input = < Input value = { value } onChange = { onChangeString ( name ) } name = { name } /> ;
72
72
}
73
73
break ;
74
74
case '%Library.Boolean' :
75
- if ( permissions . includes ( 'U' ) ) {
76
- input = < Checkbox checked = { value } onChange = { onChangeBoolean ( name ) } name = { name } > { label } </ Checkbox > ;
75
+ if ( readOnly ) {
76
+ input = < Checkbox checked = { value } readOnly name = { name } > { label } </ Checkbox > ;
77
77
}
78
78
else {
79
- input = < Checkbox checked = { value } readOnly name = { name } > { label } </ Checkbox > ;
79
+ input = < Checkbox checked = { value } onChange = { onChangeBoolean ( name ) } name = { name } > { label } </ Checkbox > ;
80
80
}
81
81
break ;
82
82
case '%Library.Date' :
83
- if ( permissions . includes ( 'U' ) ) {
84
- input = ( < DatePicker format = { dateFormat } value = { getMomentValue ( value , dateFormat ) }
85
- name = { name } onChange = { onChangeDate ( name ) } /> ) ;
83
+ if ( readOnly ) {
84
+ input = < Input value = { value } name = { name } readOnly style = { { width : '200px' } } /> ;
86
85
}
87
86
else {
88
- input = < Input value = { value } name = { name } readOnly style = { { width : '200px' } } /> ;
87
+ input = ( < DatePicker format = { dateFormat } value = { getMomentValue ( value , dateFormat ) }
88
+ name = { name } onChange = { onChangeDate ( name ) } /> ) ;
89
89
}
90
90
break ;
91
91
case '%Library.TimeStamp' :
92
- if ( permissions . includes ( 'U' ) ) {
93
- input = ( < DatePicker format = { datetimeFormat } value = { getMomentValue ( value , moment . ISO_8601 ) }
94
- showTime name = { name } onChange = { onChangeTimestamp ( name ) } /> ) ;
92
+ if ( readOnly ) {
93
+ input = < Input value = { getMomentValue ( value , moment . ISO_8601 ) } name = { name } readOnly style = { { width : '200px' } } /> ;
95
94
}
96
95
else {
97
- input = < Input value = { getMomentValue ( value , moment . ISO_8601 ) } name = { name } readOnly style = { { width : '200px' } } /> ;
96
+ input = ( < DatePicker format = { datetimeFormat } value = { getMomentValue ( value , moment . ISO_8601 ) }
97
+ showTime name = { name } onChange = { onChangeTimestamp ( name ) } /> ) ;
98
98
}
99
99
break ;
100
100
case '%Library.Integer' :
101
101
case '%Library.Numeric' :
102
- if ( permissions . includes ( 'U' ) ) {
103
- input = < InputNumber name = { name } value = { value } onChange = { onChangeNumber ( name ) } /> ;
102
+ if ( readOnly ) {
103
+ input = < Input value = { value } name = { name } readOnly style = { { width : '200px' } } /> ;
104
104
}
105
105
else {
106
- input = < Input value = { value } name = { name } readOnly style = { { width : '200px' } } /> ;
106
+ input = < InputNumber name = { name } value = { value } onChange = { onChangeNumber ( name ) } /> ;
107
107
}
108
108
break ;
109
109
default :
110
110
if ( category === 'form' ) {
111
111
112
112
if ( ! collectionType ) {
113
- if ( permissions . includes ( 'U' ) ) {
113
+ if ( readOnly ) {
114
+ input = < Input name = { name } value = { value . name } readOnly style = { { width : '200px' } } /> ;
115
+ }
116
+ else {
114
117
let options = collection . map ( item => {
115
118
return < Select . Option key = { item . _id } value = { item . _id } > { item . displayName } </ Select . Option > ;
116
119
} ) ;
@@ -131,17 +134,14 @@ const GenericInput = ({ category, collection = [], collectionType,
131
134
</ Select >
132
135
) ;
133
136
}
134
- else {
135
- input = < Input name = { name } value = { value . name } readOnly style = { { width : '200px' } } /> ;
136
- }
137
137
}
138
138
139
139
}
140
140
break ;
141
141
}
142
142
143
143
if ( input ) {
144
- if ( type !== '%Library.Boolean' ) {
144
+ if ( datatype !== '%Library.Boolean' ) {
145
145
return (
146
146
< Form . Item label = { label } >
147
147
{ input }
@@ -157,15 +157,15 @@ const GenericInput = ({ category, collection = [], collectionType,
157
157
} ;
158
158
159
159
GenericInput . propTypes = {
160
- type : PropTypes . string . isRequired ,
160
+ datatype : PropTypes . string . isRequired ,
161
161
category : PropTypes . string . isRequired ,
162
162
collectionType : PropTypes . string . isRequired ,
163
163
collection : PropTypes . array ,
164
164
name : PropTypes . string . isRequired ,
165
165
label : PropTypes . string . isRequired ,
166
166
onChange : PropTypes . func . isRequired ,
167
167
placeholder : PropTypes . string ,
168
- permissions : PropTypes . string ,
168
+ readOnly : PropTypes . bool ,
169
169
value : PropTypes . any ,
170
170
error : PropTypes . string
171
171
} ;
0 commit comments