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

81 lines
2.6 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 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
},
mixins: [Router.Navigation],
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('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) {
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');
}
2015-07-03 19:08:56 +02:00
btnDelete = <Button bsStyle="danger" className="btn-delete" 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;