+ + +
++ + +
++ + +
++ + +
+ `; + + var authorsFieldset = document.querySelector('#authors'); + authorsFieldset.appendChild(fieldset); +} + +function addAuthor() { + var authorId = getNbAuthors() + 1; + + addAuthorWithId(authorId); + + var nbAuthorsField = document.querySelector('#nbAuthors'); + nbAuthorsField.value = authorId; +} + +function removeAuthor() { + var authorId = getNbAuthors(); + + document.querySelector(`#author_${authorId}`).remove(); + + var nbAuthorsField = document.querySelector('#nbAuthors'); + nbAuthorsField.value = authorId-1; +} + +function generateCodemeta() { + var inputForm = document.querySelector('#inputForm'); + var codemetaText; + if (inputForm.checkValidity()) { + authors = []; + + var nbAuthors = getNbAuthors(); + + for (let authorId = 1; authorId <= nbAuthors; authorId++) { + authors.push({ + "@type": "Person", + "givenName": getIfSet(`#author_givenName_${authorId}`), + "familyName": getIfSet(`#author_familyName_${authorId}`), + "email": getIfSet(`#author_email_${authorId}`), + "@id": getIfSet(`#author_id_${authorId}`), + }) + } + + var doc = { + "@context": "https://doi.org/10.5063/schema/codemeta-2.0", + "@type": "SoftwareSourceCode", + "name": getIfSet('#name'), + "codeRepository": getIfSet('#codeRepository'), + "dateCreated": getIfSet('#dateCreated'), + "license": "https://spdx.org/licenses/" + getIfSet('#license'), + "author": authors, + }; + + codemetaText = JSON.stringify(doc, null, 4); + } + else { + codemetaText = "invalid input (see error above)"; + inputForm.reportValidity(); + } + + document.querySelector('#codemetaText').textContent = codemetaText; +} + +function initAuthors() { + var nbAuthors = getNbAuthors(); + + for (let authorId = 1; authorId <= nbAuthors; authorId++) { + addAuthorWithId(authorId); + } +} + +function initCallbacks() { + document.querySelector('#addAuthor') + .addEventListener('click', addAuthor); + document.querySelector('#removeAuthor') + .addEventListener('click', removeAuthor); + document.querySelector('#generateCodemeta') + .addEventListener('click', generateCodemeta); + + document.querySelector('#inputForm') + .addEventListener('change', generateCodemeta); + + initAuthors() +} diff --git a/style.css b/style.css new file mode 100644 index 0000000..09a12fd --- /dev/null +++ b/style.css @@ -0,0 +1,14 @@ +/** + * Copyright (C) 2019 The Software Heritage developers + * See the AUTHORS file at the top-level directory of this distribution + * License: GNU Affero General Public License version 3, or any later version + * See top-level LICENSE file for more information + */ + +#authors .author { + display: inline-block; +} + +#codemetaText { + width: 100%; +}