diff --git a/i18n/de.json b/i18n/de.json index db40b2e..ad3e815 100644 --- a/i18n/de.json +++ b/i18n/de.json @@ -43,5 +43,6 @@ "LABEL_TITLE": "Titel", "LABEL_URL": "URL der Ressource", "LABEL_URL_PLACEHOLDER": "Direktlink zur Resource (Voreinstellung GitHub/GitLab Pages URL)", - "LABEL_YAML_METADATA": "YAML Metadaten" + "LABEL_YAML_METADATA": "YAML Metadaten", + "LABEL_NO_INSTITUTION_FOUND": "Keine passende Institution gefunden" } \ No newline at end of file diff --git a/i18n/en.json b/i18n/en.json index c6d2c0b..ac65b58 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -43,5 +43,6 @@ "LABEL_TITLE": "Title", "LABEL_URL": "Resource URL", "LABEL_URL_PLACEHOLDER": "Direct link to the resource (default GitHub/GitLab Pages URL)", - "LABEL_YAML_METADATA": "YAML Metadata" + "LABEL_YAML_METADATA": "YAML Metadata", + "LABEL_NO_INSTITUTION_FOUND": "No matching institution found" } \ No newline at end of file diff --git a/metadata-generator.html b/metadata-generator.html index b8ddd5e..32cd660 100644 --- a/metadata-generator.html +++ b/metadata-generator.html @@ -12,6 +12,11 @@ + + + + + @@ -511,17 +516,20 @@ +
-
- + ${institutionOptions}
+
@@ -545,6 +553,7 @@ `; creatorList.insertBefore(item, creatorList.lastElementChild); + createOrUpdateSelect2(); updateContent(); } @@ -779,6 +788,53 @@ function changeLanguage(languageCode) { i18next.changeLanguage(languageCode); document.getElementById("selectedLanguageLabel").textContent = languageCode.toUpperCase(); + createOrUpdateSelect2(); + } + + function createOrUpdateSelect2() { + $('.select-institution').select2({ + language: { + noResults: () => i18next.t("LABEL_NO_INSTITUTION_FOUND") + }, + placeholder: i18next.t("LABEL_ORGANIZATION_CHOOSE"), + theme: "bootstrap", + ajax: { + url: 'https://api.ror.org/organizations?query=', + data: function (params) { + return { + query: params.term, + filter: "types:Education" + } + }, + processResults: function (data, params) { + let results = []; + + if (params.term) { + let localInstitutions = vocabInstitutions.map(institution => ({"name": institution["label"], "id": institution["ror"]})); + let rorInstitutions = data["items"].map(institution => ({"name": institution.name, "id": institution.id})); + + let matchedLocalInstitutions = localInstitutions.filter(function(item) { + return item.name.toLowerCase().includes(params.term.toLowerCase()); + }); + + let filteredRorInstitutions = rorInstitutions.filter(function(item) { + return !matchedLocalInstitutions.find(value => value.id == item.id); + }); + + results = [...matchedLocalInstitutions, ...filteredRorInstitutions]; + } + + return { + results: $.map(results, function(item) { + return { + text: item.name, + id: item.id + } + }) + } + } + } + }); } function updateContent() {