2015-06-05 11:06:36 +02:00
|
|
|
'use strict';
|
2015-05-29 16:53:30 +02:00
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import ApiUrls from '../../constants/api_urls';
|
|
|
|
import FormMixin from '../../mixins/form_mixin';
|
|
|
|
import InputText from './input_text';
|
2015-06-01 13:02:53 +02:00
|
|
|
import InputHidden from './input_hidden';
|
|
|
|
import InputCheckbox from './input_checkbox';
|
2015-06-01 14:16:06 +02:00
|
|
|
import InputDate from './input_date';
|
2015-05-29 16:53:30 +02:00
|
|
|
import InputTextArea from './input_textarea';
|
2015-06-05 11:40:49 +02:00
|
|
|
|
2015-06-05 11:06:36 +02:00
|
|
|
import OwnershipFetcher from '../../fetchers/ownership_fetcher';
|
2015-06-05 14:22:02 +02:00
|
|
|
import ButtonSubmitOrClose from '../ascribe_buttons/button_submit_close';
|
2015-05-29 16:53:30 +02:00
|
|
|
|
2015-06-01 13:02:53 +02:00
|
|
|
let LoanForm = React.createClass({
|
2015-06-05 11:06:36 +02:00
|
|
|
|
|
|
|
getInitialState() {
|
|
|
|
this.setState({
|
|
|
|
contract_key: null,
|
|
|
|
contract_url: null,
|
|
|
|
loaneeHasContract: false
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-05-29 16:53:30 +02:00
|
|
|
mixins: [FormMixin],
|
|
|
|
|
|
|
|
url() {
|
2015-06-05 11:06:36 +02:00
|
|
|
return ApiUrls.ownership_loans;
|
2015-05-29 16:53:30 +02:00
|
|
|
},
|
2015-06-05 11:06:36 +02:00
|
|
|
|
2015-05-29 16:53:30 +02:00
|
|
|
getFormData() {
|
|
|
|
return {
|
2015-06-02 14:00:05 +02:00
|
|
|
bitcoin_id: this.getBitcoinIds().join(),
|
2015-06-01 13:02:53 +02:00
|
|
|
loanee: this.refs.loanee.state.value,
|
|
|
|
gallery_name: this.refs.gallery_name.state.value,
|
2015-06-02 18:43:37 +02:00
|
|
|
startdate: this.refs.startdate.state.value_formatted,
|
|
|
|
enddate: this.refs.enddate.state.value_formatted,
|
2015-06-01 13:02:53 +02:00
|
|
|
loan_message: this.refs.loan_message.state.value,
|
|
|
|
password: this.refs.password.state.value,
|
|
|
|
terms: this.refs.terms.state.value
|
2015-06-05 11:06:36 +02:00
|
|
|
};
|
2015-05-29 16:53:30 +02:00
|
|
|
},
|
2015-06-05 11:06:36 +02:00
|
|
|
|
|
|
|
handleLoanEmailBlur(){
|
2015-06-01 13:02:53 +02:00
|
|
|
OwnershipFetcher.fetchLoanContract(this.refs.loanee.state.value)
|
|
|
|
.then((res) => {
|
|
|
|
if (res && res.length > 0) {
|
2015-06-05 11:06:36 +02:00
|
|
|
this.setState({
|
|
|
|
contract_key: res[0].s3Key,
|
|
|
|
contract_url: res[0].s3Url,
|
|
|
|
loaneeHasContract: true
|
|
|
|
});
|
2015-06-01 13:02:53 +02:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
this.resetLoanContract();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.log(err);
|
|
|
|
this.resetLoanContract();
|
|
|
|
});
|
|
|
|
},
|
2015-06-05 11:06:36 +02:00
|
|
|
|
2015-06-01 13:02:53 +02:00
|
|
|
resetLoanContract(){
|
|
|
|
this.setState({contract_key: null,
|
|
|
|
contract_url: null,
|
|
|
|
loaneeHasContract: false
|
|
|
|
});
|
|
|
|
},
|
2015-06-05 11:06:36 +02:00
|
|
|
|
2015-05-29 16:53:30 +02:00
|
|
|
renderForm() {
|
2015-06-05 11:06:36 +02:00
|
|
|
let title = this.getTitlesString().join('');
|
2015-05-29 16:53:30 +02:00
|
|
|
let username = this.props.currentUser.username;
|
|
|
|
let message =
|
|
|
|
`Hi,
|
|
|
|
|
2015-06-02 14:00:05 +02:00
|
|
|
I loan :
|
|
|
|
${title}to you.
|
2015-05-29 16:53:30 +02:00
|
|
|
|
|
|
|
Truly yours,
|
|
|
|
${username}`;
|
2015-06-02 14:00:05 +02:00
|
|
|
|
2015-06-01 13:02:53 +02:00
|
|
|
let contract = <InputHidden ref="terms" value="True"/>;
|
|
|
|
if (this.state.loaneeHasContract){
|
2015-06-05 11:06:36 +02:00
|
|
|
let label = (<div>
|
2015-06-01 13:02:53 +02:00
|
|
|
I agree to the
|
|
|
|
<a href={this.state.contract_url} target="_blank">
|
|
|
|
terms of {this.refs.loanee.state.value}
|
|
|
|
</a>
|
2015-06-05 11:06:36 +02:00
|
|
|
</div>);
|
|
|
|
contract = (<InputCheckbox
|
2015-06-01 13:02:53 +02:00
|
|
|
ref="terms"
|
|
|
|
required="required"
|
|
|
|
label={label}
|
2015-06-05 11:06:36 +02:00
|
|
|
/>);
|
2015-06-01 13:02:53 +02:00
|
|
|
}
|
2015-06-05 11:06:36 +02:00
|
|
|
|
2015-05-29 16:53:30 +02:00
|
|
|
return (
|
2015-06-01 13:02:53 +02:00
|
|
|
<form id="loan_modal_content" role="form" onSubmit={this.submit}>
|
|
|
|
<input className="invisible" type="email" name="fake_loanee"/>
|
2015-05-29 16:53:30 +02:00
|
|
|
<input className="invisible" type="password" name="fake_password"/>
|
|
|
|
<InputText
|
2015-06-01 13:02:53 +02:00
|
|
|
ref="loanee"
|
|
|
|
placeHolder="Loanee email"
|
2015-05-29 16:53:30 +02:00
|
|
|
required="required"
|
|
|
|
type="email"
|
2015-06-01 13:02:53 +02:00
|
|
|
submitted={this.state.submitted}
|
|
|
|
onBlur={this.handleLoanEmailBlur}/>
|
|
|
|
<InputText
|
|
|
|
ref="gallery_name"
|
|
|
|
placeHolder="Gallery/exhibition (optional)"
|
|
|
|
required=""
|
|
|
|
type="text"
|
2015-05-29 16:53:30 +02:00
|
|
|
submitted={this.state.submitted}/>
|
2015-06-01 13:02:53 +02:00
|
|
|
<div className="row">
|
2015-06-02 18:43:37 +02:00
|
|
|
<div className="col-xs-6">
|
2015-06-01 14:49:13 +02:00
|
|
|
<InputDate
|
|
|
|
ref="startdate"
|
|
|
|
placeholderText="Loan start date" />
|
2015-06-01 13:02:53 +02:00
|
|
|
</div>
|
2015-06-02 18:43:37 +02:00
|
|
|
<div className="col-xs-6 form-group">
|
2015-06-02 15:38:47 +02:00
|
|
|
<InputDate
|
2015-06-01 13:02:53 +02:00
|
|
|
ref="enddate"
|
2015-06-02 15:38:47 +02:00
|
|
|
placeholderText="Loan end date" />
|
2015-06-01 13:02:53 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2015-05-29 16:53:30 +02:00
|
|
|
<InputTextArea
|
2015-06-01 13:02:53 +02:00
|
|
|
ref="loan_message"
|
2015-05-29 16:53:30 +02:00
|
|
|
defaultValue={message}
|
|
|
|
required=""
|
|
|
|
/>
|
|
|
|
<InputText
|
|
|
|
ref="password"
|
|
|
|
placeHolder="Password"
|
|
|
|
required="required"
|
|
|
|
type="password"
|
|
|
|
submitted={this.state.submitted}/>
|
2015-06-01 13:02:53 +02:00
|
|
|
{contract}
|
|
|
|
<ButtonSubmitOrClose
|
|
|
|
text="LOAN"
|
2015-05-29 16:53:30 +02:00
|
|
|
onClose={this.props.onRequestHide}
|
|
|
|
submitted={this.state.submitted} />
|
|
|
|
</form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-06-01 14:49:13 +02:00
|
|
|
export default LoanForm;
|