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

68 lines
2.3 KiB
JavaScript
Raw Normal View History

'use strict';
2015-06-10 15:49:46 +02:00
import React from 'react';
import Router from 'react-router';
import Button from 'react-bootstrap/lib/Button';
import EditionDeleteForm from '../ascribe_forms/form_delete_edition';
import EditionRemoveFromCollectionForm from '../ascribe_forms/form_remove_editions_from_collection';
2015-06-10 15:49:46 +02:00
import ModalWrapper from '../ascribe_modal/modal_wrapper';
import GlobalNotificationModel from '../../models/global_notification_model';
import GlobalNotificationActions from '../../actions/global_notification_actions';
import { getAvailableAcls } from '../../utils/acl_utils';
import EditionListActions from '../../actions/edition_list_actions';
2015-06-10 15:49:46 +02:00
let DeleteButton = React.createClass({
propTypes: {
editions: React.PropTypes.array.isRequired
2015-06-10 15:49:46 +02:00
},
mixins: [Router.Navigation],
showNotification(response) {
this.props.editions
.forEach((edition) => {
EditionListActions.fetchEditionList(edition.parent);
});
EditionListActions.clearAllEditionSelections();
EditionListActions.closeAllEditionLists();
2015-06-10 15:49:46 +02:00
this.transitionTo('pieces');
let notification = new GlobalNotificationModel(response.notification, 'success');
GlobalNotificationActions.appendGlobalNotification(notification);
},
2015-06-10 15:49:46 +02:00
render: function () {
let availableAcls = getAvailableAcls(this.props.editions);
2015-06-10 15:49:46 +02:00
let btnDelete = null;
let content = null;
if (availableAcls.indexOf('delete') > -1) {
content = <EditionDeleteForm editions={ this.props.editions }/>;
btnDelete = <Button bsStyle="danger" bsSize="small">DELETE</Button>;
2015-06-10 15:49:46 +02:00
}
else if (availableAcls.indexOf('del_from_collection') > -1){
content = <EditionRemoveFromCollectionForm editions={ this.props.editions }/>;
2015-06-12 13:36:55 +02:00
btnDelete = <Button bsStyle="danger" bsSize="small">REMOVE FROM COLLECTION</Button>;
2015-06-10 15:49:46 +02:00
}
else{
2015-06-16 10:02:55 +02:00
return null;
2015-06-10 15:49:46 +02:00
}
return (
<ModalWrapper
button={ btnDelete }
handleSuccess={ this.showNotification }
title='Remove Edition'
tooltip='Click to remove edition'>
{ content }
</ModalWrapper>
);
}
});
export default DeleteButton;