import React from "react" ; import Select from "react-select" ; import CreatableSelect from "react-select/creatable" ; import ReactDragListView from "react-drag-listview/lib/index.js" ; import { gAppRef } from "./App.js" ; import { ImageFileUploader } from "./FileUploader.js" ; import { checkConstraints, confirmDiscardChanges, sortSelectableOptions, unloadCreatableSelect, makeTagLists, ciCompare, isNumeric } from "./utils.js" ; // -------------------------------------------------------------------- export class PublicationSearchResult2 { static _doEditPublication( vals, articles, notify ) { // initialize let refs = {} ; let imageFilename=null, imageData=null ; let imageRef=null, uploadImageRef=null, removeImageRef=null ; // prepare to save the initial values let initialVals = null ; function onReady() { if ( ! initialVals ) initialVals = unloadVals() ; } function doRender() { // NOTE: We implement this as a function so that we can re-render the form after articles have been re-ordered. // initialize the image let imageUrl ; if ( initialVals ) imageUrl = imageRef.src ; // nb: leave whatever's there already else imageUrl = gAppRef.makeFlaskImageUrl( "publication", vals.pub_id ) || "/force-404" ; function onImageLoaded() { onReady() ; } function onMissingImage() { imageRef.src = "/images/placeholder.png" ; removeImageRef.style.display = "none" ; onReady() ; } ; function onUploadImage( evt ) { if ( evt === null && !gAppRef.isFakeUploads() ) { // nb: the publication image was clicked - trigger an upload request uploadImageRef.click() ; return ; } let fileUploader = new ImageFileUploader() ; fileUploader.getFile( evt, imageRef, removeImageRef, (fname,data) => { imageFilename = fname ; imageData = data ; } ) ; } ; function onRemoveImage() { imageData = "{remove}" ; imageRef.src = "/images/placeholder.png" ; removeImageRef.style.display = "none" ; } ; // initialize the publishers let publishers = [ { value: null, label: (none), textLabel: "" } ] ; let currPubl = publishers[0] ; for ( let p of Object.entries( gAppRef.dataCache.data.publishers ) ) { publishers.push( { value: p[1].publ_id, label: , textLabel: p[1].publ_name } ) ; if ( p[1].publ_id === vals.publ_id ) currPubl = publishers[ publishers.length-1 ] ; } sortSelectableOptions( publishers ) ; // initialize the publications // NOTE: As a convenience, we provide a droplist of known publication names (without edition #'s), // to make it easier to add a new edition of an existing publication. let publications = {} ; for ( let p of Object.entries( gAppRef.dataCache.data.publications ) ) publications[ p[1].pub_name ] = p[1] ; let publications2 = [] ; for ( let pub_name in publications ) { const pub = publications[ pub_name ] ; publications2.push( { value: pub.pub_id, label: pub.pub_name } ) ; } sortSelectableOptions( publications2 ) ; let currPub = null ; for ( let pub of publications2 ) { if ( pub.label === vals.pub_name ) { currPub = pub ; break ; } } // initialize the tags const tags = makeTagLists( vals.pub_tags ) ; // initialize the articles function make_article_display_name( article ) { let pageno = null ; if ( article.article_pageno ) { pageno = ( { article.article_pageno.substr( 0, 1 ) === "p" || "p" } {article.article_pageno} ) ; } return ( { pageno && ({pageno}) } ) ; } const dragProps = { onDragEnd( fromIndex, toIndex ) { const item = articles.splice( fromIndex, 1 )[0] ; articles.splice( toIndex, 0, item ) ; gAppRef._modalFormRef.current.forceUpdate() ; }, nodeSelector: "li", lineClassName: "dragLine", } ; // prepare the form content /* eslint-disable jsx-a11y/img-redundant-alt */ const content =
onUploadImage(null) } ref = { r => imageRef=r } alt="Upload image." title="Click to upload an image for this publication." /> removeImageRef=r } alt="Remove image." title="Remove the publication's image." /> uploadImageRef=r } />
refs.pub_name=r } /> refs.pub_edition=r} title="Publication edition." />
refs.pub_date=r} />