From 1ad3e74ce09130cd00fe275c82f69a5f3824e78c Mon Sep 17 00:00:00 2001 From: alw-bsz Date: Thu, 15 May 2025 17:24:03 +0200 Subject: [PATCH 1/2] #1283, #1351: getDoi.js for v4.9 (includes fix for to many authors) --- public/layouts/opus4/js/getDoi.js | 84 ++++++++++++++++++------------- 1 file changed, 48 insertions(+), 36 deletions(-) diff --git a/public/layouts/opus4/js/getDoi.js b/public/layouts/opus4/js/getDoi.js index 5f0ac8948..532392d50 100644 --- a/public/layouts/opus4/js/getDoi.js +++ b/public/layouts/opus4/js/getDoi.js @@ -239,48 +239,60 @@ function expandPages(page) function expandAuthor(author) { - if (author[0] !== undefined) { - var _laenge = author.length; - var completeName = author[0] + ''; + // Abbruch, wenn kein Autor vorhanden + if (! author[0]) { + document.getElementById("Enrichmentopus_doi_flag").value = "true"; + return; + } - var vorname = completeName.split(',')[1].trim(); // [1] = Vorname - document.getElementById("PersonAuthorFirstName_1").value = vorname; - finalize("PersonAuthorFirstName_1"); + const maxAuthors = 50; + const authorLength = author.length; - var nachname = completeName.split(',')[0].trim(); // [0] = Nachname - document.getElementById("PersonAuthorLastName_1").value = nachname; - finalize("PersonAuthorLastName_1"); + // Setzen von Autor-Informationen + const setAuthorInfo = (index, feld) => { + const completeName = author[index] + ''; + const [nachname, vorname, orcid] = completeName.split(',').map(s => s.trim()); - if (completeName.split(',')[2].trim() !== '') { - var orcid = completeName.split(',')[2].trim(); // [2] = ORCID - document.getElementById("PersonAuthorIdentifierOrcid_1").value = orcid; - finalize("PersonAuthorIdentifierOrcid_1"); + document.getElementById(`PersonAuthorFirstName_${feld}`).value = vorname; + finalize(`PersonAuthorFirstName_${feld}`); + + document.getElementById(`PersonAuthorLastName_${feld}`).value = nachname; + finalize(`PersonAuthorLastName_${feld}`); + + if (orcid) { + document.getElementById(`PersonAuthorIdentifierOrcid_${feld}`).value = orcid; + finalize(`PersonAuthorIdentifierOrcid_${feld}`); } + }; - if (document.getElementById('PersonAuthorLastName_' + _laenge) === null) { - var button = document.getElementById("addMorePersonAuthor"); - button.click(); - } else { - var _z; - for (_z = 1; _z < _laenge; _z++) { - var feld = _z + 1; - var completeName = author[_z] + ''; - var vorname = completeName.split(',')[1].trim(); // [1] = Vorname - document.getElementById("PersonAuthorFirstName_" + feld).value = vorname; - finalize("PersonAuthorFirstName_" + feld); - var nachname = completeName.split(',')[0].trim(); // [0] = Nachname - document.getElementById("PersonAuthorLastName_" + feld).value = nachname; - finalize("PersonAuthorLastName_" + feld); - if (completeName.split(',')[2].trim() !== '') { - var orcid = completeName.split(',')[2].trim(); // [2] = ORCID - document.getElementById("PersonAuthorIdentifierOrcid_" + feld).value = orcid; - finalize("PersonAuthorIdentifierOrcid_" + feld); - } - } - document.getElementById("Enrichmentopus_doi_flag").value = "true"; // Hier wird das Ende der Reloads erreicht! (alle Felder sind vorhanden) + // Überprüfen und ggf. weitere Autor-Felder hinzufügen + let maxFields = Math.min(maxAuthors, authorLength); + const ensureAuthorFields = () => { + if (document.getElementById(`PersonAuthorLastName_${maxFields}`) === null) { + document.getElementById("addMorePersonAuthor").click(); + return false; } - } else { - colorPink("PersonAuthorLastName_1"); + return true; + }; + + // Überprüfen und Hinweis für zu viele Autoren + if (document.getElementById('PersonAuthorLastName_' + maxAuthors) !== null ) { + openDialog(translations.doiimport_header_note, translations.doiimport_hint_manyAuthors.replace('%s', authorLength), "OK"); + } + + // Ersten Autor setzen + setAuthorInfo(0, 1); + + // Weitere Autoren setzen + if (ensureAuthorFields()) { + const limitedLength = Math.min(authorLength, maxAuthors); + + for (let i = 1; i < limitedLength; i++) { + setAuthorInfo(i, i + 1); + } + + // Flag setzen, dass alle Felder vorhanden sind + document.getElementById("Enrichmentopus_doi_flag").value = "true"; } } From 691048c2ed010e2ffedd94ce415478b49f63cb37 Mon Sep 17 00:00:00 2001 From: alw-bsz Date: Thu, 15 May 2025 17:25:13 +0200 Subject: [PATCH 2/2] #1283: adding fix for to many authors for v4.9 --- .../configs/doctypes_templates/doi.phtml | 3 +- modules/publish/language/doiimport.tmx | 9 ++++++ public/layouts/opus4/js/doiAssist.js | 29 +++++++++++++++---- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/application/configs/doctypes_templates/doi.phtml b/application/configs/doctypes_templates/doi.phtml index 23b06575e..9c90926d1 100644 --- a/application/configs/doctypes_templates/doi.phtml +++ b/application/configs/doctypes_templates/doi.phtml @@ -135,7 +135,8 @@ $config = Config::get(); doiimport_button_cancel: "translate('doiimport_button_cancel'); ?>", doiimport_button_showId: "translate('doiimport_button_showId'); ?>", doiimport_button_back: "translate('doiimport_button_back'); ?>", - doiimport_button_tryAgain: "translate('doiimport_button_tryAgain'); ?>" + doiimport_button_tryAgain: "translate('doiimport_button_tryAgain'); ?>", + doiimport_hint_manyAuthors: "translate('doiimport_hint_manyAuthors'); ?>" }; let opusConfig = { diff --git a/modules/publish/language/doiimport.tmx b/modules/publish/language/doiimport.tmx index f10df9875..d18467f9f 100644 --- a/modules/publish/language/doiimport.tmx +++ b/modules/publish/language/doiimport.tmx @@ -124,5 +124,14 @@ + + + The DOI dataset has too many authors (%s). The first 49 authors and the last author are imported. + + + Der DOI-Datensatz hat zu viele AutorInnen (%s). Importiert werden die ersten 49 AutorInnen sowie der/die letzte AutorIn. + + + diff --git a/public/layouts/opus4/js/doiAssist.js b/public/layouts/opus4/js/doiAssist.js index de0e5a688..39801ee24 100644 --- a/public/layouts/opus4/js/doiAssist.js +++ b/public/layouts/opus4/js/doiAssist.js @@ -8,7 +8,7 @@ function finalize(field) { // Grüne Farbe und Feldname wird in populatedFields geschrieben, um die Feldfarben nach einem Reload neu aufzubauen colorGreen(field); - populatedFields.push(field); + populatedFields.push(" " + field); } function colorGreen(field) @@ -325,7 +325,9 @@ function getAuthor(json) var authors = []; var _laenge = json.message.author.length; + if (_laenge > 0) { + // Zuerst alle Autoren in das 'authors'-Array einfügen for (_z = 0; _z < _laenge; _z++) { if (json.message.author[_z].given != null || json.message.author[_z].family != null) { vorname = json.message.author[_z].given; @@ -337,22 +339,39 @@ function getAuthor(json) if (re != null) { orcid = re[0]; } else { - orcid = '' + orcid = ''; } } else { orcid = json.message.author[_z].ORCID; } } else { - orcid = '' + orcid = ''; } complete_name = nachname + ',' + vorname + ',' + orcid; authors.push(complete_name); } } + + // Prüfen, ob es mehr als 50 Autoren gibt + if (_laenge > 50) { + // Den letzten Autor extrahieren + let lastAuthor; + //lastAuthor = authors[_laenge - 1]; + if (authors[_laenge - 1]) { + lastAuthor = authors[_laenge - 1]; + } else { + lastAuthor = authors[_laenge - 2]; + } + // Entferne den letzten Autor vom Array (da wir ihn an Position 50 wieder einfügen) + authors.pop(); + // Füge den letzten Autor an der 50. Position ein + authors.splice(49, 0, lastAuthor); + //alert("lastAuthor: "+lastAuthor); + } } - return authors + return authors; // Gibt das Autoren-Array direkt zurück } else { - return '' + return ''; } } exports.getAuthor = getAuthor;