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

222 lines
7.3 KiB
JavaScript
Raw Normal View History

'use strict';
2015-05-29 16:53:30 +02:00
import React from 'react';
2015-08-12 13:34:41 +02:00
import classnames from 'classnames';
2015-07-15 17:51:09 +02:00
import Button from 'react-bootstrap/lib/Button';
import ContractAgreementListStore from '../../stores/contract_agreement_list_store';
2015-07-15 17:51:09 +02:00
import Form from './form';
import Property from './property';
2015-07-15 17:51:09 +02:00
import InputDate from './input_date';
import InputTextAreaToggable from './input_textarea_toggable';
import InputContractAgreementCheckbox from './input_contract_agreement_checkbox';
import AscribeSpinner from '../ascribe_spinner';
2015-06-05 11:40:49 +02:00
import AclInformation from '../ascribe_buttons/acl_information';
2015-07-15 17:51:09 +02:00
import { getLangText } from '../../utils/lang_utils';
import { mergeOptions } from '../../utils/general_utils';
2015-07-03 19:08:56 +02:00
2015-06-01 13:02:53 +02:00
let LoanForm = React.createClass({
2015-07-15 17:51:09 +02:00
propTypes: {
2015-08-12 14:40:44 +02:00
loanHeading: React.PropTypes.string,
2015-08-12 13:34:41 +02:00
email: React.PropTypes.string,
gallery: React.PropTypes.string,
startDate: React.PropTypes.object,
endDate: React.PropTypes.object,
2015-08-12 13:34:41 +02:00
showPersonalMessage: React.PropTypes.bool,
2015-08-26 09:50:38 +02:00
showEndDate: React.PropTypes.bool,
showStartDate: React.PropTypes.bool,
showPassword: React.PropTypes.bool,
2015-07-15 17:51:09 +02:00
url: React.PropTypes.string,
id: React.PropTypes.object,
message: React.PropTypes.string,
createPublicContractAgreement: React.PropTypes.bool,
handleSuccess: React.PropTypes.func,
children: React.PropTypes.oneOfType([
React.PropTypes.object,
React.PropTypes.array
])
2015-07-15 17:51:09 +02:00
},
2015-08-12 13:34:41 +02:00
getDefaultProps() {
return {
2015-08-12 14:40:44 +02:00
loanHeading: '',
2015-08-26 09:50:38 +02:00
showPersonalMessage: true,
2015-08-26 17:32:42 +02:00
showEndDate: true,
showStartDate: true,
showPassword: true
2015-08-12 13:34:41 +02:00
};
},
getInitialState() {
return {
email: this.props.email || ''
};
},
onChange(state) {
this.setState(state);
},
handleEmailOnChange(event) {
// event.target.value is the submitted email of the loanee
this.setState({
email: event && event.target && event.target.value || ''
});
2015-06-01 13:02:53 +02:00
},
2015-07-15 17:51:09 +02:00
handleReset() {
this.handleEmailOnChange();
2015-09-21 10:54:13 +02:00
},
getFormData() {
return this.props.id;
},
2015-08-12 13:34:41 +02:00
getButtons() {
2015-08-12 14:40:44 +02:00
if(this.props.loanHeading) {
2015-08-12 13:34:41 +02:00
return (
<button
type="submit"
2015-10-12 17:55:02 +02:00
className="btn btn-default btn-wide">
2015-08-12 13:34:41 +02:00
{getLangText('Finish process')}
</button>
);
} else {
return (
<div className="modal-footer">
<p className="pull-right">
<Button
className="btn btn-default btn-sm ascribe-margin-1px"
type="submit">
{getLangText('LOAN')}
</Button>
</p>
</div>
);
}
},
2015-08-12 13:34:41 +02:00
render() {
const { email } = this.state;
const {
children,
createPublicContractAgreement,
email: defaultEmail,
handleSuccess,
gallery,
loanHeading,
message,
showPersonalMessage,
endDate,
startDate,
showEndDate,
showStartDate,
showPassword,
url } = this.props;
2015-05-29 16:53:30 +02:00
return (
2015-07-15 17:51:09 +02:00
<Form
className={classnames({'ascribe-form-bordered': loanHeading})}
2015-07-15 17:51:09 +02:00
ref='form'
url={url}
2015-07-15 17:51:09 +02:00
getFormData={this.getFormData}
onReset={this.handleReset}
handleSuccess={handleSuccess}
2015-08-12 13:34:41 +02:00
buttons={this.getButtons()}
2015-07-15 17:51:09 +02:00
spinner={
<div className="modal-footer">
<p className="pull-right">
<AscribeSpinner color='dark-blue' size='md'/>
</p>
2015-07-15 17:51:09 +02:00
</div>}>
<div className={classnames({'ascribe-form-header': true, 'hidden': !loanHeading})}>
<h3>{loanHeading}</h3>
2015-08-12 13:34:41 +02:00
</div>
2015-10-15 11:17:16 +02:00
<AclInformation aim={'form'} verbs={['acl_loan']}/>
2015-07-15 17:51:09 +02:00
<Property
name='loanee'
label={getLangText('Loanee Email')}
editable={!defaultEmail}
onChange={this.handleEmailOnChange}
overrideForm={!!defaultEmail}>
2015-07-15 17:51:09 +02:00
<input
value={email}
2015-07-15 17:51:09 +02:00
type="email"
placeholder={getLangText('Email of the loanee')}
required/>
</Property>
<Property
2015-08-26 09:50:38 +02:00
name='gallery'
2015-08-12 13:34:41 +02:00
label={getLangText('Gallery/exhibition (optional)')}
editable={!gallery}
overrideForm={!!gallery}>
2015-07-15 17:51:09 +02:00
<input
value={gallery}
2015-07-15 17:51:09 +02:00
type="text"
placeholder={getLangText('Gallery/exhibition (optional)')}/>
</Property>
<Property
name='startdate'
2015-08-12 13:34:41 +02:00
label={getLangText('Start date')}
editable={!startDate}
overrideForm={!!startDate}
expanded={showStartDate}>
2015-07-15 17:51:09 +02:00
<InputDate
defaultValue={startDate}
2015-07-15 17:51:09 +02:00
placeholderText={getLangText('Loan start date')} />
</Property>
<Property
name='enddate'
editable={!endDate}
overrideForm={!!endDate}
2015-08-12 13:34:41 +02:00
label={getLangText('End date')}
expanded={showEndDate}>
2015-07-15 17:51:09 +02:00
<InputDate
defaultValue={endDate}
2015-07-15 17:51:09 +02:00
placeholderText={getLangText('Loan end date')} />
</Property>
<Property
name='loan_message'
label={getLangText('Personal Message')}
2015-08-12 13:34:41 +02:00
editable={true}
overrideForm={true}
expanded={showPersonalMessage}>
2015-07-15 17:51:09 +02:00
<InputTextAreaToggable
rows={1}
defaultValue={message}
2015-07-15 17:51:09 +02:00
placeholder={getLangText('Enter a message...')}
required={showPersonalMessage}/>
2015-07-15 17:51:09 +02:00
</Property>
<Property
name='contract_agreement'
label={getLangText('Loan Contract')}
className="ascribe-property-collapsible-toggle"
style={{paddingBottom: 0}}>
<InputContractAgreementCheckbox
createPublicContractAgreement={createPublicContractAgreement}
email={email} />
</Property>
2015-07-15 17:51:09 +02:00
<Property
name='password'
2015-08-26 09:50:38 +02:00
label={getLangText('Password')}
expanded={showPassword}>
2015-07-15 17:51:09 +02:00
<input
type="password"
placeholder={getLangText('Enter your password')}
2015-12-04 16:34:25 +01:00
required={showPassword}/>
2015-07-15 17:51:09 +02:00
</Property>
{children}
2015-07-15 17:51:09 +02:00
</Form>
2015-05-29 16:53:30 +02:00
);
}
});
export default LoanForm;