import React from "react" ; import ReactDOMServer from "react-dom/server" ; import Select from "react-select" ; import CreatableSelect from "react-select/creatable" ; import { gAppRef } from "./index.js" ; import { ImageFileUploader } from "./FileUploader.js" ; import { makeScenarioDisplayName, parseScenarioDisplayName, unloadCreatableSelect } from "./utils.js" ; // -------------------------------------------------------------------- export class ArticleSearchResult2 { static _doEditArticle( vals, notify ) { let refs = {} ; // initialize the image let imageFilename=null, imageData=null ; let imageRef=null, uploadImageRef=null, removeImageRef=null ; let imageUrl = gAppRef.makeFlaskUrl( "/images/article/" + vals.article_id ) ; imageUrl += "?foo=" + Math.random() ; // FUDGE! To bypass the cache :-/ let onMissingImage = (evt) => { imageRef.src = "/images/placeholder.png" ; removeImageRef.style.display = "none" ; } ; let onUploadImage = (evt) => { if ( evt === null && !gAppRef.isFakeUploads() ) { // nb: the article 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 ; } ) ; } ; let onRemoveImage = () => { imageData = "{remove}" ; imageRef.src = "/images/placeholder.png" ; removeImageRef.style.display = "none" ; } ; // initialize the publications let publications = [ { value: null, label: (none) } ] ; let currPub = 0 ; for ( let p of Object.entries(gAppRef.caches.publications) ) { publications.push( { value: p[1].pub_id, label: } ) ; if ( p[1].pub_id === vals.pub_id ) currPub = publications.length - 1 ; } publications.sort( (lhs,rhs) => { return ReactDOMServer.renderToStaticMarkup( lhs.label ).localeCompare( ReactDOMServer.renderToStaticMarkup( rhs.label ) ) ; } ) ; // initialize the authors let allAuthors = [] ; for ( let a of Object.entries(gAppRef.caches.authors) ) allAuthors.push( { value: a[1].author_id, label: a[1].author_name } ); allAuthors.sort( (lhs,rhs) => { return lhs.label.localeCompare( rhs.label ) ; } ) ; let currAuthors = [] ; if ( vals.article_authors ) { currAuthors = vals.article_authors.map( a => { return { value: a, label: gAppRef.caches.authors[a].author_name } } ) ; } // initialize the scenarios let allScenarios = [] ; for ( let s of Object.entries(gAppRef.caches.scenarios) ) allScenarios.push( { value: s[1].scenario_id, label: makeScenarioDisplayName(s[1]) } ) ; allScenarios.sort( (lhs,rhs) => { return lhs.label.localeCompare( rhs.label ) ; } ) ; let currScenarios = [] ; if ( vals.article_scenarios ) { currScenarios = vals.article_scenarios.map( s => { return { value: s, label: makeScenarioDisplayName(gAppRef.caches.scenarios[s]) } } ) ; } // initialize the tags const tags = gAppRef.makeTagLists( vals.article_tags ) ; // prepare the form content /* eslint-disable jsx-a11y/img-redundant-alt */ const content =
onUploadImage(null)} ref={r => imageRef=r} alt="Click to upload an image for this article." /> removeImageRef=r} alt="Remove the article's image." /> uploadImageRef=r} />
refs.article_title=r} />
refs.article_subtitle=r} />
refs.article_authors=r } />