2015-08-18 16:24:36 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
2015-08-28 16:18:10 +02:00
|
|
|
import ContractListActions from '../../actions/contract_list_actions';
|
|
|
|
import ContractListStore from '../../stores/contract_list_store';
|
2015-08-18 16:24:36 +02:00
|
|
|
|
2015-08-27 14:56:49 +02:00
|
|
|
import GlobalNotificationModel from '../../models/global_notification_model';
|
|
|
|
import GlobalNotificationActions from '../../actions/global_notification_actions';
|
2015-08-18 16:24:36 +02:00
|
|
|
|
2015-08-27 14:56:49 +02:00
|
|
|
import Form from './form';
|
2015-08-27 17:33:51 +02:00
|
|
|
import Property from './property';
|
|
|
|
import PropertyCollapsible from './property_collapsible';
|
|
|
|
import InputTextAreaToggable from './input_textarea_toggable';
|
2015-08-18 16:24:36 +02:00
|
|
|
|
2015-08-27 14:56:49 +02:00
|
|
|
import ApiUrls from '../../constants/api_urls';
|
2015-08-18 16:24:36 +02:00
|
|
|
|
2015-08-27 14:56:49 +02:00
|
|
|
import { getLangText } from '../../utils/lang_utils';
|
|
|
|
import { mergeOptions } from '../../utils/general_utils';
|
2015-08-18 16:24:36 +02:00
|
|
|
|
|
|
|
|
2015-09-02 14:39:32 +02:00
|
|
|
let ContractAgreementForm = React.createClass({
|
2015-08-24 11:22:44 +02:00
|
|
|
propTypes: {
|
|
|
|
handleSuccess: React.PropTypes.func
|
|
|
|
},
|
|
|
|
|
2015-08-18 16:24:36 +02:00
|
|
|
getInitialState() {
|
|
|
|
return mergeOptions(
|
2015-08-28 16:18:10 +02:00
|
|
|
ContractListStore.getState(),
|
2015-08-18 16:24:36 +02:00
|
|
|
{
|
|
|
|
selectedContract: 0
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount() {
|
2015-08-28 16:18:10 +02:00
|
|
|
ContractListStore.listen(this.onChange);
|
2015-09-16 14:07:13 +02:00
|
|
|
ContractListActions.fetchContractList(true, false);
|
2015-08-18 16:24:36 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
2015-08-28 16:18:10 +02:00
|
|
|
ContractListStore.unlisten(this.onChange);
|
2015-08-18 16:24:36 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
onChange(state) {
|
|
|
|
this.setState(state);
|
|
|
|
},
|
|
|
|
|
|
|
|
onContractChange(event){
|
|
|
|
this.setState({selectedContract: event.target.selectedIndex});
|
|
|
|
},
|
|
|
|
|
2015-09-09 13:53:03 +02:00
|
|
|
handleSubmitSuccess() {
|
|
|
|
let notification = 'Contract agreement send';
|
|
|
|
notification = new GlobalNotificationModel(notification, 'success', 10000);
|
2015-08-18 16:24:36 +02:00
|
|
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
2015-09-09 19:29:58 +02:00
|
|
|
this.refs.form.reset();
|
2015-08-18 16:24:36 +02:00
|
|
|
},
|
|
|
|
|
2015-09-02 14:39:32 +02:00
|
|
|
getFormData(){
|
2015-09-09 11:11:16 +02:00
|
|
|
return {'appendix': {'default': this.refs.form.refs.appendix.state.value}};
|
2015-09-02 14:39:32 +02:00
|
|
|
},
|
|
|
|
|
2015-08-18 16:24:36 +02:00
|
|
|
getContracts() {
|
2015-09-04 11:49:55 +02:00
|
|
|
if (this.state.contractList && this.state.contractList.length > 0) {
|
|
|
|
let contractList = this.state.contractList;
|
2015-08-18 16:24:36 +02:00
|
|
|
return (
|
|
|
|
<Property
|
|
|
|
name='contract'
|
|
|
|
label={getLangText('Contract Type')}
|
|
|
|
onChange={this.onContractChange}
|
|
|
|
footer={
|
|
|
|
<a
|
|
|
|
className="pull-right"
|
2015-09-02 14:39:32 +02:00
|
|
|
href={contractList[this.state.selectedContract].blob}
|
2015-08-18 16:24:36 +02:00
|
|
|
target="_blank">
|
|
|
|
{getLangText('Learn more')}
|
|
|
|
</a>
|
|
|
|
}>
|
|
|
|
<select name="contract">
|
2015-09-02 14:39:32 +02:00
|
|
|
{contractList.map((contract, i) => {
|
2015-08-18 16:24:36 +02:00
|
|
|
return (
|
|
|
|
<option
|
|
|
|
name={i}
|
|
|
|
key={i}
|
2015-09-04 11:49:55 +02:00
|
|
|
value={ contract.id }>
|
2015-08-18 16:24:36 +02:00
|
|
|
{ contract.name }
|
|
|
|
</option>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</select>
|
|
|
|
</Property>);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
2015-09-16 14:07:13 +02:00
|
|
|
if (this.state.contractList && this.state.contractList.length > 0) {
|
|
|
|
return (
|
|
|
|
<Form
|
|
|
|
className="ascribe-form-bordered ascribe-form-wrapper"
|
|
|
|
ref='form'
|
|
|
|
url={ApiUrls.ownership_contract_agreements}
|
|
|
|
getFormData={this.getFormData}
|
|
|
|
handleSuccess={this.handleSubmitSuccess}
|
|
|
|
buttons={<button
|
|
|
|
type="submit"
|
|
|
|
className="btn ascribe-btn ascribe-btn-login">
|
|
|
|
{getLangText('Send loan request')}
|
|
|
|
</button>}
|
|
|
|
spinner={
|
|
|
|
<span className="btn ascribe-btn ascribe-btn-login ascribe-btn-login-spinner">
|
|
|
|
<img src="https://s3-us-west-2.amazonaws.com/ascribe0/media/thumbnails/ascribe_animated_medium.gif" />
|
|
|
|
</span>
|
|
|
|
}>
|
|
|
|
<div className="ascribe-form-header">
|
|
|
|
<h3>{getLangText('Contract form')}</h3>
|
|
|
|
</div>
|
|
|
|
<Property
|
|
|
|
name='signee'
|
|
|
|
label={getLangText('Artist Email')}>
|
|
|
|
<input
|
|
|
|
type="email"
|
|
|
|
placeholder={getLangText('(e.g. andy@warhol.co.uk)')}
|
|
|
|
required/>
|
|
|
|
</Property>
|
|
|
|
{this.getContracts()}
|
|
|
|
<PropertyCollapsible
|
|
|
|
name='appendix'
|
|
|
|
checkboxLabel={getLangText('Add appendix to the contract')}>
|
|
|
|
<span>{getLangText('Appendix')}</span>
|
2015-09-21 12:05:42 +02:00
|
|
|
{/* We're using disabled on a form here as PropertyCollapsible currently
|
|
|
|
does not support the disabled + overrideForm functionality */}
|
2015-09-16 14:07:13 +02:00
|
|
|
<InputTextAreaToggable
|
|
|
|
rows={1}
|
2015-09-21 12:05:42 +02:00
|
|
|
disabled={false}
|
2015-09-16 14:07:13 +02:00
|
|
|
placeholder={getLangText('This will be appended to the contract selected above')}/>
|
|
|
|
</PropertyCollapsible>
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
}
|
2015-08-18 16:24:36 +02:00
|
|
|
return (
|
2015-09-16 14:07:13 +02:00
|
|
|
<div>
|
|
|
|
<p className="text-center">
|
|
|
|
{getLangText('No private contracts found, please go to the ')}
|
|
|
|
<a href="settings">{getLangText('settings page')}</a>
|
|
|
|
{getLangText(' and create them.')}
|
|
|
|
</p>
|
|
|
|
</div>
|
2015-08-18 16:24:36 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-09-02 14:39:32 +02:00
|
|
|
export default ContractAgreementForm;
|