1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-16 09:33:16 +02:00
onion/js/components/ascribe_forms/form_consign.js

146 lines
4.7 KiB
JavaScript
Raw Normal View History

'use strict';
import React from 'react';
2015-07-14 14:16:51 +02:00
import Button from 'react-bootstrap/lib/Button';
2015-07-14 14:16:51 +02:00
import Form from './form';
import Property from './property';
import InputContractAgreementCheckbox from './input_contract_agreement_checkbox';
import InputTextAreaToggable from './input_textarea_toggable';
import AscribeSpinner from '../ascribe_spinner';
2015-11-03 10:39:01 +01:00
import AclInformation from '../ascribe_buttons/acl_information';
2015-07-14 14:16:51 +02:00
import { getLangText } from '../../utils/lang_utils.js';
2015-06-02 11:38:18 +02:00
2015-07-14 14:16:51 +02:00
let ConsignForm = React.createClass({
propTypes: {
url: React.PropTypes.string,
id: React.PropTypes.object,
autoFocusProperty: React.PropTypes.string,
email: React.PropTypes.string,
2015-07-14 14:16:51 +02:00
message: React.PropTypes.string,
labels: React.PropTypes.object,
createPublicContractAgreement: React.PropTypes.bool,
2015-07-14 14:16:51 +02:00
handleSuccess: React.PropTypes.func
},
getDefaultProps() {
return {
labels: {}
};
},
getInitialState() {
return {
2015-12-04 16:34:25 +01:00
email: this.props.email || ''
};
},
componentWillReceiveProps(nextProps) {
if (this.props.email !== nextProps.email) {
this.setState({
email: nextProps.email
});
}
},
getFormData() {
2015-07-14 14:16:51 +02:00
return this.props.id;
},
handleEmailOnChange(event) {
// event.target.value is the submitted email of the consignee
this.setState({
email: event && event.target && event.target.value || ''
});
},
2015-07-14 14:16:51 +02:00
render() {
const { email } = this.state;
const { autoFocusProperty,
createPublicContractAgreement,
email: defaultEmail,
handleSuccess,
id,
message,
labels,
url } = this.props;
return (
2015-07-14 14:16:51 +02:00
<Form
ref='form'
url={url}
2015-07-14 14:16:51 +02:00
getFormData={this.getFormData}
2015-12-04 16:34:25 +01:00
handleSuccess={handleSuccess}
2015-07-14 14:16:51 +02:00
buttons={
<div className="modal-footer">
<p className="pull-right">
<Button
className="btn btn-default btn-sm ascribe-margin-1px"
2015-08-05 18:00:44 +02:00
type="submit">
{getLangText('CONSIGN')}
</Button>
2015-07-14 14:16:51 +02:00
</p>
</div>}
spinner={
<div className="modal-footer">
<p className="pull-right">
<AscribeSpinner color='dark-blue' size='md'/>
</p>
2015-07-14 14:16:51 +02:00
</div>}>
2015-11-03 10:39:01 +01:00
<AclInformation aim={'form'} verbs={['acl_consign']}/>
2015-07-14 14:16:51 +02:00
<Property
autoFocus={autoFocusProperty === 'email'}
2015-07-14 14:16:51 +02:00
name='consignee'
label={labels.email || getLangText('Email')}
editable={!defaultEmail}
onChange={this.handleEmailOnChange}
overrideForm={!!defaultEmail}>
2015-07-14 14:16:51 +02:00
<input
type="email"
value={email}
2015-07-14 14:16:51 +02:00
placeholder={getLangText('Email of the consignee')}
2016-11-07 09:38:49 +01:00
value={getLangText('Admin email')}
2015-07-14 14:16:51 +02:00
required/>
</Property>
<Property
autoFocus={autoFocusProperty === 'message'}
2015-07-14 14:16:51 +02:00
name='consign_message'
label={labels.message || getLangText('Personal Message')}
editable
overrideForm>
2015-07-14 14:16:51 +02:00
<InputTextAreaToggable
rows={1}
defaultValue={message}
2015-07-14 14:16:51 +02:00
placeholder={getLangText('Enter a message...')}
required />
2015-07-14 14:16:51 +02:00
</Property>
<Property
name='contract_agreement'
label={getLangText('Consign Contract')}
className="ascribe-property-collapsible-toggle">
<InputContractAgreementCheckbox
createPublicContractAgreement={createPublicContractAgreement}
email={email} />
</Property>
2015-07-14 14:16:51 +02:00
<Property
name='password'
label={getLangText('Password')}>
<input
type="password"
placeholder={getLangText('Enter your password')}
required/>
</Property>
<hr />
</Form>
);
}
});
export default ConsignForm;