UNPKG

zotero-web-library

Version:

Web library from zotero.org

121 lines (114 loc) 3.48 kB
'use strict'; var log = require('libzotero/lib/Log').Logger('zotero-web-library:deleteCollectionDialog'); var React = require('react'); var BootstrapModalWrapper = require('./BootstrapModalWrapper.js'); var DeleteCollectionDialog = React.createClass({ displayName: 'DeleteCollectionDialog', componentWillMount: function componentWillMount() { var reactInstance = this; var library = this.props.library; library.listen('deleteCollectionDialog', function () { reactInstance.setState({ collectionKey: Zotero.state.getUrlVar('collectionKey') }); reactInstance.openDialog(); }); }, getInitialState: function getInitialState() { return { collectionKey: null }; }, handleCollectionChange: function handleCollectionChange(evt) { this.setState({ 'parentCollection': evt.target.value }); }, deleteCollection: function deleteCollection() { log.debug('DeleteCollectionDialog.deleteCollection', 3); var reactInstance = this; var library = this.props.library; var collection = library.collections.getCollection(this.state.collectionKey); if (!collection) { Zotero.ui.jsNotificationMessage('Selected collection not found', 'error'); return false; } collection.remove().then(function () { delete Zotero.state.pathVars['collectionKey']; library.collections.dirty = true; library.collections.initSecondaryData(); Zotero.state.pushState(); Zotero.ui.jsNotificationMessage(collection.get('title') + ' removed', 'confirm'); reactInstance.closeDialog(); }).catch(Zotero.catchPromiseError); return false; }, openDialog: function openDialog() { if (!this.state.collectionKey) { log.error('DeleteCollectionDialog opened with no collectionKey'); } this.refs.modal.open(); }, closeDialog: function closeDialog(evt) { this.refs.modal.close(); }, render: function render() { var library = this.props.library; var collection = library.collections.getCollection(this.state.collectionKey); if (!collection) { return null; } return React.createElement( BootstrapModalWrapper, { ref: 'modal' }, React.createElement( 'div', { id: 'delete-collection-dialog', className: 'delete-collection-dialog', role: 'dialog', title: 'Delete Collection', 'data-keyboard': 'true' }, React.createElement( 'div', { className: 'modal-dialog' }, React.createElement( 'div', { className: 'modal-content' }, React.createElement( 'div', { className: 'modal-header' }, React.createElement( 'button', { type: 'button', className: 'close', 'data-dismiss': 'modal', 'aria-hidden': 'true' }, '×' ), React.createElement( 'h3', null, 'Delete Collection' ) ), React.createElement( 'div', { className: 'delete-collection-div modal-body' }, React.createElement( 'p', null, 'Really delete collection "', collection.get('title'), '"?' ) ), React.createElement( 'div', { className: 'modal-footer' }, React.createElement( 'button', { className: 'btn', 'data-dismiss': 'modal', 'aria-hidden': 'true' }, 'Close' ), React.createElement( 'button', { onClick: this.deleteCollection, className: 'btn btn-primary deleteButton' }, 'Delete' ) ) ) ) ) ); } }); module.exports = DeleteCollectionDialog;