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
|
|
|
|
|
|
|
|
|
|
|
let ContractForm = 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);
|
|
|
|
ContractListActions.fetchContractList();
|
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});
|
|
|
|
},
|
|
|
|
|
|
|
|
handleSubmitSuccess(response) {
|
|
|
|
let notification = new GlobalNotificationModel(response.notification, 'success', 10000);
|
|
|
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
|
|
|
},
|
|
|
|
|
|
|
|
getContracts() {
|
|
|
|
if (this.state.contractList && this.state.contractList.length > 0) {
|
|
|
|
return (
|
|
|
|
<Property
|
|
|
|
name='contract'
|
|
|
|
label={getLangText('Contract Type')}
|
|
|
|
onChange={this.onContractChange}
|
|
|
|
footer={
|
|
|
|
<a
|
|
|
|
className="pull-right"
|
|
|
|
href={this.state.contractList[this.state.selectedContract].s3UrlSafe}
|
|
|
|
target="_blank">
|
|
|
|
{getLangText('Learn more')}
|
|
|
|
</a>
|
|
|
|
}>
|
|
|
|
<select name="contract">
|
|
|
|
{this.state.contractList.map((contract, i) => {
|
|
|
|
return (
|
|
|
|
<option
|
|
|
|
name={i}
|
|
|
|
key={i}
|
|
|
|
value={ contract.name }>
|
|
|
|
{ contract.name }
|
|
|
|
</option>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</select>
|
|
|
|
</Property>);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Form
|
|
|
|
className="ascribe-form-bordered ascribe-form-wrapper"
|
|
|
|
ref='form'
|
2015-08-31 17:29:43 +02:00
|
|
|
url={ApiUrls.blob_contracts}
|
2015-08-18 16:24:36 +02:00
|
|
|
handleSuccess={this.props.handleSuccess}
|
|
|
|
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
|
|
|
|
name='artist_name'
|
|
|
|
label={getLangText('Artist Name')}>
|
|
|
|
<input
|
|
|
|
type="text"
|
2015-08-24 11:22:44 +02:00
|
|
|
placeholder={getLangText('(e.g. Andy Warhol)')}
|
2015-08-18 16:24:36 +02:00
|
|
|
required/>
|
|
|
|
</Property>
|
|
|
|
<Property
|
|
|
|
name='artist_email'
|
|
|
|
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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default ContractForm;
|