'use strict'; import React from 'react'; import classnames from 'classnames'; import Button from 'react-bootstrap/lib/Button'; import Form from './form'; import Property from './property'; import InputTextAreaToggable from './input_textarea_toggable'; import InputDate from './input_date'; import InputCheckbox from './input_checkbox'; import LoanContractStore from '../../stores/loan_contract_store'; import LoanContractActions from '../../actions/loan_contract_actions'; import AppConstants from '../../constants/application_constants'; import { getLangText } from '../../utils/lang_utils'; let LoanForm = React.createClass({ propTypes: { loanHeading: React.PropTypes.string, email: React.PropTypes.string, gallery: React.PropTypes.string, startdate: React.PropTypes.object, enddate: React.PropTypes.object, showPersonalMessage: React.PropTypes.bool, showEndDate: React.PropTypes.bool, showStartDate: React.PropTypes.bool, showPassword: React.PropTypes.bool, url: React.PropTypes.string, id: React.PropTypes.object, message: React.PropTypes.string, handleSuccess: React.PropTypes.func }, getDefaultProps() { return { loanHeading: '', showPersonalMessage: true, showEndDate: true, showStartDate: true, showPassword: true }; }, getInitialState() { return LoanContractStore.getState(); }, componentDidMount() { LoanContractStore.listen(this.onChange); LoanContractActions.flushLoanContract.defer(); }, componentWillUnmount() { LoanContractStore.unlisten(this.onChange); }, onChange(state) { this.setState(state); }, getFormData(){ return this.props.id; }, handleOnChange(event) { // event.target.value is the submitted email of the loanee if(event && event.target && event.target.value && event.target.value.match(/.*@.*/)) { LoanContractActions.fetchLoanContract(event.target.value); } else { LoanContractActions.flushLoanContract(); } }, getContractCheckbox() { if(this.state.contractKey && this.state.contractUrl) { // we need to define a key on the InputCheckboxes as otherwise // react is not rerendering them on a store switch and is keeping // the default value of the component (which is in that case true) return ( {getLangText('I agree to the')}  {getLangText('terms of')} {this.state.contractEmail} ); } else { return ( ); } }, getButtons() { if(this.props.loanHeading) { return ( ); } else { return (

); } }, render() { return (
}>

{this.props.loanHeading}

{this.getContractCheckbox()} {this.props.children}
); } }); export default LoanForm;