UNPKG

zotero-web-library

Version:

Web library from zotero.org

217 lines (207 loc) 6.07 kB
'use strict'; var log = require('libzotero/lib/Log').Logger('zotero-web-library:citeItemDialog'); var React = require('react'); var BootstrapModalWrapper = require('./BootstrapModalWrapper.js'); var CiteItemDialog = React.createClass({ displayName: 'CiteItemDialog', componentWillMount: function componentWillMount() { var reactInstance = this; var library = this.props.library; reactInstance.getAvailableStyles(); library.listen('citeItems', reactInstance.openDialog, {}); }, getDefaultProps: function getDefaultProps() { return { freeStyleInput: false }; }, getInitialState: function getInitialState() { return { styles: [], currentStyle: '', citationString: '' }; }, handleStyleChange: function handleStyleChange(evt) { this.setState({ 'collectionKey': evt.target.value }); }, openDialog: function openDialog() { //this.setState({open:true}); this.refs.modal.open(); }, closeDialog: function closeDialog(evt) { //this.setState({open:false}); this.refs.modal.close(); }, cite: function cite(evt) { log.debug('citeFunction', 3); var reactInstance = this; var library = this.props.library; var style = this.state.currentStyle; //get the selected item keys from the items widget var itemKeys = Zotero.state.getSelectedItemKeys(); library.loadFullBib(itemKeys, style).then(function (bibContent) { reactInstance.setState({ citationString: bibContent }); //dialogEl.find(".cite-box-div").html(bibContent); }).catch(Zotero.catchPromiseError); }, getAvailableStyles: function getAvailableStyles() { if (!Zotero.styleList) { Zotero.styleList = []; J.getJSON(Zotero.config.styleListUrl, function (data) { Zotero.styleList = data; }); } }, directCite: function directCite(cslItems, style) { var data = {}; data.items = cslItems; var url = Zotero.config.citationEndpoint + '?linkwrap=1&style=' + style; return J.post(url, JSON.stringify(data)); }, buildBibString: function buildBibString(bib) { var bibMeta = bib.bibliography[0]; var bibEntries = bib.bibliography[1]; var bibString = bibMeta.bibstart; for (var i = 0; i < bibEntries.length; i++) { bibString += bibEntries[i]; } bibString += bibMeta.bibend; return bibString; }, render: function render() { var reactInstance = this; var library = this.props.library; var freeStyleInput = null; if (this.props.freeStyleInput) { freeStyleInput = React.createElement('input', { type: 'text', className: 'free-text-style-input form-control', placeholder: 'style' }); } var citationHtml = { '__html': this.state.citationString }; return React.createElement( BootstrapModalWrapper, { ref: 'modal' }, React.createElement( 'div', { id: 'cite-item-dialog', className: 'cite-item-dialog', role: 'dialog', title: 'Cite', '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, 'Cite Items' ) ), React.createElement( 'div', { className: 'cite-item-div modal-body', 'data-role': 'content' }, React.createElement( 'form', null, React.createElement( 'select', { onChange: this.cite, className: 'cite-item-select form-control', id: 'cite-item-select' }, React.createElement( 'option', { value: '' }, 'Select Style' ), React.createElement( 'option', { value: 'apsa' }, 'American Political Science Association' ), React.createElement( 'option', { value: 'apa' }, 'American Psychological Association' ), React.createElement( 'option', { value: 'asa' }, 'American Sociological Association' ), React.createElement( 'option', { value: 'chicago-author-date' }, 'Chicago Manual of Style (Author-Date format)' ), React.createElement( 'option', { value: 'chicago-fullnote-bibliography' }, 'Chicago Manual of Style (Full Note with Bibliography)' ), React.createElement( 'option', { value: 'chicago-note-bibliography' }, 'Chicago Manual of Style (Note with Bibliography)' ), React.createElement( 'option', { value: 'harvard1' }, 'Harvard Reference format 1' ), React.createElement( 'option', { value: 'ieee' }, 'IEEE' ), React.createElement( 'option', { value: 'mhra' }, 'Modern Humanities Research Association' ), React.createElement( 'option', { value: 'mla' }, 'Modern Language Association' ), React.createElement( 'option', { value: 'nlm' }, 'National Library of Medicine' ), React.createElement( 'option', { value: 'nature' }, 'Nature' ), React.createElement( 'option', { value: 'vancouver' }, 'Vancouver' ) ), freeStyleInput ), React.createElement('div', { id: 'cite-box-div', className: 'cite-box-div', dangerouslySetInnerHTML: citationHtml }) ), React.createElement( 'div', { className: 'modal-footer' }, React.createElement( 'button', { className: 'btn btn-default', 'data-dismiss': 'modal', 'aria-hidden': 'true' }, 'Close' ) ) ) ) ) ); } }); module.exports = CiteItemDialog;