import React from "react" ; import ReactDOMServer from "react-dom/server" ; import Select from "react-select" ; import { gAppRef } from "./index.js" ; import { makeOptionalLink, pluralString } from "./utils.js" ; const axios = require( "axios" ) ; // -------------------------------------------------------------------- export class PublicationSearchResult extends React.Component { render() { return (
{ makeOptionalLink( this._makeDisplayName(), this.props.data.pub_url ) } Edit this publication. Delete this publication.
) ; } static onNewPublication( notify ) { PublicationSearchResult._doEditPublication( {}, (newVals,refs) => { axios.post( gAppRef.makeFlaskUrl( "/publication/create", {list:1} ), newVals ) .then( resp => { // update the cached publications gAppRef.caches.publications = resp.data.publications ; // unload any cleaned values for ( let r in refs ) { if ( resp.data.cleaned && resp.data.cleaned[r] ) newVals[ r ] = resp.data.cleaned[ r ] ; } // update the UI with the new details notify( resp.data.pub_id, newVals ) ; if ( resp.data.warning ) gAppRef.showWarningToast(
The new publication was created OK.

{resp.data.warning}

) ; else gAppRef.showInfoToast(
The new publication was created OK.
) ; gAppRef.closeModalForm() ; } ) .catch( err => { gAppRef.showErrorMsg(
Couldn't create the publication:
{err.toString()}
) ; } ) ; } ) ; } onEditPublication() { PublicationSearchResult._doEditPublication( this.props.data, (newVals,refs) => { // send the updated details to the server newVals.pub_id = this.props.data.pub_id ; axios.post( gAppRef.makeFlaskUrl( "/publication/update", {list:1} ), newVals ) .then( resp => { // update the cached publications gAppRef.caches.publications = resp.data.publications ; // update the UI with the new details for ( let r in refs ) this.props.data[ r ] = (resp.data.cleaned && resp.data.cleaned[r]) || newVals[r] ; this.forceUpdate() ; if ( resp.data.warning ) gAppRef.showWarningToast(
The publication was updated OK.

{resp.data.warning}

) ; else gAppRef.showInfoToast(
The publication was updated OK.
) ; gAppRef.closeModalForm() ; } ) .catch( err => { gAppRef.showErrorMsg(
Couldn't update the publication:
{err.toString()}
) ; } ) ; } ); } static _doEditPublication( vals, notify ) { let refs = {} ; let publishers = [ { value: null, label: (none) } ] ; let currPubl = 0 ; for ( let p of Object.entries(gAppRef.caches.publishers) ) { publishers.push( { value: p[1].publ_id, label: } ) ; if ( p[1].publ_id === vals.publ_id ) currPubl = publishers.length - 1 ; } publishers.sort( (lhs,rhs) => { return ReactDOMServer.renderToStaticMarkup( lhs.label ).localeCompare( ReactDOMServer.renderToStaticMarkup( rhs.label ) ) ; } ) ; const content =
refs.pub_name=r} />
refs.pub_edition=r} />