Merge branch '9-allow-software-licenses-in-form' into 'master'

Allow software licenses

See merge request oersi/metadata-form!16
This commit is contained in:
Mirjan Hoffmann 2024-04-05 06:23:30 +00:00
commit 3035268deb
3 changed files with 182 additions and 82 deletions

View file

@ -45,5 +45,7 @@
"LABEL_URL_PLACEHOLDER": "Direktlink zur Resource (Voreinstellung GitHub/GitLab Pages URL)", "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", "LABEL_NO_INSTITUTION_FOUND": "Keine passende Institution gefunden",
"LABEL_DATE_PUBLISHED": "Veröffentlichungsdatum" "LABEL_DATE_PUBLISHED": "Veröffentlichungsdatum",
"LABEL_SOFTWARE_LICENSE": "Software-Lizenz",
"LABEL_CC_LICENSE": "CC-Lizenz"
} }

View file

@ -45,5 +45,7 @@
"LABEL_URL_PLACEHOLDER": "Direct link to the resource (default GitHub/GitLab Pages 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", "LABEL_NO_INSTITUTION_FOUND": "No matching institution found",
"LABEL_DATE_PUBLISHED": "Date published" "LABEL_DATE_PUBLISHED": "Date published",
"LABEL_SOFTWARE_LICENSE": "Software license",
"LABEL_CC_LICENSE": "CC license"
} }

View file

