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-14 14:16:53 +02:00
|
|
|
ContractListActions.fetchContractList({is_active: true});
|
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() {
|
|
|
|
return (
|
|
|
|
<Form
|
|
|
|
className="ascribe-form-bordered ascribe-form-wrapper"
|
|
|
|
ref='form'
|
2015-09-02 14:39:32 +02:00
|
|
|
url={ApiUrls.ownership_contract_agreements}
|
|
|
|
getFormData={this.getFormData}
|
2015-09-09 13:53:03 +02:00
|
|
|
handleSuccess={this.handleSubmitSuccess}
|
2015-08-18 16:24:36 +02:00
|
|
|
buttons={<button
|
|
|
|
type="submit"
|
|
|
|
className="btn ascribe-btn ascribe-btn-login">
|
2015-08-27 17:33:51 +02:00
|
|
|
{getLangText('Send loan request')}
|
2015-08-18 16:24:36 +02:00
|
|
|
</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">
|
2015-08-27 17:33:51 +02:00
|
|
|
<h3>{getLangText('Contract form')}</h3>
|
2015-08-18 16:24:36 +02:00
|
|
|
</div>
|
|
|
|
<Property
|
2015-09-02 14:39:32 +02:00
|
|
|
name='signee'
|
2015-08-18 16:24:36 +02:00
|
|
|
label={getLangText('Artist Email')}>
|
|
|
|
<input
|
|
|
|
type="email"
|
2015-08-24 11:22:44 +02:00
|
|
|
placeholder={getLangText('(e.g. andy@warhol.co.uk)')}
|
2015-08-18 16:24:36 +02:00
|
|
|
required/>
|
|
|
|
</Property>
|
|
|
|
{this.getContracts()}
|
2015-08-27 17:33:51 +02:00
|
|
|
<PropertyCollapsible
|
2015-08-18 16:24:36 +02:00
|
|
|
name='appendix'
|
2015-08-27 17:33:51 +02:00
|
|
|
checkboxLabel={getLangText('Add appendix to the contract')}>
|
|
|
|
<span>{getLangText('Appendix')}</span>
|
|
|
|
<InputTextAreaToggable
|
|
|
|
rows={1}
|
|
|
|
editable={true}
|
|
|
|
placeholder={getLangText('This will be appended to the contract selected above')}/>
|
|
|
|
</PropertyCollapsible>
|
2015-08-18 16:24:36 +02:00
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-09-02 14:39:32 +02:00
|
|
|
export default ContractAgreementForm;
|