2015-10-30 11:10:31 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
|
|
|
import AclProxy from '../../acl_proxy';
|
|
|
|
|
|
|
|
import AclFormFactory from '../../ascribe_forms/acl_form_factory';
|
|
|
|
|
|
|
|
import ModalWrapper from '../../ascribe_modal/modal_wrapper';
|
|
|
|
|
|
|
|
import AppConstants from '../../../constants/application_constants';
|
|
|
|
|
2015-11-10 11:53:05 +01:00
|
|
|
import { AclInformationText } from '../../../constants/acl_information_text';
|
2015-10-30 11:10:31 +01:00
|
|
|
|
|
|
|
|
2016-02-05 10:38:59 +01:00
|
|
|
export default function AclButton({ action, displayName, title, tooltip }) {
|
2015-11-06 15:10:29 +01:00
|
|
|
if (AppConstants.aclList.indexOf(action) < 0) {
|
|
|
|
console.warn('Your specified aclName did not match a an acl class.');
|
|
|
|
}
|
2015-10-30 11:10:31 +01:00
|
|
|
|
2015-11-06 15:10:29 +01:00
|
|
|
return React.createClass({
|
|
|
|
displayName: displayName,
|
2015-10-30 11:10:31 +01:00
|
|
|
|
2015-11-06 15:10:29 +01:00
|
|
|
propTypes: {
|
|
|
|
availableAcls: React.PropTypes.object.isRequired,
|
|
|
|
pieceOrEditions: React.PropTypes.oneOfType([
|
|
|
|
React.PropTypes.object,
|
|
|
|
React.PropTypes.array
|
|
|
|
]).isRequired,
|
2016-01-18 17:31:56 +01:00
|
|
|
|
2015-11-06 15:10:29 +01:00
|
|
|
buttonAcceptName: React.PropTypes.string,
|
|
|
|
buttonAcceptClassName: React.PropTypes.string,
|
2015-11-10 18:24:46 +01:00
|
|
|
currentUser: React.PropTypes.object,
|
2015-11-06 15:10:29 +01:00
|
|
|
email: React.PropTypes.string,
|
2016-02-05 11:53:33 +01:00
|
|
|
handleSuccess: React.PropTypes.func
|
2015-11-06 15:10:29 +01:00
|
|
|
},
|
2015-10-30 11:10:31 +01:00
|
|
|
|
2015-11-06 15:10:29 +01:00
|
|
|
sanitizeAction() {
|
2016-02-05 11:53:33 +01:00
|
|
|
return this.props.buttonAcceptName || AclInformationText.titles[action];
|
2015-11-06 15:10:29 +01:00
|
|
|
},
|
2015-10-30 11:10:31 +01:00
|
|
|
|
2015-11-06 15:10:29 +01:00
|
|
|
render() {
|
2016-01-18 14:46:39 +01:00
|
|
|
const { availableAcls,
|
|
|
|
buttonAcceptClassName,
|
|
|
|
currentUser,
|
|
|
|
email,
|
|
|
|
pieceOrEditions,
|
|
|
|
handleSuccess } = this.props;
|
2015-11-06 15:10:29 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<AclProxy
|
|
|
|
aclName={action}
|
|
|
|
aclObject={availableAcls}>
|
|
|
|
<ModalWrapper
|
|
|
|
trigger={
|
|
|
|
<button
|
|
|
|
className={classNames('btn', 'btn-default', 'btn-sm', buttonAcceptClassName)}>
|
|
|
|
{this.sanitizeAction()}
|
|
|
|
</button>
|
|
|
|
}
|
|
|
|
handleSuccess={handleSuccess}
|
|
|
|
title={title}>
|
|
|
|
<AclFormFactory
|
|
|
|
action={action}
|
|
|
|
currentUser={currentUser}
|
|
|
|
email={email}
|
|
|
|
pieceOrEditions={pieceOrEditions}
|
|
|
|
showNotification />
|
|
|
|
</ModalWrapper>
|
|
|
|
</AclProxy>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|