From bb9f644c4c00964a02502c84713d571126532983 Mon Sep 17 00:00:00 2001 From: Mirjan Hoffmann Date: Thu, 10 Mar 2022 10:17:54 +0100 Subject: [PATCH] added possibility to choose between person/organization creator --- i18n/de.json | 3 ++ i18n/en.json | 3 ++ metadata-generator.html | 93 ++++++++++++++++++++++++++++++++--------- 3 files changed, 79 insertions(+), 20 deletions(-) diff --git a/i18n/de.json b/i18n/de.json index 6c35c8a..029b52e 100644 --- a/i18n/de.json +++ b/i18n/de.json @@ -26,7 +26,10 @@ "LABEL_LICENSE_CHECKBOX_ND": "darf verändert werden", "LABEL_LICENSE_CHECKBOX_NC": "darf kommerziell genutzt werden", "LABEL_MANDATORY_FIELD": "Pflichtfeld", + "LABEL_ORGANIZATION": "Organisation", "LABEL_ORGANIZATION_CHOOSE": "Wähle Institution ...", + "LABEL_ORGANIZATION_NAME": "Name", + "LABEL_PERSON": "Person", "LABEL_STATUS": "Status", "LABEL_STATUS_DRAFT": "Entwurf", "LABEL_STATUS_INCOMPLETE": "Unvollständig", diff --git a/i18n/en.json b/i18n/en.json index edfb314..98d0712 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -26,7 +26,10 @@ "LABEL_LICENSE_CHECKBOX_ND": "may be changed", "LABEL_LICENSE_CHECKBOX_NC": "may be used commercially", "LABEL_MANDATORY_FIELD": "Mandatory field", + "LABEL_ORGANIZATION": "Organization", "LABEL_ORGANIZATION_CHOOSE": "Choose Institution ...", + "LABEL_ORGANIZATION_NAME": "Name", + "LABEL_PERSON": "Person", "LABEL_STATUS": "Status", "LABEL_STATUS_DRAFT": "Draft", "LABEL_STATUS_INCOMPLETE": "Incomplete", diff --git a/metadata-generator.html b/metadata-generator.html index eaffc98..e3eb6db 100644 --- a/metadata-generator.html +++ b/metadata-generator.html @@ -26,6 +26,18 @@ background-color: #0A1F40; border: 0; } + .btn-outline-primary { + color: #0A1F40; + border-color: #0A1F40; + } + .btn-outline-primary:not(:disabled):not(.disabled).active, .btn-outline-primary:not(:disabled):not(.disabled):active, .show > .btn-outline-primary.dropdown-toggle { + background-color: #0A1F40; + border-color: #0A1F40; + } + .btn-outline-primary:hover { + background-color: #0A1F40; + border-color: #0A1F40; + } .main { margin-top: 40px; @@ -410,7 +422,18 @@ return keywords.map((k) => k.trim()); } - function addCreator(firstName = "", lastName = "", authorId = "", institution = "") { + function changeCreatorType(creatorListItem, type) { + const personElements = creatorListItem.getElementsByClassName("person-element") + for (let i = 0; i < personElements.length; i++) { + personElements[i].style.display = type === "Person" ? "flex" : "none" + } + const organizationElements = creatorListItem.getElementsByClassName("organization-element") + for (let i = 0; i < organizationElements.length; i++) { + organizationElements[i].style.display = type === "Organization" ? "flex" : "none" + } + } + + function addCreator(firstName = "", lastName = "", authorId = "", institution = "", organizationName = "", type = "Person") { const creatorList = document.getElementById("creator-list"); const item = document.createElement("li"); item.setAttribute("class", "list-group-item"); @@ -421,6 +444,16 @@ item.innerHTML = `
+
+ + +
+
+
@@ -432,12 +465,12 @@
Pflichtfeld
-
+
-
+
+
+
+ +
+
Pflichtfeld
+
+
@@ -464,19 +504,28 @@ const creatorsElement = document.getElementById("creator-list").querySelectorAll(".list-group-item"); const creators = []; for (let i = 0; i < creatorsElement.length - 1; i++) { - const creatorId = creatorsElement[i].getElementsByClassName("inputAuthorId")[0].value; - const affiliationInput = creatorsElement[i].querySelector("select.inputAffiliation"); - creators.push({ - name: (creatorsElement[i].getElementsByClassName("inputGivenName")[0].value - + " " - + creatorsElement[i].getElementsByClassName("inputFamilyName")[0].value).trim(), - id: creatorId ? creatorId : undefined, - affiliation: affiliationInput.value ? { - name: affiliationInput.options[affiliationInput.selectedIndex].innerHTML, - id: affiliationInput.value, + const typeElement = creatorsElement[i].getElementsByClassName("inputType")[0]; + const type = $(typeElement).find('input:radio:checked').val() + if (type === "Organization") { + creators.push({ + name: creatorsElement[i].getElementsByClassName("inputOrganizationName")[0].value.trim(), type: "Organization" - } : undefined - }); + }); + } else { + const creatorId = creatorsElement[i].getElementsByClassName("inputAuthorId")[0].value; + const affiliationInput = creatorsElement[i].querySelector("select.inputAffiliation"); + creators.push({ + givenName: creatorsElement[i].getElementsByClassName("inputGivenName")[0].value.trim(), + familyName: creatorsElement[i].getElementsByClassName("inputFamilyName")[0].value.trim(), + id: creatorId ? creatorId : undefined, + type: "Person", + affiliation: affiliationInput.value ? { + name: affiliationInput.options[affiliationInput.selectedIndex].innerHTML, + id: affiliationInput.value, + type: "Organization" + } : undefined + }); + } } return creators; } @@ -520,11 +569,15 @@ removeCreator(creatorsElement[i]); } for (let i = 0; i < creators.length; i++) { - const firstName = creators[i].name.split(" ")[0]; - const lastName = creators[i].name.substring(creators[i].name.indexOf(" ") + 1); - const authorId = creators[i].id ? creators[i].id : ""; - const ror = creators[i].affiliation?.id ? creators[i].affiliation.id : ""; - addCreator(firstName, lastName, authorId, ror); + if (creators[i].type === "Organization") { + addCreator("", "", "", "", creators[i].name, "Organization"); + } else { + const firstName = creators[i].givenName ? creators[i].givenName : creators[i].name.split(" ")[0]; + const lastName = creators[i].familyName ? creators[i].familyName: creators[i].name.substring(creators[i].name.indexOf(" ") + 1); + const authorId = creators[i].id ? creators[i].id : ""; + const ror = creators[i].affiliation?.id ? creators[i].affiliation.id : ""; + addCreator(firstName, lastName, authorId, ror); + } } } function importData() {