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
|
|
|
|
|
|
|
import UserActions from '../../actions/user_actions';
|
|
|
|
import UserStore from '../../stores/user_store';
|
|
|
|
|
2015-10-30 11:10:31 +01:00
|
|
|
import ConsignButton from './acls/consign_button';
|
|
|
|
import LoanButton from './acls/loan_button';
|
|
|
|
import LoanRequestButton from './acls/loan_request_button';
|
|
|
|
import ShareButton from './acls/share_button';
|
|
|
|
import TransferButton from './acls/transfer_button';
|
|
|
|
import UnconsignButton from './acls/unconsign_button';
|
2015-06-03 10:27:11 +02:00
|
|
|
|
2015-10-23 09:29:17 +02:00
|
|
|
import { mergeOptions } 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: {
|
2015-06-05 16:20:28 +02:00
|
|
|
className: React.PropTypes.string,
|
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,
|
|
|
|
availableAcls: React.PropTypes.object.isRequired,
|
2015-09-28 22:09:25 +02:00
|
|
|
buttonsStyle: React.PropTypes.object,
|
2015-10-30 11:10:31 +01:00
|
|
|
handleSuccess: React.PropTypes.func.isRequired,
|
2015-07-13 17:09:44 +02:00
|
|
|
children: React.PropTypes.oneOfType([
|
|
|
|
React.PropTypes.arrayOf(React.PropTypes.element),
|
|
|
|
React.PropTypes.element
|
|
|
|
])
|
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() {
|
2015-10-23 09:29:17 +02:00
|
|
|
return mergeOptions(
|
|
|
|
UserStore.getState(),
|
|
|
|
{
|
|
|
|
buttonListSize: 0
|
|
|
|
}
|
|
|
|
);
|
2015-06-03 10:27:11 +02:00
|
|
|
},
|
|
|
|
|
2015-06-03 11:49:39 +02:00
|
|
|
componentDidMount() {
|
2015-06-03 10:27:11 +02:00
|
|
|
UserStore.listen(this.onChange);
|
2015-06-03 11:49:39 +02:00
|
|
|
UserActions.fetchCurrentUser();
|
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) {
|
|
|
|
if(prevProps.availableAcls && prevProps.availableAcls !== this.props.availableAcls) {
|
|
|
|
window.dispatchEvent(new Event('resize'));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-06-05 15:17:35 +02:00
|
|
|
componentWillUnmount() {
|
2015-06-03 10:27:11 +02:00
|
|
|
UserStore.unlisten(this.onChange);
|
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-06-05 15:17:35 +02:00
|
|
|
onChange(state) {
|
|
|
|
this.setState(state);
|
|
|
|
},
|
|
|
|
|
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() {
|
2015-10-23 09:29:17 +02:00
|
|
|
const { className,
|
|
|
|
buttonsStyle,
|
|
|
|
availableAcls,
|
2015-11-02 15:19:52 +01:00
|
|
|
pieceOrEditions,
|
2015-10-23 09:29:17 +02:00
|
|
|
handleSuccess } = this.props;
|
|
|
|
|
|
|
|
const { currentUser } = this.state;
|
|
|
|
|
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}>
|
2015-10-30 11:10:31 +01:00
|
|
|
<ShareButton
|
2015-10-23 09:29:17 +02:00
|
|
|
availableAcls={availableAcls}
|
2015-11-02 15:19:52 +01:00
|
|
|
pieceOrEditions={pieceOrEditions}
|
2015-10-23 09:29:17 +02:00
|
|
|
currentUser={currentUser}
|
|
|
|
handleSuccess={handleSuccess} />
|
2015-10-30 11:10:31 +01:00
|
|
|
<TransferButton
|
2015-10-23 09:29:17 +02:00
|
|
|
availableAcls={availableAcls}
|
2015-11-02 15:19:52 +01:00
|
|
|
pieceOrEditions={pieceOrEditions}
|
2015-10-23 09:29:17 +02:00
|
|
|
currentUser={currentUser}
|
|
|
|
handleSuccess={handleSuccess}/>
|
2015-10-30 11:10:31 +01:00
|
|
|
<ConsignButton
|
2015-10-23 09:29:17 +02:00
|
|
|
availableAcls={availableAcls}
|
2015-11-02 15:19:52 +01:00
|
|
|
pieceOrEditions={pieceOrEditions}
|
2015-10-23 09:29:17 +02:00
|
|
|
currentUser={currentUser}
|
|
|
|
handleSuccess={handleSuccess} />
|
2015-10-30 11:10:31 +01:00
|
|
|
<UnconsignButton
|
2015-10-23 09:29:17 +02:00
|
|
|
availableAcls={availableAcls}
|
2015-11-02 15:19:52 +01:00
|
|
|
pieceOrEditions={pieceOrEditions}
|
2015-10-23 09:29:17 +02:00
|
|
|
currentUser={currentUser}
|
|
|
|
handleSuccess={handleSuccess} />
|
2015-10-30 11:10:31 +01:00
|
|
|
<LoanButton
|
2015-10-23 09:29:17 +02:00
|
|
|
availableAcls={availableAcls}
|
2015-11-02 15:19:52 +01:00
|
|
|
pieceOrEditions={pieceOrEditions}
|
2015-10-23 09:29:17 +02:00
|
|
|
currentUser={currentUser}
|
|
|
|
handleSuccess={handleSuccess} />
|
|
|
|
{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;
|