1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 09:50:31 +01:00
onion/js/components/ascribe_forms/form_contract_agreement.js
Tim Daubenschütz f0d8e32ecf Merge remote-tracking branch 'origin/master' into AD-1080-restyle-webapp-with-new-corporate-identity
Conflicts:
	js/components/ascribe_accordion_list/accordion_list_item_piece.js
	js/components/ascribe_app.js
	js/components/ascribe_piece_list_toolbar/piece_list_toolbar.js
	js/components/logout_container.js
	js/components/whitelabel/wallet/wallet_app.js
2015-10-19 10:30:14 +02:00

151 lines
5.3 KiB
JavaScript

'use strict';
import React from 'react';
import { History } from 'react-router';
import ContractListActions from '../../actions/contract_list_actions';
import ContractListStore from '../../stores/contract_list_store';
import GlobalNotificationModel from '../../models/global_notification_model';
import GlobalNotificationActions from '../../actions/global_notification_actions';
import Form from './form';
import Property from './property';
import PropertyCollapsible from './property_collapsible';
import InputTextAreaToggable from './input_textarea_toggable';
import ApiUrls from '../../constants/api_urls';
import AscribeSpinner from '../ascribe_spinner';
import { getLangText } from '../../utils/lang_utils';
import { mergeOptions } from '../../utils/general_utils';
let ContractAgreementForm = React.createClass({
propTypes: {
handleSuccess: React.PropTypes.func
},
mixins: [History],
getInitialState() {
return mergeOptions(
ContractListStore.getState(),
{
selectedContract: 0
}
);
},
componentDidMount() {
ContractListStore.listen(this.onChange);
ContractListActions.fetchContractList(true, false);
},
componentWillUnmount() {
ContractListStore.unlisten(this.onChange);
},
onChange(state) {
this.setState(state);
},
onContractChange(event){
this.setState({selectedContract: event.target.selectedIndex});
},
handleSubmitSuccess() {
let notification = 'Contract agreement send';
notification = new GlobalNotificationModel(notification, 'success', 10000);
GlobalNotificationActions.appendGlobalNotification(notification);
this.history.pushState(null, '/collection');
},
getFormData(){
return {'appendix': {'default': this.refs.form.refs.appendix.state.value}};
},
getContracts() {
if (this.state.contractList && this.state.contractList.length > 0) {
let contractList = this.state.contractList;
return (
<Property
name='contract'
label={getLangText('Contract Type')}
onChange={this.onContractChange}>
<select name="contract">
{contractList.map((contract, i) => {
return (
<option
name={i}
key={i}
value={ contract.id }>
{ contract.name }
</option>
);
})}
</select>
</Property>);
}
return null;
},
render() {
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 btn-default btn-wide">
{getLangText('Send contract')}
</button>}
spinner={
<span className="btn btn-default btn-wide btn-spinner">
<AscribeSpinner color="dark-blue" size="md" />
</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>
{/* We're using disabled on a form here as PropertyCollapsible currently
does not support the disabled + overrideForm functionality */}
<InputTextAreaToggable
rows={1}
disabled={false}
placeholder={getLangText('This will be appended to the contract selected above')}/>
</PropertyCollapsible>
</Form>
);
}
return (
<div>
<p className="text-center">
{getLangText('No contracts uploaded yet, please go to the ')}
<a href="contract_settings">{getLangText('contract settings page')}</a>
{getLangText(' and create them.')}
</p>
</div>
);
}
});
export default ContractAgreementForm;