From 4b9eccec8c07494d78497f1a356be8c3b16e29e1 Mon Sep 17 00:00:00 2001 From: smatts Date: Thu, 28 Sep 2023 13:59:11 +0200 Subject: [PATCH] Add choice between list and custom organization Just like in the "Person" tab, it is possible to either enter a custom organization, or choose one from our list / ror api. --- metadata-generator.html | 58 +++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/metadata-generator.html b/metadata-generator.html index 79fbd9a..e978f72 100644 --- a/metadata-generator.html +++ b/metadata-generator.html @@ -491,6 +491,18 @@ $('.selectpicker').selectpicker('refresh'); } + function changeOrganizationType(creatorListItem, type) { + const organizationElements = creatorListItem.getElementsByClassName("inputOrganization") + for (const element of organizationElements) { + if (element.classList.contains("customOrganization")) { + element.disabled = type !== "custom"; + } else { + element.disabled = type === "custom"; + } + } + $('.selectpicker').selectpicker('refresh'); + } + function addCreator(firstName = "", lastName = "", authorId = "", institution = "", organizationName = "", type = "Person", affiliationName = "") { const creatorList = document.getElementById("creator-list"); const item = document.createElement("li"); @@ -502,6 +514,7 @@ organizationOptions += ''; }); let customInstitutionSelected = institution === "" && affiliationName !== ""; + let customOrganizationSelected = institution === "" && organizationName !== ""; let radioGroupName = creatorList.childElementCount > 1 ? $(creatorList.lastElementChild.previousElementSibling).find('.inputType').find('input').attr('name') : '' radioGroupName += 'x' @@ -555,14 +568,28 @@ -
-
- +
+
+
+
+
+ +
+
+ +
+
+ +
@@ -588,12 +615,25 @@ const typeElement = creatorsElement[i].getElementsByClassName("inputType")[0]; const type = $(typeElement).find('input:radio:checked').val() if (type === "Organization") { - const organizationInput = creatorsElement[i].querySelector("select.inputOrganizationName"); + const organizationTypeElement = creatorsElement[i].querySelector("input.organizationType:checked"); + let organizationInput, organization; + if ("custom" === organizationTypeElement.value) { + organizationInput = creatorsElement[i].getElementsByClassName("customOrganization")[0].value.trim(); + organization = organizationInput ? { + name: organizationInput + } : undefined; + } else { + organizationInput = creatorsElement[i].querySelector("select.inputOrganization"); + organization = organizationInput ? { + name: organizationInput.options[organizationInput.selectedIndex].innerHTML, + id: organizationInput.value + } : undefined; + } creators.push({ - name: organizationInput.options[organizationInput.selectedIndex].innerHTML, - id: organizationInput.value, + name: organization.name, + id: organization.id ? organization.id : undefined, type: "Organization" - }); + }) } else { const creatorId = creatorsElement[i].getElementsByClassName("inputAuthorId")[0].value; const affiliationTypeElement = creatorsElement[i].querySelector("input.affiliationType:checked"); @@ -692,8 +732,10 @@ } for (let i = 0; i < creators.length; i++) { if (creators[i].type === "Organization") { + const name = creators[i].name ? creators[i].name : ""; const ror = creators[i].id ? creators[i].id : ""; - addCreator("", "", "", ror, creators[i].name, "Organization"); + console.log(creators[i], name, ror); + addCreator("", "", "", ror, 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);