1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 09:50:31 +01:00
onion/js/components/ascribe_forms/form_loan.js

166 lines
5.6 KiB
JavaScript
Raw Normal View History

'use strict';
2015-05-29 16:53:30 +02:00
import React from 'react';
2015-07-15 17:51:09 +02:00
import Button from 'react-bootstrap/lib/Button';
import Form from './form';
import Property from './property';
import InputTextAreaToggable from './input_textarea_toggable';
2015-06-01 14:16:06 +02:00
import InputDate from './input_date';
2015-07-15 17:51:09 +02:00
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';
2015-06-05 11:40:49 +02:00
2015-07-15 17:51:09 +02:00
import { getLangText } from '../../utils/lang_utils';
2015-05-29 16:53:30 +02:00
2015-07-03 19:08:56 +02:00
2015-06-01 13:02:53 +02:00
let LoanForm = React.createClass({
2015-07-15 17:51:09 +02:00
propTypes: {
url: React.PropTypes.string,
id: React.PropTypes.object,
message: React.PropTypes.string,
handleSuccess: React.PropTypes.func
},
getInitialState() {
2015-07-15 17:51:09 +02:00
return LoanContractStore.getState();
},
2015-07-15 17:51:09 +02:00
componentDidMount() {
LoanContractStore.listen(this.onChange);
2015-08-06 15:14:50 +02:00
LoanContractActions.flushLoanContract();
2015-07-15 17:51:09 +02:00
},
2015-05-29 16:53:30 +02:00
2015-07-15 17:51:09 +02:00
componentWillUnmount() {
LoanContractStore.unlisten(this.onChange);
2015-05-29 16:53:30 +02:00
},
2015-07-15 17:51:09 +02:00
onChange(state) {
this.setState(state);
2015-05-29 16:53:30 +02:00
},
2015-07-15 17:51:09 +02:00
getFormData(){
return this.props.id;
2015-06-01 13:02:53 +02:00
},
2015-07-15 17:51:09 +02:00
handleOnBlur(event) {
LoanContractActions.fetchLoanContract(event.target.value);
2015-06-01 13:02:53 +02:00
},
2015-07-15 17:51:09 +02:00
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)
2015-07-15 17:51:09 +02:00
return (
<Property
name="terms"
className="ascribe-settings-property-collapsible-toggle"
style={{paddingBottom: 0}}>
2015-07-28 11:32:16 +02:00
<InputCheckbox
key="terms_explicitly"
2015-07-28 15:33:47 +02:00
defaultChecked={false}>
2015-07-15 17:51:09 +02:00
<span>
2015-07-03 19:08:56 +02:00
{getLangText('I agree to the')}&nbsp;
2015-07-15 17:51:09 +02:00
<a href={this.state.contractUrl} target="_blank">
{getLangText('terms of')} {this.state.contractEmail}
2015-06-01 13:02:53 +02:00
</a>
2015-07-15 17:51:09 +02:00
</span>
</InputCheckbox>
</Property>
);
2015-07-15 17:57:28 +02:00
} else {
return (
<Property
name="terms"
2015-07-28 15:33:47 +02:00
style={{paddingBottom: 0}}
hidden={true}>
<InputCheckbox
key="terms_implicitly"
2015-07-28 15:33:47 +02:00
defaultChecked={true} />
2015-07-15 17:57:28 +02:00
</Property>
);
2015-06-01 13:02:53 +02:00
}
2015-07-15 17:51:09 +02:00
},
render() {
2015-05-29 16:53:30 +02:00
return (
2015-07-15 17:51:09 +02:00
<Form
ref='form'
url={this.props.url}
getFormData={this.getFormData}
handleSuccess={this.props.handleSuccess}
buttons={
<div className="modal-footer">
<p className="pull-right">
<Button
className="btn btn-default btn-sm ascribe-margin-1px"
2015-08-05 18:00:44 +02:00
type="submit">
{getLangText('LOAN')}
</Button>
2015-07-15 17:51:09 +02:00
</p>
</div>}
spinner={
<div className="modal-footer">
<img src={AppConstants.baseUrl + 'static/img/ascribe_animated_small.gif'} />
</div>}>
<Property
name='loanee'
label={getLangText('Loanee Email')}
onBlur={this.handleOnBlur}>
<input
type="email"
placeholder={getLangText('Email of the loanee')}
required/>
</Property>
<Property
name='gallery_name'
2015-07-28 15:33:47 +02:00
label={getLangText('Gallery/exhibition (optional)')}>
2015-07-15 17:51:09 +02:00
<input
type="text"
placeholder={getLangText('Gallery/exhibition (optional)')}/>
</Property>
<Property
name='startdate'
label={getLangText('Start date')}>
<InputDate
placeholderText={getLangText('Loan start date')} />
</Property>
<Property
name='enddate'
label={getLangText('End date')}>
<InputDate
placeholderText={getLangText('Loan end date')} />
</Property>
<Property
name='loan_message'
label={getLangText('Personal Message')}
editable={true}>
<InputTextAreaToggable
rows={1}
editable={true}
defaultValue={this.props.message}
placeholder={getLangText('Enter a message...')}
required="required"/>
</Property>
<Property
name='password'
label={getLangText('Password')}>
<input
type="password"
placeholder={getLangText('Enter your password')}
required/>
</Property>
{this.getContractCheckbox()}
</Form>
2015-05-29 16:53:30 +02:00
);
}
});
2015-07-15 17:51:09 +02:00
export default LoanForm;