1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-24 10:16:29 +02:00
onion/js/components/ascribe_buttons/acl_button_list.js

99 lines
2.9 KiB
JavaScript
Raw Normal View History

2015-06-05 15:17:35 +02:00
'use strict';
import React from 'react/addons';
2015-06-03 10:27:11 +02:00
import ConsignButton from './acls/consign_button';
import EmailButton from './acls/email_button';
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
import { selectFromObject } from '../../utils/general_utils';
2015-06-03 10:27:11 +02:00
let AclButtonList = React.createClass({
2015-06-05 15:17:35 +02:00
propTypes: {
availableAcls: React.PropTypes.object.isRequired,
currentUser: React.PropTypes.object.isRequired,
handleSuccess: React.PropTypes.func.isRequired,
pieceOrEditions: React.PropTypes.oneOfType([
2015-07-13 17:09:44 +02:00
React.PropTypes.object,
React.PropTypes.array
]).isRequired,
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
]),
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() {
return {
buttonListSize: 0
}
2015-06-03 10:27:11 +02:00
},
2015-06-03 11:49:39 +02:00
componentDidMount() {
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) {
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() {
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
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,
buttonsStyle,
2016-02-08 14:08:54 +01:00
className,
currentUser,
handleSuccess,
pieceOrEditions } = this.props;
const buttonProps = selectFromObject(this.props, [
'availableAcls',
'currentUser',
'handleSuccess',
'pieceOrEditions'
]);
2015-06-03 11:49:39 +02:00
return (
<div className={className}>
<span ref="buttonList" style={buttonsStyle}>
<EmailButton {...buttonProps} />
<TransferButton {...buttonProps} />
<ConsignButton {...buttonProps} />
<UnconsignButton {...buttonProps} />
<LoanButton {...buttonProps} />
{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
}
});
export default AclButtonList;