2015-08-18 16:24:36 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
2015-10-01 11:16:38 +02:00
|
|
|
import { History } from 'react-router';
|
2015-08-18 16:24:36 +02:00
|
|
|
|
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-10-12 17:55:02 +02:00
|
|
|
import AscribeSpinner from '../ascribe_spinner';
|
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-09-25 15:39:36 +02:00
|
|
|
propTypes: {
|
2015-08-24 11:22:44 +02:00
|
|
|
handleSuccess: React.PropTypes.func
|
2015-09-25 15:39:36 +02:00
|
|
|
},
|
|
|
|
|
2015-10-01 11:16:38 +02:00
|
|
|
mixins: [History],
|
2015-08-24 11:22:44 +02:00
|
|
|
|
2015-09-25 15:39:36 +02:00
|
|
|
getInitialState() {
|
2015-08-18 16:24:36 +02:00
|
|
|
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-10-01 11:16:38 +02:00
|
|
|
|
2015-10-01 14:30:11 +02:00
|
|
|
this.history.pushState(null, '/collection');
|
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')}
|
2015-09-22 13:20:55 +02:00
|
|
|
onChange={this.onContractChange}>
|
2015-08-18 16:24:36 +02:00
|
|
|
<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"
|
2015-10-12 17:55:02 +02:00
|
|
|
className="btn btn-default btn-wide">
|
2015-09-28 11:51:02 +02:00
|
|
|
{getLangText('Send contract')}
|
2015-09-16 14:07:13 +02:00
|
|
|
</button>}
|
|
|
|
spinner={
|
2015-10-12 17:55:02 +02:00
|
|
|
<span className="btn btn-default btn-wide btn-spinner">
|
|
|
|
<AscribeSpinner color="dark-blue" size="md" />
|
2015-09-16 14:07:13 +02:00
|
|
|
</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">
|
2015-09-22 14:13:04 +02:00
|
|
|
{getLangText('No contracts uploaded yet, please go to the ')}
|
2015-10-01 15:57:46 +02:00
|
|
|
<a href="contract_settings">{getLangText('contract settings page')}</a>
|
2015-09-16 14:07:13 +02:00
|
|
|
{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;
|