1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 17:33:14 +01:00

Use AclButton in LumenusSubmitButton

Instead of copying functionality from AclButton to add a default email,
LumenusSubmitButton just returns one with preset settings.
This commit is contained in:
Brett Sun 2015-10-27 17:01:50 +01:00
parent ac1b43d24b
commit 633939b7fa
3 changed files with 52 additions and 60 deletions

View File

@ -30,6 +30,7 @@ let AclButton = React.createClass({
currentUser: React.PropTypes.object,
buttonAcceptName: React.PropTypes.string,
buttonAcceptClassName: React.PropTypes.string,
email: React.PropTypes.string,
handleSuccess: React.PropTypes.func.isRequired,
className: React.PropTypes.string
},
@ -52,6 +53,7 @@ let AclButton = React.createClass({
tooltip: getLangText('Have someone else sell the artwork'),
form: (
<ConsignForm
email={this.props.email}
message={message}
id={this.getFormDataId()}
url={ApiUrls.ownership_consigns}/>
@ -88,6 +90,7 @@ let AclButton = React.createClass({
tooltip: getLangText('Loan your artwork for a limited period of time'),
form: (
<LoanForm
email={this.props.email}
message={message}
id={this.getFormDataId()}
url={this.isPiece() ? ApiUrls.ownership_loans_pieces

View File

@ -4,10 +4,12 @@ import React from 'react';
import LumenusSubmitButton from './lumenus_submit_button';
import AclProxy from '../../../../../acl_proxy';
import AclButton from '../../../../../ascribe_buttons/acl_button';
import DeleteButton from '../../../../../ascribe_buttons/delete_button';
import UserActions from '../../../../../../actions/user_actions';
import UserStore from '../../../../../../stores/user_store';
let LumenusAclButtonList = React.createClass({
propTypes: {
availableAcls: React.PropTypes.object.isRequired,
@ -20,16 +22,38 @@ let LumenusAclButtonList = React.createClass({
])
},
getInitialState() {
return UserStore.getState();
},
componentDidMount() {
UserStore.listen(this.onChange);
UserActions.fetchCurrentUser();
},
componentWillUnmount() {
UserStore.unlisten(this.onChange);
},
onChange(state) {
this.setState(state);
},
render() {
let { availableAcls, className, editions, handleSuccess } = this.props;
return (
<div className={this.props.className}>
<AclProxy
aclObject={this.props.availableAcls}
aclName={'acl_consign'}>
<LumenusSubmitButton
editions={this.props.editions}
handleSuccess={this.props.handleSuccess} />
</AclProxy>
<div className={className}>
<LumenusSubmitButton
availableAcls={availableAcls}
currentUser={this.state.currentUser}
editions={editions}
handleSuccess={handleSuccess} />
<AclButton
action="acl_share"
availableAcls={availableAcls}
currentUser={this.state.currentUser}
pieceOrEditions={editions}
handleSuccess={handleSuccess} />
{this.props.children}
</div>
);

View File

@ -3,47 +3,32 @@
import React from 'react';
import classNames from 'classnames';
import AclButton from '../../../../../ascribe_buttons/acl_button';
import GlobalNotificationModel from '../../../../../../models/global_notification_model';
import GlobalNotificationActions from '../../../../../../actions/global_notification_actions';
import UserActions from '../../../../../../actions/user_actions';
import UserStore from '../../../../../../stores/user_store';
import WhitelabelActions from '../../../../../../actions/whitelabel_actions';
import WhitelabelStore from '../../../../../../stores/whitelabel_store';
import ConsignForm from '../../../../../ascribe_forms/form_consign';
import ModalWrapper from '../../../../../ascribe_modal/modal_wrapper';
import ApiUrls from '../../../../../../constants/api_urls';
import { getAclFormMessage, getAclFormDataId } from '../../../../../../utils/form_utils';
import { mergeOptions } from '../../../../../../utils/general_utils';
import { getLangText } from '../../../../../../utils/lang_utils';
let LumenusSubmitButton = React.createClass({
propTypes: {
className: React.PropTypes.string,
availableAcls: React.PropTypes.object.isRequired,
currentUser: React.PropTypes.object,
editions: React.PropTypes.array,
handleSuccess: React.PropTypes.func,
className: React.PropTypes.string,
},
getInitialState() {
return mergeOptions(
UserStore.getState(),
WhitelabelStore.getState()
);
return WhitelabelStore.getState();
},
componentDidMount() {
UserStore.listen(this.onChange);
UserActions.fetchCurrentUser();
WhitelabelStore.listen(this.onChange);
WhitelabelActions.fetchWhitelabel();
},
componentWillUnmount() {
UserStore.unlisten(this.onChange);
WhitelabelStore.unlisten(this.onChange);
},
@ -51,39 +36,19 @@ let LumenusSubmitButton = React.createClass({
this.setState(state);
},
showNotification(response) {
this.props.handleSuccess();
if (response.notification) {
let notification = new GlobalNotificationModel(response.notification, 'success');
GlobalNotificationActions.appendGlobalNotification(notification);
}
},
render() {
const { className, editions, handleSuccess } = this.props;
const title = getLangText('Consign to Lumenus');
const message = getAclFormMessage({
aclName: 'acl_consign',
entities: editions,
isPiece: false,
senderName: this.state.currentUser.username
});
const { availableAcls, currentUser, className, editions, handleSuccess } = this.props;
return (
<ModalWrapper
trigger={
<button className={classNames('btn', 'btn-default', 'btn-sm', className)}>
{title}
</button>
}
handleSuccess={this.showNotification}
title={title}>
<ConsignForm
email={this.state.whitelabel.user}
message={message}
id={getAclFormDataId(false, editions)}
url={ApiUrls.ownership_consigns}/>
</ModalWrapper>
<AclButton
action='acl_consign'
availableAcls={availableAcls}
buttonAcceptName={getLangText('CONSIGN TO LUMENUS')}
email={this.state.whitelabel.user}
currentUser={currentUser}
handleSuccess={handleSuccess}
pieceOrEditions={editions}
className={className} />
);
}
});