@ -170,41 +170,56 @@
</div> </div>
<div class="form-group row"> <div class="form-group row">
<label for="choicesLicense" class="col-sm-2 col-form-label" data-i18n="LABEL_LICENSE">Lizenz</label> <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="col-sm-2">
<div class="form-check"> <input type="radio" value="ccLicense" name="license" id="radioLicenseCC" onchange="ccOrSoftwareLicense()" checked>
<label class="form-check-label"> <label data-i18n="LABEL_CC_LICENSE">CC-Lizenz</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>
<div class="form-check"> <div class="col-sm-6" id="choicesLicense">
<label class="form-check-label"> <div class="form-check">
<input type="checkbox" onclick="chooseLicense()" class="form-check-input" id="inputLicenseSA" value="SA" <label class="form-check-label">
checked> <input type="checkbox" onclick="chooseCCLicense()" class="form-check-input" id="inputLicenseBY" value="BY"
<span data-i18n="LABEL_LICENSE_CHECKBOX_SA">darf unter anderer Lizenz veröffentlicht werden</span> checked>
</label> <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="chooseCCLicense()" 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="chooseCCLicense()" 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="chooseCCLicense()" 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>
<div class="form-check"> <div class="col-sm-2">
<label class="form-check-label"> <label for="choicesLicense" id="choosenLicense" class="col-form-label">CC-0</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>
<div class="form-check"> <label for="choicesLicense" class="col-sm-2 col-form-label"></label>
<label class="form-check-label"> <div class="col-sm-2" id="softwareLicense">
<input type="checkbox" onclick="chooseLicense()" class="form-check-input" id="inputLicenseNC" value="NC" <input type="radio" value="softwareLicenseInput" name="license" id="radioLicenseSoftware" onchange="ccOrSoftwareLicense()">
checked> <label data-i18n="LABEL_SOFTWARE_LICENSE">Software-Lizenz</label>
<span data-i18n="LABEL_LICENSE_CHECKBOX_NC">darf kommerziell genutzt werden</span> </div>
<input type="hidden" id="licenseUrl" <div class="col-sm-8" style="padding-top: 1ch">
value="https://creativecommons.org/share-your-work/public-domain/cc0/"> <select data-style="input-dropdown" data-width="100%" class="selectpicker" id="inputSoftwareLicense" data-live-search="true" data-i18n-title="LABEL_LICENSE" required disabled>
</label> </select>
<div class="valid-feedback"></div>
<div class="invalid-feedback" data-i18n="LABEL_MANDATORY_FIELD">Pflichtfeld</div>
</div> </div>
</div>
<div class="col-sm-3">
<label for="choicesLicense" id="choosenLicense" class="col-form-label">CC-0</label>
</div>
</div> </div>
<div class="form-group row"> <div class="form-group row">
<label for="inputSubjectOf" class="col-sm-2 col-form-label" data-i18n="LABEL_SUBJECT">Fach</label> <label for="inputSubjectOf" class="col-sm-2 col-form-label" data-i18n="LABEL_SUBJECT">Fach</label>
@ -293,7 +308,8 @@
async function init() { async function init() {
await loadVocabs(); await loadVocabs();
await i18nLoader(); await i18nLoader();
chooseLicense(); chooseCCLicense();
addSoftwareLicenses();
addCreator(); addCreator();
$("#inputEducationalLevel option[value='https://w3id.org/kim/educationalLevel/level_A']").attr("selected", "true"); $("#inputEducationalLevel option[value='https://w3id.org/kim/educationalLevel/level_A']").attr("selected", "true");
$('.selectpicker').selectpicker('refresh'); $('.selectpicker').selectpicker('refresh');
@ -302,7 +318,9 @@
if (userLang) { if (userLang) {
changeLanguage(userLang); changeLanguage(userLang);
} }
} }
let vocabInstitutions = [] let vocabInstitutions = []
function loadVocabs() { function loadVocabs() {
@ -385,8 +403,50 @@
} }
]; ];
const softwareLicenses = [
{
name: 'Apache License 2.0',
url:'https://opensource.org/license/apache-2-0'
},
{
name: 'BSD 2-Clause "Simplified" License',
url: 'https://opensource.org/license/bsd-2-clause'
},
{
name: 'BSD 3-Clause "New" or "Revised" License',
url: 'https://opensource.org/license/bsd-3-clause',
},
{
name: 'GNU General Public License v2.0',
url: 'https://opensource.org/license/gpl-2-0',
},
{
name: 'GNU General Public License v3.0',
url: 'https://opensource.org/license/gpl-3-0',
},
{
name: 'GNU Lesser General Public License v2.1',
url: 'https://opensource.org/license/lgpl-2-1',
},
{
name: 'GNU Affero General Public License v3.0',
url: 'https://www.gnu.org/licenses/agpl-3.0.html',
},
{
name: 'MIT License',
url: 'https://opensource.org/license/mit',
},
{
name: 'GNU Free Documentation License',
url: 'https://www.gnu.org/licenses/fdl-1.3.html',
},
{
name: 'Zero-Clause BSD',
url: 'https://opensource.org/license/0bsd'
}
]
function chooseLicense() { function chooseCCLicense() {
const by = document.getElementById("inputLicenseBY") const by = document.getElementById("inputLicenseBY")
const sa = document.getElementById("inputLicenseSA") const sa = document.getElementById("inputLicenseSA")
const nd = document.getElementById("inputLicenseND") const nd = document.getElementById("inputLicenseND")
@ -478,6 +538,27 @@
} }
} }
function addSoftwareLicenses() {
softwareLicenses.forEach((item) => {
$("#inputSoftwareLicense").append('<option value="' + item.url + '" data-i18n="' + item.name + '">'+item.name+'</option>');
});
}
function ccOrSoftwareLicense() {
if(document.getElementById("radioLicenseCC").checked) {
document.getElementById("inputLicenseBY").disabled = false;
document.getElementById("choicesLicense").style = "";
chooseCCLicense();
document.getElementById("inputSoftwareLicense").setAttribute("disabled", "true");
} else {
document.getElementById("inputLicenseBY").disabled = true;
document.getElementById("choicesLicense").style = "color: gray";
document.getElementById("choosenLicense").style = "color: gray";
document.getElementById("inputSoftwareLicense").removeAttribute("disabled");
}
$('.selectpicker').selectpicker('refresh');
}
function splitKeywords(keywordString) { function splitKeywords(keywordString) {
const keywords = keywordString.split(","); const keywords = keywordString.split(",");
return keywords.map((k) => k.trim()); return keywords.map((k) => k.trim());
@ -712,7 +793,11 @@
type: "LearningResource", type: "LearningResource",
name: document.getElementById("inputTitle").value, name: document.getElementById("inputTitle").value,
description: document.getElementById("inputDescription").value, description: document.getElementById("inputDescription").value,
license: document.getElementById("licenseUrl").value }
if(document.getElementById("radioLicenseCC").checked) {
meta.license = document.getElementById("licenseUrl").value
} else {
meta.license = document.getElementById("inputSoftwareLicense").value
} }
if (identifier) { if (identifier) {
meta.id = identifier; meta.id = identifier;
@ -791,7 +876,7 @@
document.getElementById("inputDescription").value = data.description ? data.description : ""; document.getElementById("inputDescription").value = data.description ? data.description : "";
$('#inputLanguage').val(data.inLanguage ? data.inLanguage : []).selectpicker('refresh'); $('#inputLanguage').val(data.inLanguage ? data.inLanguage : []).selectpicker('refresh');
$('#inputSubjectOf').val(aboutIds).selectpicker('refresh'); $('#inputSubjectOf').val(aboutIds).selectpicker('refresh');
setLicense(licenseUrl) setLicense((data.license && data.license.id) ? idMap(data.license) : data.license)
document.getElementById("inputImage").value = data.image ? data.image : ""; document.getElementById("inputImage").value = data.image ? data.image : "";
$('#inputResourceType').val(learningResourceTypeIds).selectpicker('refresh'); $('#inputResourceType').val(learningResourceTypeIds).selectpicker('refresh');
if (educationalLevelIds.length > 0) { if (educationalLevelIds.length > 0) {
@ -805,52 +890,63 @@
} }
} }
function setLicense(license) { function setLicense(license) {
const by = document.getElementById("inputLicenseBY") if (license.startsWith("https://creativecommons.org/")) {
const sa = document.getElementById("inputLicenseSA") const by = document.getElementById("inputLicenseBY")
const nd = document.getElementById("inputLicenseND") const sa = document.getElementById("inputLicenseSA")
const nc = document.getElementById("inputLicenseNC") const nd = document.getElementById("inputLicenseND")
if (license.startsWith("https://creativecommons.org/publicdomain/zero/")) { const nc = document.getElementById("inputLicenseNC")
by.checked = true; if (license.startsWith("https://creativecommons.org/publicdomain/zero/")) {
sa.checked = true; by.checked = true;
nd.checked = true; sa.checked = true;
nc.checked = true; nd.checked = true;
} else if (license.startsWith("https://creativecommons.org/licenses/by/")) { nc.checked = true;
by.checked = false; } else if (license.startsWith("https://creativecommons.org/licenses/by/")) {
sa.checked = true; by.checked = false;
nd.checked = true; sa.checked = true;
nc.checked = true; nd.checked = true;
} else if (license.startsWith("https://creativecommons.org/licenses/by-sa/")) { nc.checked = true;
by.checked = false; } else if (license.startsWith("https://creativecommons.org/licenses/by-sa/")) {
sa.checked = false; by.checked = false;
nd.checked = true; sa.checked = false;
nc.checked = true; nd.checked = true;
} else if (license.startsWith("https://creativecommons.org/licenses/by-nd/")) { nc.checked = true;
by.checked = false; } else if (license.startsWith("https://creativecommons.org/licenses/by-nd/")) {
sa.checked = true; by.checked = false;
nd.checked = false; sa.checked = true;
nc.checked = true; nd.checked = false;
} else if (license.startsWith("https://creativecommons.org/licenses/by-nc/")) { nc.checked = true;
by.checked = false; } else if (license.startsWith("https://creativecommons.org/licenses/by-nc/")) {
sa.checked = true; by.checked = false;
nd.checked = true; sa.checked = true;
nc.checked = false; nd.checked = true;
} else if (license.startsWith("https://creativecommons.org/licenses/by-nc-sa/")) { nc.checked = false;
by.checked = false; } else if (license.startsWith("https://creativecommons.org/licenses/by-nc-sa/")) {
sa.checked = false; by.checked = false;
nd.checked = true; sa.checked = false;
nc.checked = false; nd.checked = true;
} else if (license.startsWith("https://creativecommons.org/licenses/by-nc-nd/")) { nc.checked = false;
by.checked = false; } else if (license.startsWith("https://creativecommons.org/licenses/by-nc-nd/")) {
sa.checked = true; by.checked = false;
nd.checked = false; sa.checked = true;
nc.checked = false; nd.checked = false;
nc.checked = false;
} else {
by.checked = false;
sa.checked = false;
nd.checked = false;
nc.checked = false;
}
chooseCCLicense();
} else { } else {
by.checked = false; document.getElementById("inputSoftwareLicense").name = softwareLicenses.find(l => l.url == license).name;
sa.checked = false; document.getElementById("inputSoftwareLicense").value = license;
nd.checked = false; document.getElementById("radioLicenseSoftware").checked = "true";
nc.checked = false; document.getElementById("inputLicenseBY").disabled = true;
document.getElementById("choicesLicense").style = "color: gray";
document.getElementById("choosenLicense").style = "color: gray";
document.getElementById("inputSoftwareLicense").removeAttribute("disabled");
$('.selectpicker').selectpicker('refresh');
} }
chooseLicense();
} }
async function i18nLoader() { async function i18nLoader() {