1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 09:35:10 +01:00
onion/js/components/ascribe_buttons/acl_button.js

90 lines
3.6 KiB
JavaScript
Raw Normal View History

'use strict';
2015-05-27 14:35:33 +02:00
import React from 'react';
2015-06-03 10:27:11 +02:00
import ConsignForm from '../ascribe_forms/form_consign';
import UnConsignForm from '../ascribe_forms/form_unconsign';
2015-06-03 10:27:11 +02:00
import TransferForm from '../ascribe_forms/form_transfer';
import LoanForm from '../ascribe_forms/form_loan';
import ShareForm from '../ascribe_forms/form_share_email';
import ModalWrapper from '../ascribe_modal/modal_wrapper';
import AppConstants from '../../constants/application_constants';
2015-05-27 14:35:33 +02:00
import GlobalNotificationModel from '../../models/global_notification_model';
import GlobalNotificationActions from '../../actions/global_notification_actions';
2015-05-27 14:35:33 +02:00
let AclButton = React.createClass({
propTypes: {
action: React.PropTypes.oneOf(AppConstants.aclList).isRequired,
2015-05-27 15:49:12 +02:00
availableAcls: React.PropTypes.array.isRequired,
2015-06-01 18:59:47 +02:00
editions: React.PropTypes.array.isRequired,
2015-06-02 11:38:18 +02:00
currentUser: React.PropTypes.object,
handleSuccess: React.PropTypes.func.isRequired
2015-05-27 14:35:33 +02:00
},
2015-06-01 18:59:47 +02:00
actionProperties(){
if (this.props.action === 'consign'){
2015-06-01 18:59:47 +02:00
return {
title: 'Consign artwork',
tooltip: 'Have someone else sell the artwork',
2015-06-10 15:49:46 +02:00
form: <ConsignForm currentUser={ this.props.currentUser } editions={ this.props.editions }/>,
handleSuccess: this.showNotification
};
2015-06-01 18:59:47 +02:00
}
if (this.props.action === 'unconsign'){
return {
title: 'Unconsign artwork',
tooltip: 'Have the owner manage his sales again',
form: <UnConsignForm currentUser={ this.props.currentUser } editions={ this.props.editions }/>,
handleSuccess: this.showNotification
};
}else if (this.props.action === 'transfer') {
2015-06-01 18:59:47 +02:00
return {
title: 'Transfer artwork',
tooltip: 'Transfer the ownership of the artwork',
2015-06-10 15:49:46 +02:00
form: <TransferForm currentUser={ this.props.currentUser } editions={ this.props.editions }/>,
handleSuccess: this.showNotification
};
2015-06-01 18:59:47 +02:00
}
else if (this.props.action === 'loan'){
2015-06-01 18:59:47 +02:00
return {
title: 'Loan artwork',
tooltip: 'Loan your artwork for a limited period of time',
2015-06-10 15:49:46 +02:00
form: <LoanForm currentUser={ this.props.currentUser } editions={ this.props.editions }/>,
handleSuccess: this.showNotification
};
2015-06-01 18:59:47 +02:00
}
else if (this.props.action === 'share'){
2015-06-01 18:59:47 +02:00
return {
title: 'Share artwork',
tooltip: 'Share the artwork',
2015-06-10 15:49:46 +02:00
form: <ShareForm currentUser={ this.props.currentUser } editions={ this.props.editions }/>,
handleSuccess: this.showNotification
};
2015-06-01 18:59:47 +02:00
}
},
showNotification(response){
this.props.handleSuccess();
let notification = new GlobalNotificationModel(response.notification, 'success');
GlobalNotificationActions.appendGlobalNotification(notification);
},
2015-05-27 14:35:33 +02:00
render() {
let shouldDisplay = this.props.availableAcls.indexOf(this.props.action) > -1;
2015-06-01 18:59:47 +02:00
let aclProps = this.actionProperties();
2015-05-27 14:35:33 +02:00
return (
2015-06-01 18:59:47 +02:00
<ModalWrapper
button={
<div className={shouldDisplay ? 'btn btn-default btn-sm' : 'hidden'}>
{this.props.action.toUpperCase()}
</div>
}
handleSuccess={ aclProps.handleSuccess }
2015-06-01 18:59:47 +02:00
title={ aclProps.title }
tooltip={ aclProps.tooltip }>
{ aclProps.form }
</ModalWrapper>
2015-05-27 14:35:33 +02:00
);
}
});
export default AclButton;