2015-06-05 15:17:35 +02:00
|
|
|
'use strict';
|
|
|
|
|
2015-10-23 09:29:17 +02:00
|
|
|
import React from 'react/addons';
|
2015-06-03 10:27:11 +02:00
|
|
|
|
2015-10-30 11:10:31 +01:00
|
|
|
import ConsignButton from './acls/consign_button';
|
2015-11-10 11:53:05 +01:00
|
|
|
import EmailButton from './acls/email_button';
|
2015-10-30 11:10:31 +01:00
|
|
|
import LoanButton from './acls/loan_button';
|
|
|
|
import LoanRequestButton from './acls/loan_request_button';
|
|
|
|
import TransferButton from './acls/transfer_button';
|
|
|
|
import UnconsignButton from './acls/unconsign_button';
|
2015-06-03 10:27:11 +02:00
|
|
|
|
2016-01-11 17:41:31 +01:00
|
|
|
import { selectFromObject } from '../../utils/general_utils';
|
2015-10-23 09:29:17 +02:00
|
|
|
|
2015-06-03 10:27:11 +02:00
|
|
|
let AclButtonList = React.createClass({
|
2015-06-05 15:17:35 +02:00
|
|
|
propTypes: {
|
2016-01-11 17:41:31 +01:00
|
|
|
availableAcls: React.PropTypes.object.isRequired,
|
|
|
|
currentUser: React.PropTypes.object.isRequired,
|
|
|
|
handleSuccess: React.PropTypes.func.isRequired,
|
2015-11-02 15:19:52 +01:00
|
|
|
pieceOrEditions: React.PropTypes.oneOfType([
|
2015-07-13 17:09:44 +02:00
|
|
|
React.PropTypes.object,
|
|
|
|
React.PropTypes.array
|
2015-10-30 11:10:31 +01:00
|
|
|
]).isRequired,
|
2016-01-11 17:41:31 +01:00
|
|
|
|
2015-09-28 22:09:25 +02:00
|
|
|
buttonsStyle: React.PropTypes.object,
|
2015-07-13 17:09:44 +02:00
|
|
|
children: React.PropTypes.oneOfType([
|
|
|
|
React.PropTypes.arrayOf(React.PropTypes.element),
|
|
|
|
React.PropTypes.element
|
2016-01-11 17:41:31 +01:00
|
|
|
]),
|
|
|
|
className: React.PropTypes.string
|
2015-06-03 10:27:11 +02:00
|
|
|
},
|
2015-09-29 10:31:13 +02:00
|
|
|
|
2015-06-05 15:17:35 +02:00
|
|
|
getInitialState() {
|
2016-01-11 17:41:31 +01:00
|
|
|
return {
|
|
|
|
buttonListSize: 0
|
|
|
|
}
|
2015-06-03 10:27:11 +02:00
|
|
|
},
|
|
|
|
|
2015-06-03 11:49:39 +02:00
|
|
|
componentDidMount() {
|
2015-10-23 09:29:17 +02:00
|
|
|
window.addEventListener('resize', this.handleResize);
|
|
|
|
window.dispatchEvent(new Event('resize'));
|
2015-06-03 10:27:11 +02:00
|
|
|
},
|
|
|
|
|
2015-10-23 11:24:26 +02:00
|
|
|
componentDidUpdate(prevProps) {
|
2016-01-11 17:41:31 +01:00
|
|
|
if (prevProps.availableAcls && prevProps.availableAcls !== this.props.availableAcls) {
|
2015-10-23 11:24:26 +02:00
|
|
|
window.dispatchEvent(new Event('resize'));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-06-05 15:17:35 +02:00
|
|
|
componentWillUnmount() {
|
2015-10-23 09:29:17 +02:00
|
|
|
window.removeEventListener('resize', this.handleResize);
|
|
|
|
},
|
|
|
|
|
|
|
|
handleResize() {
|
|
|
|
this.setState({
|
|
|
|
buttonListSize: this.refs.buttonList.getDOMNode().offsetWidth
|
|
|
|
});
|
2015-06-03 10:27:11 +02:00
|
|
|
},
|
2015-06-03 11:49:39 +02:00
|
|
|
|
2015-10-23 09:29:17 +02:00
|
|
|
renderChildren() {
|
|
|
|
const { children } = this.props;
|
|
|
|
const { buttonListSize } = this.state;
|
|
|
|
|
|
|
|
return React.Children.map(children, (child) => {
|
|
|
|
return React.addons.cloneWithProps(child, { buttonListSize });
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-06-03 10:27:11 +02:00
|
|
|
render() {
|
2016-02-08 14:08:54 +01:00
|
|
|
const { availableAcls,
|
2015-10-23 09:29:17 +02:00
|
|
|
buttonsStyle,
|
2016-02-08 14:08:54 +01:00
|
|
|
className,
|
|
|
|
currentUser,
|
|
|
|
handleSuccess,
|
|
|
|
pieceOrEditions } = this.props;
|
2016-01-11 17:41:31 +01:00
|
|
|
|
|
|
|
const buttonProps = selectFromObject(this.props, [
|
|
|
|
'availableAcls',
|
|
|
|
'currentUser',
|
|
|
|
'handleSuccess',
|
|
|
|
'pieceOrEditions'
|
|
|
|
]);
|
2015-10-23 09:29:17 +02:00
|
|
|
|
2015-06-03 11:49:39 +02:00
|
|
|
return (
|
2015-10-23 09:29:17 +02:00
|
|
|
<div className={className}>
|
|
|
|
<span ref="buttonList" style={buttonsStyle}>
|
2016-01-11 17:41:31 +01:00
|
|
|
<EmailButton {...buttonProps} />
|
|
|
|
<TransferButton {...buttonProps} />
|
|
|
|
<ConsignButton {...buttonProps} />
|
|
|
|
<UnconsignButton {...buttonProps} />
|
|
|
|
<LoanButton {...buttonProps} />
|
2015-10-23 09:29:17 +02:00
|
|
|
{this.renderChildren()}
|
2015-09-28 22:09:25 +02:00
|
|
|
</span>
|
2015-06-03 11:49:39 +02:00
|
|
|
</div>
|
|
|
|
);
|
2015-06-03 10:27:11 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-10-30 11:10:31 +01:00
|
|
|
export default AclButtonList;
|