onDrawingNew
Drawing creation handler
This example demonstrates how the onDrawingNew callback
sends a request using the Fetch API to create new drawings and their associated layouts. Once the request completes, the
result is returned to the widget through the
onResponse
callback.
Drawing creation handler
onDrawingNew = async function(drawings: Array<DIQ_DrawingRevision>, layouts: Array<DIQ_Layout>, onResponse: (result: DIQ_Result) => void) {
try {
const res = await fetch("/api/drawings", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
drawing,
layouts
})
});
if (!res.ok) {
throw new Error(`HTTP ${res.status}`);
}
await res.json();
onResponse({ ok: true });
} catch (err) {
onResponse({
ok: false,
message: err.message || "Failed to create drawing"
});
}
};