NonTabularSection.js 6.3 KB
import React,{PropTypes} from 'react';
import ReactDOM from 'react-dom';  
import cx from 'classnames';
import s from './form.scss';
import {Row, Col,Form} from 'antd'; 
import TextField from './TextField';
import MobileField from './MobileField';
import LookupField from './LookupField';
import DateField from './DateField';
import DecimalField from './DecimalField';
import OrgField from './OrgField';
import PositionField from './PositionField'; 
const FormItem = Form.Item;

class NonTabularSection extends React.Component {
	constructor(props) {
        super(props);  
        this.state={ 
        };  
    }
    static propTypes = {   
        nonTabularSection:PropTypes.array,
        fields:PropTypes.object,
        readOnly:PropTypes.bool 
    } 
    static defaultProps={
        readOnly:false
    }
    
    componentDidMount(){ 
    } 
    render(){  
    	const self=this;  
        const {nonTabularSection,fields={},readOnly,employee}=this.props;  
        if(readOnly){
            return(
                <div style={{margin:'20px auto',float:'left',width:'100%'}}> 
                    {nonTabularSection.map((field,i)=>{
                        const {display_name,options='{}',name,type}=field;
                        return(
                            <Col sm={12} key={i}>
                                {/*<TextField options={fieldOptions} field={fields[name]} name={name} label={display_name}></TextField>*/}
                                <FormItem
                                    label={display_name}
                                    labelCol={{ span: 6 }}
                                    wrapperCol={{span:14 }}
                                    required={options.is_required}  >
                                    {employee[name]}
                                </FormItem> 
                            </Col> 
                        ); 
                    })}
                </div> 
            )
        }else{
            return( 
                <div style={{margin:'20px auto',float:'left',width:'100%'}}> 
                  {nonTabularSection.map((field,i)=>{
                    const {display_name,options='{}',name,type}=field;
                    const fieldOptions=JSON.parse(options); 
                    switch(type) {
                        case 'text':  
                            return(
                                <Col sm={12} key={i}>
                                    <TextField options={fieldOptions} field={fields[name]} name={name} label={display_name}></TextField> 
                                </Col> 
                            );
                        case 'mobile':    
                            return (  
                                <Col sm={12} key={i}>
                                    <MobileField options={fieldOptions} field={fields[name]}  name={name}  label={display_name}></MobileField> 
                                </Col> 
                            );
                        case 'lookup': 
                            const fieldName=fields[name+'_ID'].name;
                            if(fieldName=='organization_ID')
                                return (  
                                    <Col sm={12} key={i}>
                                        <OrgField options={fieldOptions} field={fields[name+'_ID']}  name={name}  label={display_name}></OrgField> 
                                    </Col> 
                                );
                            else if(fieldName=='position_ID'){
                                return (  
                                    <Col sm={12} key={i}>
                                        <PositionField options={fieldOptions} field={fields[name+'_ID']}  name={name}  label={display_name}></PositionField> 
                                    </Col> 
                                );
                            }
                        case 'email':
                            return (  
                                <Col sm={12} key={i}>
                                    <TextField options={fieldOptions} field={fields[name]}  name={name}  label={display_name}></TextField> 
                                </Col> 
                            );
                        case 'date':
                            return (  
                                <Col sm={12} key={i}>
                                    <DateField options={fieldOptions} field={fields[name]}  name={name}  label={display_name}></DateField> 
                                </Col> 
                            );
                        case 'datetime':
                            return (  
                                <Col sm={12} key={i}>
                                    <DateField options={fieldOptions} field={fields[name]}  name={name}  label={display_name}></DateField> 
                                </Col> 
                            );
                        case 'dropdown':
                            return (  
                                <Col sm={12} key={i}>
                                    <TextField options={fieldOptions} field={fields[name]}  name={name}  label={display_name}></TextField> 
                                </Col> 
                            );
                        case 'number':    
                            return (  
                                <Col sm={12} key={i}>
                                    <TextField options={fieldOptions} field={fields[name]}  name={name}  label={display_name}></TextField> 
                                </Col> 
                            );
                        case 'decimal':
                            return (  
                                <Col sm={12} key={i}>
                                    <DecimalField options={fieldOptions} field={fields[name]}  name={name}  label={display_name}></DecimalField>
                                </Col> 
                            );
                        default:
                            return (  
                                <Col sm={12} key={i}>
                                    <TextField options={fieldOptions} field={fields[name]}  name={name}  label={display_name}></TextField> 
                                </Col> 
                            );
                    } 
                  })}
                </div> 
            )
        }
        
    }
}

 
export default NonTabularSection;