FOERBICO-metadata-form/metadata-generator.html
smatts 677e45c681 Add institution picker for organization tab
Lets users choose their organization using our list and ror query
when they set the author type to "Organization".
2023-09-28 10:50:37 +02:00

966 lines
41 KiB
HTML

<!DOCTYPE html>
<html lang="de">
<head>
<title>OER Metadaten Formular</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/js/bootstrap-select.min.js"></script> -->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.9/dist/css/bootstrap-select.min.css"/>
<!-- jQuery Select2 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.full.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2-bootstrap-theme/0.1.0-beta.10/select2-bootstrap.min.css"/>
<!-- datepicker -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.10.0/js/bootstrap-datepicker.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.10.0/locales/bootstrap-datepicker.de.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.10.0/locales/bootstrap-datepicker.en-US.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.10.0/css/bootstrap-datepicker.min.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"/>
<!-- Latest compiled and minified JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.9/dist/js/bootstrap-select.min.js"></script>
<!-- (Optional) Latest compiled and minified JavaScript translation files -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.9/dist/js/i18n/defaults-de_DE.min.js"></script>
<script src="https://unpkg.com/i18next/dist/umd/i18next.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-yaml/4.1.0/js-yaml.min.js"></script>
<style>
.btn-primary {
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;
padding: 0 20px;
margin-bottom: 120px;
}
.input-dropdown {
background: #F1F6DF;
color: #0A1F40;
}
</style>
</head>
<body>
<nav class="navbar navbar-light bg-light">
<div class="navbar-brand">
<img src="logo.svg" height="50" width="116" alt="LOGO">
</div>
<form class="form-inline ml-auto mr-3">
<button class="btn" type="button" data-toggle="modal" data-target="#importModal">Import</button>
</form>
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarLanguageDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span id="selectedLanguageLabel">DE</span>
</a>
<div class="dropdown-menu position-absolute dropdown-menu-right" aria-labelledby="navbarLanguageDropdown">
<a class="dropdown-item" onclick="changeLanguage('en')">English</a>
<a class="dropdown-item" onclick="changeLanguage('de')">Deutsch</a>
</div>
</li>
</ul>
</nav>
<!-- Modal -->
<div class="modal fade" id="importModal" tabindex="-1" role="dialog" aria-labelledby="importModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Import</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<textarea rows="15" class="form-control" id="importData" placeholder="Daten" data-i18n-placeholder="LABEL_IMPORT_DATA_PLACEHOLDER"></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal" data-i18n="LABEL_CLOSE">Schließen</button>
<button type="button" class="btn btn-primary" data-i18n="LABEL_IMPORT" onclick="importData()">Import</button>
</div>
</div>
</div>
</div>
<div class="container main">
<h2 style="margin-bottom:40px;" data-i18n="FORM_HEADING">OER Metadaten Formular</h2>
<form class="was-validated">
<div class="form-group row">
<label for="inputTitle" class="col-sm-2 col-form-label" data-i18n="LABEL_TITLE">Titel</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputTitle" placeholder="Titel"
data-i18n-placeholder="LABEL_TITLE" value="" required>
<div class="valid-feedback"></div>
<div class="invalid-feedback" data-i18n="LABEL_MANDATORY_FIELD">Pflichtfeld</div>
</div>
</div>
<div class="form-group row">
<label for="inputDescription" class="col-sm-2 col-form-label"
data-i18n="LABEL_DESCRIPTION">Beschreibung</label>
<div class="col-sm-10">
<textarea class="form-control" id="inputDescription" placeholder="Beschreibung" data-i18n-placeholder="LABEL_DESCRIPTION"></textarea>
</div>
</div>
<div class="form-group row">
<label for="inputTags" class="col-sm-2 col-form-label" data-i18n="LABEL_KEYWORDS">Schlagworte</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputTags" placeholder="Komma getrennte Liste von Schlagworten"
data-i18n-placeholder="LABEL_KEYWORDS_PLACEHOLDER" value="">
</div>
</div>
<div class="form-group row">
<label for="inputEducationalLevel" class="col-sm-2 col-form-label" data-i18n="LABEL_EDUCATIONALLEVEL">Bildungsstufe</label>
<div class="col-sm-10">
<select data-style="input-dropdown" data-width="100%" class="selectpicker" id="inputEducationalLevel" data-i18n-title="LABEL_EDUCATIONALLEVEL_CHOOSE" required multiple>
</select>
<div class="valid-feedback"></div>
<div class="invalid-feedback" data-i18n="LABEL_MANDATORY_FIELD">Pflichtfeld</div>
</div>
</div>
<div class="form-group row">
<label for="inputResourceType" class="col-sm-2 col-form-label" data-i18n="LABEL_LEARNINGRESOURCETYPE">Materialart</label>
<div class="col-sm-10">
<select data-style="input-dropdown" data-width="100%" class="selectpicker" id="inputResourceType" data-i18n-title="LABEL_LEARNINGRESOURCETYPE_CHOOSE" required multiple>
</select>
<div class="valid-feedback"></div>
<div class="invalid-feedback" data-i18n="LABEL_MANDATORY_FIELD">Pflichtfeld</div>
</div>
</div>
<div class="form-group row">
<label for="creator-list" class="col-sm-2 col-form-label" data-i18n="LABEL_CREATOR">Autor</label>
<div class="col-sm-10 form-row">
<ul class="list-group col" id="creator-list">
<li class="list-group-item">
<button type="button" onclick="addCreator()" class="btn btn-primary"><i class="fa fa-plus"></i> <span
data-i18n="LABEL_CREATOR_ADD">Autor hinzufügen</span></button>
</li>
</ul>
</div>
</div>
<div class="form-group row">
<label for="inputLanguage" class="col-sm-2 col-form-label" data-i18n="LABEL_LANGUAGE">Sprache</label>
<div class="col-sm-10">
<select data-style="input-dropdown" data-width="100%" class="selectpicker" id="inputLanguage" data-i18n-title="LABEL_CHOOSE" required multiple>
</select>
<div class="valid-feedback"></div>
<div class="invalid-feedback">Pflichtfeld</div>
</div>
</div>
<div class="form-group row">
<label for="choicesLicense" class="col-sm-2 col-form-label" data-i18n="LABEL_LICENSE">Lizenz</label>
<div class="col-sm-7" id="choicesLicense">
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" onclick="chooseLicense()" class="form-check-input" id="inputLicenseBY" value="BY"
checked>
<span data-i18n="LABEL_LICENSE_CHECKBOX_BY">darf ohne Namensnennung verwendet werden</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" onclick="chooseLicense()" class="form-check-input" id="inputLicenseSA" value="SA"
checked>
<span data-i18n="LABEL_LICENSE_CHECKBOX_SA">darf unter anderer Lizenz veröffentlicht werden</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" onclick="chooseLicense()" class="form-check-input" id="inputLicenseND" value="ND"
checked>
<span data-i18n="LABEL_LICENSE_CHECKBOX_ND">darf verändert werden</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" onclick="chooseLicense()" class="form-check-input" id="inputLicenseNC" value="NC"
checked>
<span data-i18n="LABEL_LICENSE_CHECKBOX_NC">darf kommerziell genutzt werden</span>
<input type="hidden" id="licenseUrl"
value="https://creativecommons.org/share-your-work/public-domain/cc0/">
</label>
</div>
</div>
<div class="col-sm-3">
<label for="choicesLicense" id="choosenLicense" class="col-form-label">CC-0</label>
</div>
</div>
<div class="form-group row">
<label for="inputSubjectOf" class="col-sm-2 col-form-label" data-i18n="LABEL_SUBJECT">Fach</label>
<div class="col-sm-10">
<select data-style="input-dropdown" data-width="100%" class="selectpicker" id="inputSubjectOf" data-live-search="true" data-i18n-title="LABEL_CHOOSE" multiple>
</select>
</div>
</div>
<div class="form-group row">
<label for="inputUrl" class="col-sm-2 col-form-label" data-i18n="LABEL_URL">URL</label>
<div class="col-sm-10">
<input type="url" class="form-control" id="inputUrl" placeholder="URL" data-i18n-placeholder="LABEL_URL_PLACEHOLDER" value="">
<div class="valid-feedback"></div>
</div>
</div>
<div class="form-group row">
<label for="inputImage" class="col-sm-2 col-form-label" data-i18n="LABEL_IMAGE_URL">Vorschaubild URL</label>
<div class="col-sm-10">
<input type="url" class="form-control" id="inputImage" placeholder="Vorschaubild URL" data-i18n-placeholder="LABEL_IMAGE_URL" value="">
</div>
</div>
<div class="form-group row">
<label for="inputStatus" class="col-sm-2 col-form-label" data-i18n="LABEL_STATUS">Status</label>
<div class="col-sm-10">
<select class="custom-select" id="inputStatus" onchange="createOrUpdateDatePicker()" required>
<option value="Draft" data-i18n="LABEL_STATUS_DRAFT" selected>Entwurf</option>
<option value="Incomplete" data-i18n="LABEL_STATUS_INCOMPLETE">Unvollständig</option>
<option value="Published" data-i18n="LABEL_STATUS_PUBLISHED">Veröffentlicht</option>
</select>
<div class="valid-feedback"></div>
<div class="invalid-feedback" data-i18n="LABEL_MANDATORY_FIELD">Pflichtfeld</div>
</div>
</div>
<div class="form-group row" id="datePublishedFormGroup">
<label for="datePublished" class="col-sm-2 col-form-label" data-i18n="LABEL_DATE_PUBLISHED">Veröffentlichungsdatum</label>
<div class="col-sm-10 input-group date" id="datepicker1" data-target-input="nearest">
<input type="text" id="datepickerInput" class="form-control datepicker-input" data-target="#datepicker1"/>
<div class="input-group-append" data-target="#datepicker1" data-toggle="datepicker">
<div class="input-group-text"><i class="fa fa-calendar"></i></div>
</div>
</div>
</div>
<button type="button" onclick="generate()" class="btn btn-primary"><i class="fa fa-arrow-down"></i> <span data-i18n="LABEL_GENERATE">Generieren</span>
</button>
<button type="button" disabled onclick="copy_generated_output()" class="btn btn-primary" id="button_copy_generated_output"><i class="fa fa-copy"></i> <span data-i18n="LABEL_COPY">Kopieren</span>
</button>
<div class="form-group">
<label for="comment" data-i18n="LABEL_YAML_METADATA">YAML Metadaten</label>
<textarea class="form-control" rows="15" id="comment"></textarea>
</div>
</form>
</div>
<div id="copied_to_clipboard_toast" class="toast hide" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-body"><span data-i18n="LABEL_COPIED_TO_CLIPBOARD">In die Zwischenablage kopiert</span></div>
<button type="button" class="btn-close me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<footer class="bg-light text-center">
<div class="text-center p-3">
GitLab:
<a class="text-dark" href="https://gitlab.com/oersi/metadata-form">https://gitlab.com/oersi/metadata-form</a>
</div>
</footer>
</div>
<script>
init();
async function init() {
await loadVocabs();
await i18nLoader();
chooseLicense();
addCreator();
$("#inputEducationalLevel option[value='https://w3id.org/kim/educationalLevel/level_A']").attr("selected", "true");
$('.selectpicker').selectpicker('refresh');
var userLang = navigator.language || navigator.userLanguage;
if (userLang) {
changeLanguage(userLang);
}
}
let vocabInstitutions = []
function loadVocabs() {
$(document).ready(function () {
$.getJSON("vocabs/educationalLevel.json", function (result) {
$.each(result, function (i, item) {
$("#inputEducationalLevel").append('<option value="' + item + '" data-i18n="' + item + '"></option>');
});
});
$.getJSON("vocabs/hcrt.json", function (result) {
$.each(result, function (i, item) {
$("#inputResourceType").append('<option value="' + item + '" data-i18n="' + item + '"></option>');
});
});
$.getJSON("vocabs/language.json", function (result) {
$.each(result, function (i, item) {
$("#inputLanguage").append('<option value="' + item + '" data-i18n="' + item + '"></option>');
});
});
$.getJSON("vocabs/organizations.json", function (result) {
vocabInstitutions = result;
});
$.getJSON("vocabs/subject.json", function (result) {
$.each(result, function (i, item) {
$("#inputSubjectOf").append('<option value="' + item + '" data-i18n="' + item + '"></option>');
});
});
});
}
var licenses = [
{
shortName: "CC-0",
color: "green",
name: "Public Domain",
url: "https://creativecommons.org/publicdomain/zero/1.0/deed.de",
icon: ""
},
{
shortName: "CC BY",
color: "green",
name: "Namensnennung 4.0 International",
url: "https://creativecommons.org/licenses/by/4.0/deed.de",
icon: ""
},
{
shortName: "CC BY-SA",
color: "yellow",
name: "Namensnennung - Weitergabe unter gleichen Bedingungen 4.0 International",
url: "https://creativecommons.org/licenses/by-sa/4.0/deed.de",
icon: ""
},
{
shortName: "CC BY-ND",
color: "orange",
name: "Namensnennung - Keine Bearbeitungen 4.0 International",
url: "https://creativecommons.org/licenses/by-nd/4.0/deed.de",
icon: ""
},
{
shortName: "CC BY-NC",
color: "red",
name: "Namensnennung-Nicht kommerziell 4.0 International",
url: "https://creativecommons.org/licenses/by-nc/4.0/deed.de",
icon: ""
},
{
shortName: "CC BY-SA-NC",
color: "red",
name: "Namensnennung - Nicht-kommerziell - Weitergabe unter gleichen Bedingungen 4.0 International",
url: "https://creativecommons.org/licenses/by-nc-sa/4.0/deed.de",
icon: ""
},
{
shortName: "CC BY-ND-NC",
color: "red",
name: "Namensnennung - Nicht kommerziell - Keine Bearbeitungen 4.0 International",
url: "https://creativecommons.org/licenses/by-nc-nd/4.0/deed.de",
icon: ""
}
];
function chooseLicense() {
const by = document.getElementById("inputLicenseBY")
const sa = document.getElementById("inputLicenseSA")
const nd = document.getElementById("inputLicenseND")
const nc = document.getElementById("inputLicenseNC")
let licenseShortName = "CC"
if (by.checked === false) {
licenseShortName += " " + by.value
}
if (sa.checked === false) {
licenseShortName += "-" + sa.value
}
if (nd.checked === false) {
licenseShortName += "-" + nd.value
}
if (nc.checked === false) {
licenseShortName += "-" + nc.value
}
if (licenseShortName === "CC") {
licenseShortName = "CC-0"
}
document.getElementById("choosenLicense").innerText = licenseShortName
let color = ""
switch (licenseShortName) {
case "CC-0":
color = "green"
by.disabled = false;
sa.disabled = true;
nd.disabled = true;
nc.disabled = true;
break;
case "CC BY":
color = "green"
by.disabled = false;
sa.disabled = false;
nd.disabled = false;
nc.disabled = false;
break;
case "CC BY-SA":
color = "orange"
by.disabled = true;
sa.disabled = false;
nd.disabled = true;
nc.disabled = false;
break;
case "CC BY-ND":
color = "orange"
by.disabled = true;
sa.disabled = true;
nd.disabled = false;
nc.disabled = false;
break;
case "CC BY-NC":
color = "red"
by.disabled = true;
sa.disabled = false;
nd.disabled = false;
nc.disabled = false;
break;
case "CC BY-SA-NC":
color = "red"
by.disabled = true;
sa.disabled = false;
nd.disabled = true;
nc.disabled = false;
break;
case "CC BY-ND-NC":
color = "red"
by.disabled = true;
sa.disabled = true;
nd.disabled = false;
nc.disabled = false;
break;
default:
color = "grey"
document.getElementById("choosenLicense").innerText = i18next.t("LABEL_INVALID_LICENSE")
document.getElementById("licenseUrl").value = ""
by.disabled = false;
sa.disabled = false;
nd.disabled = false;
nc.disabled = false;
}
document.getElementById("choosenLicense").style.color = color
for (x in licenses) {
if (licenses[x].shortName === licenseShortName) {
document.getElementById("licenseUrl").value = licenses[x].url
}
}
}
function splitKeywords(keywordString) {
const keywords = keywordString.split(",");
return keywords.map((k) => k.trim());
}
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 changeAffiliationType(creatorListItem, type) {
const affiliationElements = creatorListItem.getElementsByClassName("inputAffiliation")
for (const element of affiliationElements) {
if (element.classList.contains("customAffiliation")) {
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");
item.setAttribute("class", "list-group-item");
let institutionOptions = "";
let organizationOptions = "";
$.each(vocabInstitutions, function (i, item) {
institutionOptions += '<option value="' + item["ror"] + '"' + (item["ror"] === institution ? ' selected' : '') + '>' + item["label"] + '</option>';
organizationOptions += '<option value="' + item["ror"] + '"' + (item["ror"] === institution ? ' selected' : '') + '>' + item["label"] + '</option>';
});
let customInstitutionSelected = institution === "" && affiliationName !== "";
let radioGroupName = creatorList.childElementCount > 1 ? $(creatorList.lastElementChild.previousElementSibling).find('.inputType').find('input').attr('name') : ''
radioGroupName += 'x'
item.innerHTML = `
<div class="form-row">
<div class="btn-group btn-group-toggle inputType" role="group" data-toggle="buttons">
<label class="btn btn-outline-primary ${type === "Person" ? "active" : ""}" onclick="changeCreatorType(this.parentNode.parentNode.parentNode, 'Person')">
<input type="radio" name="${radioGroupName}" ${type === "Person" ? "checked" : ""} value="Person"><span data-i18n="LABEL_PERSON">Person</span>
</label>
<label class="btn btn-outline-primary ${type === "Organization" ? "active" : ""}" onclick="changeCreatorType(this.parentNode.parentNode.parentNode, 'Organization')">
<input type="radio" name="${radioGroupName}" ${type === "Organization" ? "checked" : ""} value="Organization"><span data-i18n="LABEL_ORGANIZATION">Organisation</span>
</label>
</div>
</div>
<div class="form-row mt-3 person-element" ${type !== "Person" ? 'style="display:none;"':''}>
<div class="col">
<input type="text" class="form-control inputGivenName" placeholder="Vorname" data-i18n-placeholder="LABEL_CREATOR_GIVEN_NAME" value="${firstName}" required>
<div class="valid-feedback"></div>
<div class="invalid-feedback" data-i18n="LABEL_MANDATORY_FIELD">Pflichtfeld</div>
</div>
<div class="col">
<input type="text" class="form-control inputFamilyName" placeholder="Nachname" data-i18n-placeholder="LABEL_CREATOR_LAST_NAME" value="${lastName}" required>
<div class="valid-feedback"></div>
<div class="invalid-feedback" data-i18n="LABEL_MANDATORY_FIELD">Pflichtfeld</div>
</div>
</div>
<div class="form-row mt-2 person-element" ${type !== "Person" ? 'style="display:none;"':''}>
<div class="col">
<input type="text" class="form-control inputAuthorId" placeholder="Persönliche ID (optional, wie ORCID, GND)" data-i18n-placeholder="LABEL_CREATOR_ID" value="${authorId}">
</div>
</div>
<div class="form-row mt-2 person-element" ${type !== "Person" ? 'style="display:none;"':''}>
<div class="col-1 m-auto" style="flex-basis: content">
<input class="affiliationType" type="radio" name="institution_${radioGroupName}" aria-label="radio button for institution list" ${customInstitutionSelected ? "":"checked"} value="standard" onclick="changeAffiliationType(this.parentNode.parentNode.parentNode, 'standard')">
</div>
<div class="col-11 mb-1" id="select-div">
<select ${customInstitutionSelected ? "disabled":""} data-style="input-dropdown" data-width="100%" class="form-select inputAffiliation select-institution" id="institution-select">
<option value="" data-i18n="LABEL_ORGANIZATION_CHOOSE" ${institution === "" ? "selected":""}></option>
${institutionOptions}
</select>
</div>
</div>
<div class="form-row person-element" ${type !== "Person" ? 'style="display:none;"':''}>
<div class="col-1 m-auto" style="flex-basis: content">
<input class="affiliationType" type="radio" name="institution_${radioGroupName}" aria-label="radio button for custom institution" ${customInstitutionSelected ? "checked":""} value="custom" onclick="changeAffiliationType(this.parentNode.parentNode.parentNode, 'custom')">
</div>
<div class="col-11">
<input type="text" ${customInstitutionSelected ? "":"disabled"} class="form-control customAffiliation inputAffiliation" placeholder="Institution" data-i18n-placeholder="LABEL_CUSTOM_INSTITUTION" value="${customInstitutionSelected ? affiliationName:""}">
</div>
</div>
<div class="form-row mt-3 organization-element" ${type !== "Organization" ? 'style="display:none;"':''}>
<div class="col mb-1" id="select-div">
<select data-style="input-dropdown" data-width="100%" class="form-select inputOrganizationName select-organization" id="organization-select">
<option value="" data-i18n="LABEL_ORGANIZATION_CHOOSE" ${institution === "" ? "selected":""}></option>
${organizationOptions}
</select>
</div>
</div>
<div class="form-row mt-2">
<div class="col">
<button type="button" onclick="removeCreator(this.parentNode.parentNode.parentNode)" class="btn btn-primary"><i class="fa fa-minus"></i> <span data-i18n="LABEL_CREATOR_REMOVE"> Autor entfernen</span></button>
</div>
</div>
`;
creatorList.insertBefore(item, creatorList.lastElementChild);
createOrUpdateSelectInputAffiliation();
createOrUpdateSelectOrganization();
createOrUpdateDatePicker();
updateContent();
}
function removeCreator(creatorListItem) {
creatorListItem.parentNode.removeChild(creatorListItem);
}
function getCreators() {
const creatorsElement = document.getElementById("creator-list").querySelectorAll(".list-group-item");
const creators = [];
for (let i = 0; i < creatorsElement.length - 1; i++) {
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");
creators.push({
name: organizationInput.options[organizationInput.selectedIndex].innerHTML,
id: organizationInput.value,
type: "Organization"
});
} else {
const creatorId = creatorsElement[i].getElementsByClassName("inputAuthorId")[0].value;
const affiliationTypeElement = creatorsElement[i].querySelector("input.affiliationType:checked");
let affiliation
if ("custom" === affiliationTypeElement.value) {
const affiliationInput = creatorsElement[i].getElementsByClassName("customAffiliation")[0].value.trim();
affiliation = affiliationInput ? {
name: affiliationInput,
type: "Organization"
} : undefined
} else {
const affiliationInput = creatorsElement[i].querySelector("select.inputAffiliation");
affiliation = affiliationInput.value ? {
name: affiliationInput.options[affiliationInput.selectedIndex].innerHTML,
id: affiliationInput.value,
type: "Organization"
} : undefined
}
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: affiliation
});
}
}
return creators;
}
function copy_generated_output() {
if (!navigator.clipboard) {
return;
}
navigator.clipboard.writeText(document.getElementById("comment").value).then(function() {
$("#copied_to_clipboard_toast").toast("show");
}, function(err) {
console.error('Async: Could not copy text: ', err);
});
}
function generate() {
const creators = getCreators()
const selectedLanguages = $('#inputLanguage').val();
const selectedSubjects = $('#inputSubjectOf').val();
const selectedResourceTypes = $('#inputResourceType').val();
const selectedEducationalLevel = $('#inputEducationalLevel').val();
const identifier = document.getElementById("inputUrl").value;
const datePublished = $("#datepicker1").datepicker("getDate");
let meta = {
creativeWorkStatus: document.getElementById("inputStatus").value,
name: document.getElementById("inputTitle").value,
description: document.getElementById("inputDescription").value,
license: {id: document.getElementById("licenseUrl").value}
}
if (identifier) {
meta.id = identifier;
}
if (creators.length > 0) {
meta.creator = creators
}
if (document.getElementById("inputTags").value) {
meta.keywords = splitKeywords(document.getElementById("inputTags").value)
}
if (selectedLanguages.length > 0) {
meta.inLanguage = selectedLanguages;
}
if (selectedSubjects.length > 0) {
meta.about = selectedSubjects
}
if (document.getElementById("inputImage").value) {
meta.image = document.getElementById("inputImage").value
}
if (selectedResourceTypes.length > 0) {
meta.learningResourceType = selectedResourceTypes
}
if (selectedEducationalLevel.length > 0) {
meta.educationalLevel = selectedEducationalLevel
}
if (meta.creativeWorkStatus == "Published" && datePublished) {
let dateString = datePublished.getFullYear() + "-"
+ ('0' + (datePublished.getMonth()+1)).slice(-2) + "-"
+ ('0' + datePublished.getDate()).slice(-2);
meta.datePublished = dateString;
}
document.getElementById("comment").value = jsyaml.dump(meta);
if (navigator.clipboard) {
document.getElementById("button_copy_generated_output").disabled = false
}
}
function setCreators(creators) {
const creatorsElement = document.getElementById("creator-list").querySelectorAll(".list-group-item");
for (let i = 0; i < creatorsElement.length - 1; i++) {
removeCreator(creatorsElement[i]);
}
for (let i = 0; i < creators.length; i++) {
if (creators[i].type === "Organization") {
const ror = creators[i].id ? creators[i].id : "";
addCreator("", "", "", ror, 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 : "";
const affiliationName = creators[i].affiliation?.name ? creators[i].affiliation.name : "";
addCreator(firstName, lastName, authorId, ror, "", "Person", affiliationName);
}
}
}
function importData() {
try {
const idMap = (o) => (typeof o === 'string' || o instanceof String) ? o : o.id;
const data = jsyaml.load(document.getElementById("importData").value);
const aboutIds = data.about ? data.about.map(idMap) : [];
const learningResourceTypeIds = data.learningResourceType ? data.learningResourceType.map(idMap) : [];
const educationalLevelIds = data.educationalLevel ? data.educationalLevel.map(idMap) : [];
document.getElementById("inputStatus").value = data.creativeWorkStatus ? data.creativeWorkStatus : "Draft";
$("#datepicker1").datepicker("update", new Date(data.datePublished));
document.getElementById("inputUrl").value = data.id ? data.id : "";
document.getElementById("inputTitle").value = data.name;
setCreators(data.creator ? data.creator : []);
document.getElementById("inputTags").value = data.keywords ? data.keywords.join(", ") : "";
document.getElementById("inputDescription").value = data.description ? data.description : "";
$('#inputLanguage').val(data.inLanguage ? data.inLanguage : []).selectpicker('refresh');
$('#inputSubjectOf').val(aboutIds).selectpicker('refresh');
setLicense((data.license && data.license.id) ? idMap(data.license) : "")
document.getElementById("inputImage").value = data.image ? data.image : "";
$('#inputResourceType').val(learningResourceTypeIds).selectpicker('refresh');
if (educationalLevelIds.length > 0) {
$('#inputEducationalLevel').val(educationalLevelIds).selectpicker('refresh');
}
} catch (e) {
console.warn(e);
alert(i18next.t("LABEL_IMPORT_ERROR_MSG"));
} finally {
$('#importModal').modal('hide')
}
}
function setLicense(license) {
const by = document.getElementById("inputLicenseBY")
const sa = document.getElementById("inputLicenseSA")
const nd = document.getElementById("inputLicenseND")
const nc = document.getElementById("inputLicenseNC")
if (license.startsWith("https://creativecommons.org/publicdomain/zero/")) {
by.checked = true;
sa.checked = true;
nd.checked = true;
nc.checked = true;
} else if (license.startsWith("https://creativecommons.org/licenses/by/")) {
by.checked = false;
sa.checked = true;
nd.checked = true;
nc.checked = true;
} else if (license.startsWith("https://creativecommons.org/licenses/by-sa/")) {
by.checked = false;
sa.checked = false;
nd.checked = true;
nc.checked = true;
} else if (license.startsWith("https://creativecommons.org/licenses/by-nd/")) {
by.checked = false;
sa.checked = true;
nd.checked = false;
nc.checked = true;
} else if (license.startsWith("https://creativecommons.org/licenses/by-nc/")) {
by.checked = false;
sa.checked = true;
nd.checked = true;
nc.checked = false;
} else if (license.startsWith("https://creativecommons.org/licenses/by-nc-sa/")) {
by.checked = false;
sa.checked = false;
nd.checked = true;
nc.checked = false;
} else if (license.startsWith("https://creativecommons.org/licenses/by-nc-nd/")) {
by.checked = false;
sa.checked = true;
nd.checked = false;
nc.checked = false;
} else {
by.checked = false;
sa.checked = false;
nd.checked = false;
nc.checked = false;
}
chooseLicense();
}
async function i18nLoader() {
const langs = ["en", "de"];
const jsons = await Promise.all(
langs.map((l) => fetch("i18n/" + l + ".json").then((r) => r.json()))
);
const educationalLevelLabels = await Promise.all(
langs.map((l) => fetch("i18n/educationalLevel-" + l + ".json").then((r) => r.json()))
);
const hcrt = await Promise.all(
langs.map((l) => fetch("i18n/hcrt-" + l + ".json").then((r) => r.json()))
);
const languageLabels = await Promise.all(
langs.map((l) => fetch("i18n/language-" + l + ".json").then((r) => r.json()))
);
const subjectLabels = await Promise.all(
langs.map((l) => fetch("i18n/subject-" + l + ".json").then((r) => r.json()))
);
const res = langs.reduce((acc, l, idx) => {
acc[l] = {translation: {...jsons[idx], ...educationalLevelLabels[idx], ...hcrt[idx], ...languageLabels[idx], ...subjectLabels[idx]}};
return acc;
}, {});
await i18next.init({
lng: "de",
debug: false,
nsSeparator: "#",
resources: res,
fallbackLng: 'en'
});
updateContent();
i18next.on("languageChanged", () => {
updateContent();
});
}
function changeLanguage(languageCode) {
i18next.changeLanguage(languageCode);
document.getElementById("selectedLanguageLabel").textContent = languageCode.toUpperCase();
createOrUpdateSelectInputAffiliation();
createOrUpdateSelectOrganization();
createOrUpdateDatePicker();
}
function createOrUpdateSelectOrganization() {
$('.select-organization').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 createOrUpdateSelectInputAffiliation() {
$('.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 createOrUpdateDatePicker() {
// Keep previously set date when changing the language
let date = $('#datepicker1').datepicker("getDate");
if (document.getElementById("inputStatus").value != "Published") {
document.getElementById("datepickerInput").required = false;
} else {
// Make required if input status is set to published
document.getElementById("datepickerInput").required = true;
// When set to published, set datePublished to today
if (!date) {
$('#datepicker1').datepicker("update", new Date());
}
}
$('#datepicker1').datepicker("destroy");
let language = document.getElementById("selectedLanguageLabel").textContent.toLowerCase();
if (language == "en") language += "-US";
$('#datepicker1').datepicker({
language: language
});
if (date) {
$('#datepicker1').datepicker("update", new Date(date));
}
}
function updateContent() {
let elements = document.querySelectorAll('[data-i18n]');
for (let i = 0; i < elements.length; i++) {
const element = elements[i];
const k = element.getAttribute("data-i18n");
element.innerHTML = i18next.t(k);
}
elements = document.querySelectorAll('[data-i18n-placeholder]');
for (let i = 0; i < elements.length; i++) {
const element = elements[i];
const k = element.getAttribute("data-i18n-placeholder");
element.setAttribute("placeholder", i18next.t(k));
}
$("[data-i18n-title]").each( function () {
const k = $(this).attr("data-i18n-title")
$(this).selectpicker({title: i18next.t(k)}).selectpicker('render');
})
$('.selectpicker').selectpicker('refresh');
}
</script>
</body>
</html>