mirror of
https://github.com/ascribe/onion.git
synced 2024-12-23 01:39:36 +01:00
Change AclButtonList and parents for loading UserStore from top level app
This commit is contained in:
parent
f31d6352eb
commit
d4bb00168c
@ -2,9 +2,6 @@
|
|||||||
|
|
||||||
import React from 'react/addons';
|
import React from 'react/addons';
|
||||||
|
|
||||||
import UserActions from '../../actions/user_actions';
|
|
||||||
import UserStore from '../../stores/user_store';
|
|
||||||
|
|
||||||
import ConsignButton from './acls/consign_button';
|
import ConsignButton from './acls/consign_button';
|
||||||
import EmailButton from './acls/email_button';
|
import EmailButton from './acls/email_button';
|
||||||
import LoanButton from './acls/loan_button';
|
import LoanButton from './acls/loan_button';
|
||||||
@ -12,37 +9,33 @@ import LoanRequestButton from './acls/loan_request_button';
|
|||||||
import TransferButton from './acls/transfer_button';
|
import TransferButton from './acls/transfer_button';
|
||||||
import UnconsignButton from './acls/unconsign_button';
|
import UnconsignButton from './acls/unconsign_button';
|
||||||
|
|
||||||
import { mergeOptions } from '../../utils/general_utils';
|
import { selectFromObject } from '../../utils/general_utils';
|
||||||
|
|
||||||
let AclButtonList = React.createClass({
|
let AclButtonList = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
className: React.PropTypes.string,
|
availableAcls: React.PropTypes.object.isRequired,
|
||||||
|
currentUser: React.PropTypes.object.isRequired,
|
||||||
|
handleSuccess: React.PropTypes.func.isRequired,
|
||||||
pieceOrEditions: React.PropTypes.oneOfType([
|
pieceOrEditions: React.PropTypes.oneOfType([
|
||||||
React.PropTypes.object,
|
React.PropTypes.object,
|
||||||
React.PropTypes.array
|
React.PropTypes.array
|
||||||
]).isRequired,
|
]).isRequired,
|
||||||
availableAcls: React.PropTypes.object.isRequired,
|
|
||||||
buttonsStyle: React.PropTypes.object,
|
buttonsStyle: React.PropTypes.object,
|
||||||
handleSuccess: React.PropTypes.func.isRequired,
|
|
||||||
children: React.PropTypes.oneOfType([
|
children: React.PropTypes.oneOfType([
|
||||||
React.PropTypes.arrayOf(React.PropTypes.element),
|
React.PropTypes.arrayOf(React.PropTypes.element),
|
||||||
React.PropTypes.element
|
React.PropTypes.element
|
||||||
])
|
]),
|
||||||
|
className: React.PropTypes.string
|
||||||
},
|
},
|
||||||
|
|
||||||
getInitialState() {
|
getInitialState() {
|
||||||
return mergeOptions(
|
return {
|
||||||
UserStore.getState(),
|
|
||||||
{
|
|
||||||
buttonListSize: 0
|
buttonListSize: 0
|
||||||
}
|
}
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
UserStore.listen(this.onChange);
|
|
||||||
UserActions.fetchCurrentUser.defer();
|
|
||||||
|
|
||||||
window.addEventListener('resize', this.handleResize);
|
window.addEventListener('resize', this.handleResize);
|
||||||
window.dispatchEvent(new Event('resize'));
|
window.dispatchEvent(new Event('resize'));
|
||||||
},
|
},
|
||||||
@ -54,8 +47,6 @@ let AclButtonList = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
UserStore.unlisten(this.onChange);
|
|
||||||
|
|
||||||
window.removeEventListener('resize', this.handleResize);
|
window.removeEventListener('resize', this.handleResize);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -65,10 +56,6 @@ let AclButtonList = React.createClass({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
onChange(state) {
|
|
||||||
this.setState(state);
|
|
||||||
},
|
|
||||||
|
|
||||||
renderChildren() {
|
renderChildren() {
|
||||||
const { children } = this.props;
|
const { children } = this.props;
|
||||||
const { buttonListSize } = this.state;
|
const { buttonListSize } = this.state;
|
||||||
@ -79,42 +66,29 @@ let AclButtonList = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { className,
|
const {
|
||||||
buttonsStyle,
|
|
||||||
availableAcls,
|
availableAcls,
|
||||||
pieceOrEditions,
|
buttonsStyle,
|
||||||
handleSuccess } = this.props;
|
className,
|
||||||
|
currentUser,
|
||||||
|
handleSuccess,
|
||||||
|
pieceOrEditions } = this.props;
|
||||||
|
|
||||||
const { currentUser } = this.state;
|
const buttonProps = selectFromObject(this.props, [
|
||||||
|
'availableAcls',
|
||||||
|
'currentUser',
|
||||||
|
'handleSuccess',
|
||||||
|
'pieceOrEditions'
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={className}>
|
<div className={className}>
|
||||||
<span ref="buttonList" style={buttonsStyle}>
|
<span ref="buttonList" style={buttonsStyle}>
|
||||||
<EmailButton
|
<EmailButton {...buttonProps} />
|
||||||
availableAcls={availableAcls}
|
<TransferButton {...buttonProps} />
|
||||||
pieceOrEditions={pieceOrEditions}
|
<ConsignButton {...buttonProps} />
|
||||||
currentUser={currentUser}
|
<UnconsignButton {...buttonProps} />
|
||||||
handleSuccess={handleSuccess} />
|
<LoanButton {...buttonProps} />
|
||||||
<TransferButton
|
|
||||||
availableAcls={availableAcls}
|
|
||||||
pieceOrEditions={pieceOrEditions}
|
|
||||||
currentUser={currentUser}
|
|
||||||
handleSuccess={handleSuccess}/>
|
|
||||||
<ConsignButton
|
|
||||||
availableAcls={availableAcls}
|
|
||||||
pieceOrEditions={pieceOrEditions}
|
|
||||||
currentUser={currentUser}
|
|
||||||
handleSuccess={handleSuccess} />
|
|
||||||
<UnconsignButton
|
|
||||||
availableAcls={availableAcls}
|
|
||||||
pieceOrEditions={pieceOrEditions}
|
|
||||||
currentUser={currentUser}
|
|
||||||
handleSuccess={handleSuccess} />
|
|
||||||
<LoanButton
|
|
||||||
availableAcls={availableAcls}
|
|
||||||
pieceOrEditions={pieceOrEditions}
|
|
||||||
currentUser={currentUser}
|
|
||||||
handleSuccess={handleSuccess} />
|
|
||||||
{this.renderChildren()}
|
{this.renderChildren()}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
@ -37,10 +37,9 @@ export default function ({ action, displayName, title, tooltip }) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
sanitizeAction() {
|
sanitizeAction() {
|
||||||
if (this.props.buttonAcceptName) {
|
const { buttonAcceptName } = this.props;
|
||||||
return this.props.buttonAcceptName;
|
|
||||||
}
|
return buttonAcceptName ? buttonAcceptName : AclInformationText.titles[action];
|
||||||
return AclInformationText.titles[action];
|
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -36,9 +36,10 @@ import { getLangText } from '../../utils/lang_utils';
|
|||||||
*/
|
*/
|
||||||
let EditionActionPanel = React.createClass({
|
let EditionActionPanel = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
|
edition: React.PropTypes.object.isRequired,
|
||||||
|
currentUser: React.PropTypes.object.isRequired,
|
||||||
|
|
||||||
actionPanelButtonListType: React.PropTypes.func,
|
actionPanelButtonListType: React.PropTypes.func,
|
||||||
edition: React.PropTypes.object,
|
|
||||||
currentUser: React.PropTypes.object,
|
|
||||||
handleSuccess: React.PropTypes.func
|
handleSuccess: React.PropTypes.func
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ let EditionActionPanel = React.createClass({
|
|||||||
EditionListActions.closeAllEditionLists();
|
EditionListActions.closeAllEditionLists();
|
||||||
EditionListActions.clearAllEditionSelections();
|
EditionListActions.clearAllEditionSelections();
|
||||||
|
|
||||||
let notification = new GlobalNotificationModel(response.notification, 'success');
|
const notification = new GlobalNotificationModel(response.notification, 'success');
|
||||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||||
|
|
||||||
this.history.pushState(null, '/collection');
|
this.history.pushState(null, '/collection');
|
||||||
@ -99,24 +100,22 @@ let EditionActionPanel = React.createClass({
|
|||||||
edition,
|
edition,
|
||||||
currentUser } = this.props;
|
currentUser } = this.props;
|
||||||
|
|
||||||
if (edition &&
|
if (edition.notifications &&
|
||||||
edition.notifications &&
|
|
||||||
edition.notifications.length > 0){
|
edition.notifications.length > 0){
|
||||||
return (
|
return (
|
||||||
<ListRequestActions
|
<ListRequestActions
|
||||||
pieceOrEditions={[edition]}
|
|
||||||
currentUser={currentUser}
|
currentUser={currentUser}
|
||||||
handleSuccess={this.handleSuccess}
|
notifications={edition.notifications}
|
||||||
notifications={edition.notifications}/>);
|
pieceOrEditions={[edition]}
|
||||||
}
|
handleSuccess={this.handleSuccess} />);
|
||||||
|
} else {
|
||||||
else {
|
|
||||||
return (
|
return (
|
||||||
<Row>
|
<Row>
|
||||||
<Col md={12}>
|
<Col md={12}>
|
||||||
<ActionPanelButtonListType
|
<ActionPanelButtonListType
|
||||||
className="ascribe-button-list"
|
|
||||||
availableAcls={edition.acl}
|
availableAcls={edition.acl}
|
||||||
|
className="ascribe-button-list"
|
||||||
|
currentUser={currentUser}
|
||||||
pieceOrEditions={[edition]}
|
pieceOrEditions={[edition]}
|
||||||
handleSuccess={this.handleSuccess}>
|
handleSuccess={this.handleSuccess}>
|
||||||
<AclProxy
|
<AclProxy
|
||||||
|
@ -210,10 +210,10 @@ let PieceContainer = React.createClass({
|
|||||||
if (piece && piece.notifications && piece.notifications.length > 0) {
|
if (piece && piece.notifications && piece.notifications.length > 0) {
|
||||||
return (
|
return (
|
||||||
<ListRequestActions
|
<ListRequestActions
|
||||||
pieceOrEditions={piece}
|
|
||||||
currentUser={currentUser}
|
currentUser={currentUser}
|
||||||
handleSuccess={this.loadPiece}
|
pieceOrEditions={piece}
|
||||||
notifications={piece.notifications}/>);
|
notifications={piece.notifications}
|
||||||
|
handleSuccess={this.loadPiece} />);
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<AclProxy
|
<AclProxy
|
||||||
@ -227,8 +227,9 @@ let PieceContainer = React.createClass({
|
|||||||
label={getLangText('ACTIONS')}
|
label={getLangText('ACTIONS')}
|
||||||
className="hidden-print">
|
className="hidden-print">
|
||||||
<AclButtonList
|
<AclButtonList
|
||||||
className="ascribe-button-list"
|
|
||||||
availableAcls={piece.acl}
|
availableAcls={piece.acl}
|
||||||
|
className="ascribe-button-list"
|
||||||
|
currentUser={currentUser}
|
||||||
pieceOrEditions={piece}
|
pieceOrEditions={piece}
|
||||||
handleSuccess={this.loadPiece}>
|
handleSuccess={this.loadPiece}>
|
||||||
<CreateEditionsButton
|
<CreateEditionsButton
|
||||||
|
@ -263,6 +263,7 @@ let PieceList = React.createClass({
|
|||||||
const {
|
const {
|
||||||
accordionListItemType: AccordionListItemType,
|
accordionListItemType: AccordionListItemType,
|
||||||
bulkModalButtonListType: BulkModalButtonListType,
|
bulkModalButtonListType: BulkModalButtonListType,
|
||||||
|
currentUser,
|
||||||
customSubmitButton,
|
customSubmitButton,
|
||||||
customThumbnailPlaceholder,
|
customThumbnailPlaceholder,
|
||||||
filterParams,
|
filterParams,
|
||||||
@ -299,6 +300,7 @@ let PieceList = React.createClass({
|
|||||||
className="ascribe-piece-list-bulk-modal">
|
className="ascribe-piece-list-bulk-modal">
|
||||||
<BulkModalButtonListType
|
<BulkModalButtonListType
|
||||||
availableAcls={availableAcls}
|
availableAcls={availableAcls}
|
||||||
|
currentUser={currentUser}
|
||||||
pieceOrEditions={selectedEditions}
|
pieceOrEditions={selectedEditions}
|
||||||
handleSuccess={this.handleAclSuccess}
|
handleSuccess={this.handleAclSuccess}
|
||||||
className="text-center ascribe-button-list collapse-group">
|
className="text-center ascribe-button-list collapse-group">
|
||||||
|
@ -21,48 +21,48 @@ let WalletActionPanel = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (this.props.piece &&
|
const { currentUser, handleDeleteSuccess, loadPiece, piece, submitButtonType } = this.props;
|
||||||
this.props.piece.notifications &&
|
|
||||||
this.props.piece.notifications.length > 0) {
|
if (piece && piece.notifications && piece.notifications.length) {
|
||||||
return (
|
return (
|
||||||
<ListRequestActions
|
<ListRequestActions
|
||||||
pieceOrEditions={this.props.piece}
|
pieceOrEditions={piece}
|
||||||
currentUser={this.props.currentUser}
|
currentUser={currentUser}
|
||||||
handleSuccess={this.props.loadPiece}
|
handleSuccess={loadPiece}
|
||||||
notifications={this.props.piece.notifications}/>);
|
notifications={piece.notifications}/>);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
|
|
||||||
//We need to disable the normal acl_loan because we're inserting a custom acl_loan button
|
//We need to disable the normal acl_loan because we're inserting a custom acl_loan button
|
||||||
let availableAcls;
|
let availableAcls;
|
||||||
|
|
||||||
if (this.props.piece && this.props.piece.acl && typeof this.props.piece.acl.acl_loan !== 'undefined') {
|
if (piece && piece.acl && typeof piece.acl.acl_loan !== 'undefined') {
|
||||||
// make a copy to not have side effects
|
// make a copy to not have side effects
|
||||||
availableAcls = mergeOptions({}, this.props.piece.acl);
|
availableAcls = mergeOptions({}, piece.acl);
|
||||||
availableAcls.acl_loan = false;
|
availableAcls.acl_loan = false;
|
||||||
}
|
}
|
||||||
let SubmitButtonType = this.props.submitButtonType;
|
let SubmitButtonType = submitButtonType;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AclButtonList
|
<AclButtonList
|
||||||
className="text-center ascribe-button-list"
|
|
||||||
availableAcls={availableAcls}
|
availableAcls={availableAcls}
|
||||||
pieceOrEditions={this.props.piece}
|
className="text-center ascribe-button-list"
|
||||||
handleSuccess={this.props.loadPiece}>
|
currentUser={currentUser}
|
||||||
|
pieceOrEditions={piece}
|
||||||
|
handleSuccess={loadPiece}>
|
||||||
<AclProxy
|
<AclProxy
|
||||||
aclObject={this.props.currentUser.acl}
|
aclObject={currentUser.acl}
|
||||||
aclName="acl_wallet_submit">
|
aclName="acl_wallet_submit">
|
||||||
<AclProxy
|
<AclProxy
|
||||||
aclObject={availableAcls}
|
aclObject={availableAcls}
|
||||||
aclName="acl_wallet_submit">
|
aclName="acl_wallet_submit">
|
||||||
<SubmitButtonType
|
<SubmitButtonType
|
||||||
className="btn-sm"
|
className="btn-sm"
|
||||||
piece={this.props.piece}/>
|
piece={piece}/>
|
||||||
</AclProxy>
|
</AclProxy>
|
||||||
</AclProxy>
|
</AclProxy>
|
||||||
<DeleteButton
|
<DeleteButton
|
||||||
handleSuccess={this.props.handleDeleteSuccess}
|
handleSuccess={handleDeleteSuccess}
|
||||||
piece={this.props.piece}/>
|
piece={piece}/>
|
||||||
</AclButtonList>
|
</AclButtonList>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ let CylandLanding = React.createClass({
|
|||||||
whitelabel: React.PropTypes.object,
|
whitelabel: React.PropTypes.object,
|
||||||
|
|
||||||
// Provided from router
|
// Provided from router
|
||||||
location: object
|
location: React.PropTypes.object
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -9,63 +9,45 @@ import EmailButton from '../../../../../ascribe_buttons/acls/email_button';
|
|||||||
import TransferButton from '../../../../../ascribe_buttons/acls/transfer_button';
|
import TransferButton from '../../../../../ascribe_buttons/acls/transfer_button';
|
||||||
import UnconsignButton from '../../../../../ascribe_buttons/acls/unconsign_button';
|
import UnconsignButton from '../../../../../ascribe_buttons/acls/unconsign_button';
|
||||||
|
|
||||||
import UserActions from '../../../../../../actions/user_actions';
|
import { selectFromObject } from '../../../../../../utils/general_utils';
|
||||||
import UserStore from '../../../../../../stores/user_store';
|
|
||||||
|
|
||||||
let MarketAclButtonList = React.createClass({
|
let MarketAclButtonList = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
availableAcls: React.PropTypes.object.isRequired,
|
availableAcls: React.PropTypes.object.isRequired,
|
||||||
className: React.PropTypes.string,
|
currentUser: React.PropTypes.object.isRequired,
|
||||||
pieceOrEditions: React.PropTypes.array,
|
handleSuccess: React.PropTypes.func.isRequired,
|
||||||
handleSuccess: React.PropTypes.func,
|
pieceOrEditions: React.PropTypes.array.isRequired,
|
||||||
|
|
||||||
children: React.PropTypes.oneOfType([
|
children: React.PropTypes.oneOfType([
|
||||||
React.PropTypes.arrayOf(React.PropTypes.element),
|
React.PropTypes.arrayOf(React.PropTypes.element),
|
||||||
React.PropTypes.element
|
React.PropTypes.element
|
||||||
])
|
]),
|
||||||
},
|
className: React.PropTypes.string
|
||||||
|
|
||||||
getInitialState() {
|
|
||||||
return UserStore.getState();
|
|
||||||
},
|
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
UserStore.listen(this.onChange);
|
|
||||||
UserActions.fetchCurrentUser();
|
|
||||||
},
|
|
||||||
|
|
||||||
componentWillUnmount() {
|
|
||||||
UserStore.unlisten(this.onChange);
|
|
||||||
},
|
|
||||||
|
|
||||||
onChange(state) {
|
|
||||||
this.setState(state);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let { availableAcls, className, pieceOrEditions, handleSuccess } = this.props;
|
const {
|
||||||
|
availableAcls,
|
||||||
|
children,
|
||||||
|
className,
|
||||||
|
currentUser,
|
||||||
|
handleSuccess,
|
||||||
|
pieceOrEditions } = this.props;
|
||||||
|
|
||||||
|
const buttonProps = selectFromObject(this.props, [
|
||||||
|
'availableAcls',
|
||||||
|
'currentUser',
|
||||||
|
'handleSuccess',
|
||||||
|
'pieceOrEditions'
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={className}>
|
<div className={className}>
|
||||||
<MarketSubmitButton
|
<MarketSubmitButton {...buttonProps} />
|
||||||
availableAcls={availableAcls}
|
<EmailButton {...buttonProps} />
|
||||||
currentUser={this.state.currentUser}
|
<TransferButton {...buttonProps} />
|
||||||
editions={pieceOrEditions}
|
<UnconsignButton {...buttonProps} />
|
||||||
handleSuccess={handleSuccess} />
|
{children}
|
||||||
<EmailButton
|
|
||||||
availableAcls={availableAcls}
|
|
||||||
currentUser={this.state.currentUser}
|
|
||||||
pieceOrEditions={pieceOrEditions}
|
|
||||||
handleSuccess={handleSuccess} />
|
|
||||||
<TransferButton
|
|
||||||
availableAcls={availableAcls}
|
|
||||||
currentUser={this.state.currentUser}
|
|
||||||
pieceOrEditions={pieceOrEditions}
|
|
||||||
handleSuccess={handleSuccess} />
|
|
||||||
<UnconsignButton
|
|
||||||
availableAcls={availableAcls}
|
|
||||||
currentUser={this.state.currentUser}
|
|
||||||
pieceOrEditions={pieceOrEditions}
|
|
||||||
handleSuccess={handleSuccess} />
|
|
||||||
{this.props.children}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user