@@ -5,8 +5,8 @@ import moment from 'moment';
55
66
77const GenericInput = ( { category, collection = [ ] , collectionType,
8- type , name, label, onChange, placeholder,
9- value, error, permissions } ) => {
8+ datatype , name, label, onChange, placeholder,
9+ value, error, readOnly } ) => {
1010
1111 function onChangeDate ( name ) {
1212 return function ( date , dateString ) {
@@ -36,7 +36,7 @@ const GenericInput = ({ category, collection = [], collectionType,
3636
3737 function onChangeSelect ( name ) {
3838 return function ( value ) {
39- onChange ( name , { _id : value , _class : type } ) ;
39+ onChange ( name , { _id : value , _class : datatype } ) ;
4040 } ;
4141 }
4242
@@ -62,55 +62,58 @@ const GenericInput = ({ category, collection = [], collectionType,
6262 const dateFormat = 'YYYY-MM-DD' ;
6363 const datetimeFormat = 'YYYY-MM-DD HH:mm:ss' ;
6464
65- switch ( type ) {
65+ switch ( datatype ) {
6666 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 } /> ;
6969 }
7070 else {
71- input = < Input value = { value } readOnly name = { name } /> ;
71+ input = < Input value = { value } onChange = { onChangeString ( name ) } name = { name } /> ;
7272 }
7373 break ;
7474 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 > ;
7777 }
7878 else {
79- input = < Checkbox checked = { value } readOnly name = { name } > { label } </ Checkbox > ;
79+ input = < Checkbox checked = { value } onChange = { onChangeBoolean ( name ) } name = { name } > { label } </ Checkbox > ;
8080 }
8181 break ;
8282 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' } } /> ;
8685 }
8786 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 ) } /> ) ;
8989 }
9090 break ;
9191 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' } } /> ;
9594 }
9695 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 ) } /> ) ;
9898 }
9999 break ;
100100 case '%Library.Integer' :
101101 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' } } /> ;
104104 }
105105 else {
106- input = < Input value = { value } name = { name } readOnly style = { { width : '200px' } } /> ;
106+ input = < InputNumber name = { name } value = { value } onChange = { onChangeNumber ( name ) } /> ;
107107 }
108108 break ;
109109 default :
110110 if ( category === 'form' ) {
111111
112112 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 {
114117 let options = collection . map ( item => {
115118 return < Select . Option key = { item . _id } value = { item . _id } > { item . displayName } </ Select . Option > ;
116119 } ) ;
@@ -131,17 +134,14 @@ const GenericInput = ({ category, collection = [], collectionType,
131134 </ Select >
132135 ) ;
133136 }
134- else {
135- input = < Input name = { name } value = { value . name } readOnly style = { { width : '200px' } } /> ;
136- }
137137 }
138138
139139 }
140140 break ;
141141 }
142142
143143 if ( input ) {
144- if ( type !== '%Library.Boolean' ) {
144+ if ( datatype !== '%Library.Boolean' ) {
145145 return (
146146 < Form . Item label = { label } >
147147 { input }
@@ -157,15 +157,15 @@ const GenericInput = ({ category, collection = [], collectionType,
157157} ;
158158
159159GenericInput . propTypes = {
160- type : PropTypes . string . isRequired ,
160+ datatype : PropTypes . string . isRequired ,
161161 category : PropTypes . string . isRequired ,
162162 collectionType : PropTypes . string . isRequired ,
163163 collection : PropTypes . array ,
164164 name : PropTypes . string . isRequired ,
165165 label : PropTypes . string . isRequired ,
166166 onChange : PropTypes . func . isRequired ,
167167 placeholder : PropTypes . string ,
168- permissions : PropTypes . string ,
168+ readOnly : PropTypes . bool ,
169169 value : PropTypes . any ,
170170 error : PropTypes . string
171171} ;
0 commit comments