2015-06-11 15:03:55 +02:00
|
|
|
'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';
|
2015-06-11 15:03:55 +02:00
|
|
|
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';
|
|
|
|
|
2015-06-11 15:03:55 +02:00
|
|
|
import { getAvailableAcls } from '../../utils/acl_utils';
|
2015-07-13 21:19:45 +02:00
|
|
|
import { getLangText } from '../../utils/lang_utils.js';
|
2015-06-11 15:03:55 +02:00
|
|
|
|
|
|
|
import EditionListActions from '../../actions/edition_list_actions';
|
|
|
|
|
2015-06-10 15:49:46 +02:00
|
|
|
let DeleteButton = React.createClass({
|
|
|
|
propTypes: {
|
2015-07-14 00:56:23 +02:00
|
|
|
editions: React.PropTypes.array.isRequired,
|
|
|
|
handleSuccess: React.PropTypes.func
|
2015-06-10 15:49:46 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
mixins: [Router.Navigation],
|
|
|
|
|
2015-06-15 09:29:34 +02:00
|
|
|
showNotification(response) {
|
2015-07-14 00:56:23 +02:00
|
|
|
if (this.props.editions.constructor === Array){
|
|
|
|
this.props.editions
|
|
|
|
.forEach((edition) => {
|
|
|
|
EditionListActions.fetchEditionList(edition.parent);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
EditionListActions.fetchEditionList(this.props.editions.id);
|
|
|
|
}
|
2015-06-11 15:03:55 +02:00
|
|
|
EditionListActions.clearAllEditionSelections();
|
2015-06-15 09:29:34 +02:00
|
|
|
EditionListActions.closeAllEditionLists();
|
2015-07-14 00:56:23 +02:00
|
|
|
this.props.handleSuccess();
|
2015-06-10 15:49:46 +02:00
|
|
|
this.transitionTo('pieces');
|
|
|
|
let notification = new GlobalNotificationModel(response.notification, 'success');
|
|
|
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
|
|
|
},
|
2015-06-11 15:03:55 +02:00
|
|
|
|
2015-06-10 15:49:46 +02:00
|
|
|
render: function () {
|
2015-06-11 15:03:55 +02:00
|
|
|
let availableAcls = getAvailableAcls(this.props.editions);
|
2015-06-10 15:49:46 +02:00
|
|
|
let btnDelete = null;
|
2015-06-11 15:03:55 +02:00
|
|
|
let content = null;
|
|
|
|
|
2015-07-13 21:19:45 +02:00
|
|
|
if (availableAcls.acl_delete) {
|
2015-06-11 15:03:55 +02:00
|
|
|
content = <EditionDeleteForm editions={ this.props.editions }/>;
|
2015-07-03 19:08:56 +02:00
|
|
|
btnDelete = <Button bsStyle="danger" className="btn-delete" bsSize="small">{getLangText('DELETE')}</Button>;
|
2015-06-10 15:49:46 +02:00
|
|
|
}
|
2015-07-13 23:57:16 +02:00
|
|
|
else if (availableAcls.acl_unshare || (this.props.editions.constructor !== Array && this.props.editions.acl.acl_unshare)){
|
2015-06-11 15:03:55 +02:00
|
|
|
content = <EditionRemoveFromCollectionForm editions={ this.props.editions }/>;
|
2015-07-03 19:08:56 +02:00
|
|
|
btnDelete = <Button bsStyle="danger" className="btn-delete" bsSize="small">{getLangText('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 }
|
2015-07-03 19:08:56 +02:00
|
|
|
title={getLangText('Remove Edition')}
|
|
|
|
tooltip={getLangText('Click to remove edition')}>
|
2015-06-10 15:49:46 +02:00
|
|
|
{ content }
|
|
|
|
</ModalWrapper>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default DeleteButton;
|
|
|
|
|