1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +01:00
onion/js/components/ascribe_buttons/delete_button.js

78 lines
2.5 KiB
JavaScript
Raw Permalink Normal View History

'use strict';
2015-06-10 15:49:46 +02:00
import React from 'react';
import Button from 'react-bootstrap/lib/Button';
import EditionDeleteForm from '../ascribe_forms/form_delete_edition';
import PieceDeleteForm from '../ascribe_forms/form_delete_piece';
import EditionRemoveFromCollectionForm from '../ascribe_forms/form_remove_editions_from_collection';
import PieceRemoveFromCollectionForm from '../ascribe_forms/form_remove_piece_from_collection';
import ModalWrapper from '../ascribe_modal/modal_wrapper';
2015-06-10 15:49:46 +02:00
import { getAvailableAcls } from '../../utils/acl_utils';
import { getLangText } from '../../utils/lang_utils.js';
2015-06-10 15:49:46 +02:00
let DeleteButton = React.createClass({
propTypes: {
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
},
2015-08-05 18:14:49 +02:00
render() {
let availableAcls;
let btnDelete;
let content;
let title;
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
}
if(availableAcls.acl_delete) {
if(this.props.piece && !this.props.editions) {
content = <PieceDeleteForm pieceId={this.props.piece.id}/>;
title = getLangText('Delete Piece');
} else {
content = <EditionDeleteForm editions={this.props.editions}/>;
title = getLangText('Delete Edition');
}
2015-10-27 17:15:23 +01:00
btnDelete = <button className="btn btn-sm btn-tertiary">{getLangText('DELETE')}</button>;
} else if(availableAcls.acl_unshare){
2015-07-15 17:51:09 +02:00
if(this.props.editions) {
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) {
content = <PieceRemoveFromCollectionForm pieceId={this.props.piece.id}/>;
title = getLangText('Remove Piece from Collection');
}
btnDelete = <Button bsStyle="default" bsSize="small">{getLangText('REMOVE FROM COLLECTION')}</Button>;
2015-08-05 18:14:49 +02:00
} else {
2015-06-16 10:02:55 +02:00
return null;
2015-06-10 15:49:46 +02:00
}
2015-08-05 18:14:49 +02:00
2015-06-10 15:49:46 +02:00
return (
<ModalWrapper
2015-08-05 16:49:25 +02:00
trigger={btnDelete}
handleSuccess={this.props.handleSuccess}
title={title}>
{content}
</ModalWrapper>
2015-06-10 15:49:46 +02:00
);
}
});
export default DeleteButton;