1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 17:45:10 +01:00
onion/js/components/ascribe_forms/form_contract_agreement.js

139 lines
4.8 KiB
JavaScript
Raw Normal View History

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
import GlobalNotificationModel from '../../models/global_notification_model';
import GlobalNotificationActions from '../../actions/global_notification_actions';
2015-08-18 16:24:36 +02:00
import Form from './form';
import Property from './property';
import PropertyCollapsible from './property_collapsible';
import InputTextAreaToggable from './input_textarea_toggable';
2015-08-18 16:24:36 +02:00
import ApiUrls from '../../constants/api_urls';
2015-08-18 16:24:36 +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);
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);
},
2015-09-02 14:39:32 +02:00
getFormData(){
return {'appendix': {'default': this.refs.form.refs.appendix.value}}
},
2015-08-18 16:24:36 +02:00
getContracts() {
2015-09-02 14:39:32 +02:00
if (this.state.contractList && this.state.contractList.count > 0) {
let contractList = this.state.contractList.results;
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}
value={ contract.name }>
{ 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-08-18 16:24:36 +02:00
handleSuccess={this.props.handleSuccess}
buttons={<button
type="submit"
className="btn ascribe-btn ascribe-btn-login">
{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">
<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()}
<PropertyCollapsible
2015-08-18 16:24:36 +02:00
name='appendix'
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;