mirror of
https://gitlab.com/comenius-institut/foerbico/metadata-form.git
synced 2025-12-09 16:24:30 +00:00
use jsyaml for generator; added creativeWorkStatus
This commit is contained in:
parent
dc40c1b0aa
commit
9be2ce0286
1 changed files with 25 additions and 27 deletions
|
|
@ -416,12 +416,8 @@
|
|||
}
|
||||
|
||||
function splitKeywords(keywordString) {
|
||||
var keywords = keywordString.split(",");
|
||||
var listString = "";
|
||||
for (x in keywords) {
|
||||
listString += " - \"" + keywords[x].trim() + "\"\n";
|
||||
}
|
||||
return listString;
|
||||
const keywords = keywordString.split(",");
|
||||
return keywords.map((k) => k.trim());
|
||||
}
|
||||
|
||||
function addCreator(firstName = "", lastName = "", authorId = "") {
|
||||
|
|
@ -465,13 +461,12 @@
|
|||
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;
|
||||
creators.push({
|
||||
name: (creatorsElement[i].getElementsByClassName("inputGivenName")[0].value
|
||||
+ " "
|
||||
+ creatorsElement[i].getElementsByClassName("inputFamilyName")[0].value).trim(),
|
||||
givenName: creatorsElement[i].getElementsByClassName("inputGivenName")[0].value,
|
||||
familyName: creatorsElement[i].getElementsByClassName("inputFamilyName")[0].value,
|
||||
creatorId: creatorsElement[i].getElementsByClassName("inputAuthorId")[0].value
|
||||
id: creatorId ? creatorId : undefined
|
||||
});
|
||||
}
|
||||
return creators;
|
||||
|
|
@ -483,38 +478,41 @@
|
|||
const selectedLanguages = $('#inputLanguage').val();
|
||||
const selectedSubjects = $('#inputSubjectOf').val();
|
||||
const selectedResourceTypes = $('#inputResourceType').val();
|
||||
var meta = "---\n"
|
||||
meta += "id: \"" + document.getElementById("inputUrl").value + "\"\n"
|
||||
meta += "name: \"" + document.getElementById("inputTitle").value + "\"\n"
|
||||
let meta = {
|
||||
creativeWorkStatus: document.getElementById("inputStatus").value,
|
||||
id: document.getElementById("inputUrl").value,
|
||||
name: document.getElementById("inputTitle").value,
|
||||
description: document.getElementById("inputDescription").value,
|
||||
license: {id: document.getElementById("licenseUrl").value}
|
||||
}
|
||||
if (creators.length > 0) {
|
||||
meta += "creator:\n"
|
||||
meta += creators.map((c) => " - name: \"" + c.name + "\"" + (c.creatorId ? "\n id: \"" + c.creatorId + "\"" : "")).join("\n") + "\n"
|
||||
meta.creator = creators
|
||||
}
|
||||
if (document.getElementById("inputTags").value) {
|
||||
meta += "keywords:\n"
|
||||
meta += splitKeywords(document.getElementById("inputTags").value)
|
||||
meta.keywords = splitKeywords(document.getElementById("inputTags").value)
|
||||
}
|
||||
meta += "description: \"" + document.getElementById("inputDescription").value + "\"\n"
|
||||
if (selectedLanguages.length > 0) {
|
||||
meta += "inLanguage:\n" + selectedLanguages.map((l) => " - \"" + l + "\"").join("\n") + "\n"
|
||||
meta.inLanguage = selectedLanguages;
|
||||
}
|
||||
if (inputSourceOrganization.value) {
|
||||
meta += "sourceOrganization:\n"
|
||||
meta += " - name: \"" + inputSourceOrganization.options[inputSourceOrganization.selectedIndex].innerHTML + "\"\n"
|
||||
meta += " id: \"" + inputSourceOrganization.value + "\"\n"
|
||||
meta += " type: \"Organization\"\n"
|
||||
meta.sourceOrganization = [
|
||||
{
|
||||
name: inputSourceOrganization.options[inputSourceOrganization.selectedIndex].innerHTML,
|
||||
id: inputSourceOrganization.value,
|
||||
type: "Organization"
|
||||
}
|
||||
]
|
||||
}
|
||||
if (selectedSubjects.length > 0) {
|
||||
meta += "about:\n" + selectedSubjects.map((s) => " - id: \"" + s + "\"").join("\n") + "\n"
|
||||
meta.about = selectedSubjects.map((s) => ({id: s}))
|
||||
}
|
||||
meta += "license:\n" + " id: \"" + document.getElementById("licenseUrl").value + "\"\n"
|
||||
if (document.getElementById("inputImage").value) {
|
||||
meta += "image: \"" + document.getElementById("inputImage").value + "\"\n"
|
||||
meta.image = document.getElementById("inputImage").value
|
||||
}
|
||||
if (selectedResourceTypes.length > 0) {
|
||||
meta += "learningResourceType:\n" + selectedResourceTypes.map((t) => " - id: \"" + t + "\"").join("\n") + "\n"
|
||||
meta.learningResourceType = selectedResourceTypes.map((t) => ({id: t}))
|
||||
}
|
||||
document.getElementById("comment").value = meta;
|
||||
document.getElementById("comment").value = jsyaml.dump(meta);
|
||||
}
|
||||
|
||||
function setCreators(creators) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue