) ;
} ) ;
} );
}
static _doEditPublication( vals, notify ) {
let refs = {} ;
// initialize the publishers
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 ) ) ;
} ) ;
// initialize the tags
const tags = gAppRef.makeTagLists( vals.pub_tags ) ;
// prepare the form content
const content =
refs.pub_name=r} />
refs.pub_edition=r} />
refs.pub_tags=r }
/>
refs.pub_url=r} />
;
const buttons = {
OK: () => {
// unload the new values
let newVals = {} ;
for ( let r in refs ) {
if ( r === "publ_id" )
newVals[ r ] = refs[r].state.value && refs[r].state.value.value ;
else if ( r === "pub_tags" ) {
let vals = unloadCreatableSelect( refs[r] ) ;
newVals[ r ] = vals.map( v => v.label ) ;
} else
newVals[ r ] = refs[r].value.trim() ;
}
if ( newVals.pub_name === "" ) {
gAppRef.showErrorMsg(
Please specify the publication's name.
) ;
return ;
}
// notify the caller about the new details
notify( newVals, refs ) ;
},
Cancel: () => { gAppRef.closeModalForm() ; },
} ;
const isNew = Object.keys( vals ).length === 0 ;
gAppRef.showModalForm( isNew?"New publication":"Edit publication", content, buttons ) ;
}
onDeletePublication() {
let doDelete = ( nArticles ) => {
// confirm the operation
let warning ;
if ( typeof nArticles === "number" ) {
if ( nArticles === 0 )
warning =
No articles will be deleted.
;
else
warning =
{ pluralString(nArticles,"associated article") + " will also be deleted." }
;
} else {
warning = (
WARNING: Couldn't check if any associated articles will be deleted:
{nArticles.toString()}
) ;
}
const content = (
Delete this publication?
{warning}
) ;
gAppRef.ask( content, "ask", {
"OK": () => {
// delete the publication on the server
axios.get( gAppRef.makeFlaskUrl( "/publication/delete/" + this.props.data.pub_id, {list:1} ) )
.then( resp => {
// update the caches
gAppRef.caches.publications = resp.data.publications ;
gAppRef.caches.tags = resp.data.tags ;
// update the UI
this.props.onDelete( "pub_id", this.props.data.pub_id ) ;
resp.data.deleteArticles.forEach( article_id => {
this.props.onDelete( "article_id", article_id ) ;
} ) ;
if ( resp.data.warnings )
gAppRef.showWarnings( "The publication was deleted.", resp.data.warnings ) ;
else
gAppRef.showInfoToast(