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-07-14 16:29:01 +02:00
|
|
|
import PieceDeleteForm from '../ascribe_forms/form_delete_piece';
|
|
|
|
|
2015-06-11 15:03:55 +02:00
|
|
|
import EditionRemoveFromCollectionForm from '../ascribe_forms/form_remove_editions_from_collection';
|
2015-07-14 16:29:01 +02:00
|
|
|
import PieceRemoveFromCollectionForm from '../ascribe_forms/form_remove_piece_from_collection';
|
|
|
|
|
2015-06-10 15:49:46 +02:00
|
|
|
import ModalWrapper from '../ascribe_modal/modal_wrapper';
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2015-06-10 15:49:46 +02:00
|
|
|
let DeleteButton = React.createClass({
|
|
|
|
propTypes: {
|
2015-07-14 16:29:01 +02:00
|
|
|
editions: React.PropTypes.array,
|
|
|
|
piece: React.PropTypes.object,
|
2015-07-14 00:56:23 +02:00
|
|
|
handleSuccess: React.PropTypes.func
|
2015-06-10 15:49:46 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
mixins: [Router.Navigation],
|
|
|
|
|
|
|
|
render: function () {
|
2015-07-14 16:29:01 +02:00
|
|
|
let availableAcls;
|
|
|
|
let btnDelete;
|
|
|
|
let content;
|
|
|
|
let title;
|
2015-06-11 15:03:55 +02:00
|
|
|
|
2015-07-14 16:29:01 +02:00
|
|
|
if(this.props.piece && !this.props.editions) {
|
|
|
|
availableAcls = getAvailableAcls([this.props.piece]);
|
|
|
|
} else {
|
|
|
|
availableAcls = getAvailableAcls(this.props.editions);
|
2015-06-10 15:49:46 +02:00
|
|
|
}
|
2015-07-14 16:29:01 +02:00
|
|
|
|
|
|
|
if(availableAcls.acl_delete) {
|
|
|
|
|
|
|
|
if(this.props.piece && !this.props.editions) {
|
|
|
|
content = <PieceDeleteForm pieceId={this.props.piece.id}/>;
|
|
|
|
title = getLangText('Remove Piece');
|
|
|
|
} else {
|
|
|
|
content = <EditionDeleteForm editions={this.props.editions}/>;
|
|
|
|
title = getLangText('Remove Edition');
|
|
|
|
}
|
|
|
|
|
|
|
|
btnDelete = <Button bsStyle="danger" className="btn-delete" bsSize="small">{getLangText('DELETE')}</Button>;
|
|
|
|
|
|
|
|
} else if(availableAcls.acl_unshare){
|
|
|
|
|
2015-07-15 17:51:09 +02:00
|
|
|
if(this.props.editions) {
|
2015-07-14 16:29:01 +02:00
|
|
|
content = <EditionRemoveFromCollectionForm editions={this.props.editions}/>;
|
|
|
|
title = getLangText('Remove Edition from Collection');
|
2015-07-15 17:51:09 +02:00
|
|
|
} else if(this.props.piece) {
|
2015-07-14 16:29:01 +02:00
|
|
|
content = <PieceRemoveFromCollectionForm pieceId={this.props.piece.id}/>;
|
|
|
|
title = getLangText('Remove Piece from Collection');
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2015-07-14 14:45:33 +02:00
|
|
|
else {
|
2015-06-16 10:02:55 +02:00
|
|
|
return null;
|
2015-06-10 15:49:46 +02:00
|
|
|
}
|
|
|
|
return (
|
|
|
|
<ModalWrapper
|
2015-07-14 14:45:33 +02:00
|
|
|
button={btnDelete}
|
|
|
|
handleSuccess={this.props.handleSuccess}
|
2015-07-14 16:29:01 +02:00
|
|
|
title={title}>
|
|
|
|
{content}
|
2015-06-10 15:49:46 +02:00
|
|
|
</ModalWrapper>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default DeleteButton;
|
|
|
|
|