49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
import axios from "axios";
|
|
|
|
export function createRecordEntry() {
|
|
const createButton = document.getElementById("record-create-button");
|
|
if(!createButton){
|
|
return;
|
|
}
|
|
createButton.addEventListener("click", save)
|
|
}
|
|
|
|
|
|
function save(e) {
|
|
e.preventDefault();
|
|
const recordForm = document.getElementById("record-form");
|
|
let validationErrors = null;
|
|
let errorMessage = "";
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
const schemaName = urlParams.get("schema")
|
|
console.log("SAVE: Attempt");
|
|
|
|
let formData = new FormData(recordForm)
|
|
|
|
axios
|
|
.post("/lucent/records", {
|
|
schema: schemaName,
|
|
data: Object.fromEntries(formData),
|
|
status: "draft",
|
|
// edges: graph.edges,
|
|
isCreateMode: true,
|
|
})
|
|
.then(function (response) {
|
|
console.log("SAVE: SAVED");
|
|
window.location = "/lucent/recordss/" + record.id;
|
|
return;
|
|
})
|
|
.catch(function (error) {
|
|
if (!error?.response) {
|
|
}
|
|
if (typeof error?.response.data.error === "string") {
|
|
errorMessage = error.response.data.error;
|
|
} else {
|
|
validationErrors = error.response.data.error;
|
|
console.log(validationErrors)
|
|
}
|
|
|
|
|
|
});
|
|
|
|
} |