-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform.js
49 lines (45 loc) · 1.42 KB
/
form.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { resolveFromZip, OcaJs } from 'oca.js-form-core'
import { renderOCAForm } from 'oca.js-form-html'
const ocaJs = new OcaJs({
dataVaults: ['https://data-vault.argo.colossi.network'],
ocaRepositories: ['https://repository-old.oca.argo.colossi.network/api/v0.1/schemas']
})
const app = document.querySelector('#app')
const fileChooser = document.querySelector('#file-input')
fileChooser.onchange = async e => {
let ocaBundleFile = e.target.files[0]
const files = []
for (let i = 0; i < e.target.files.length; i++) {
const file = e.target.files[i]
if (file.type === 'application/zip') {
ocaBundleFile = file
} else {
files.push(file)
}
}
const additionalOverlays = (await Promise.all(files.map(f => readFile(f)))).map(o => JSON.parse(o))
const oca = await resolveFromZip(ocaBundleFile)
const structure = await ocaJs.createStructure(oca)
const onSubmitHandler = (capturedData) => {
console.log(capturedData)
}
const data = {}
const form = await renderOCAForm(structure, data, {
showFlagged: true,
defaultLanguage: 'en',
onSubmitHandler,
ocaRepoHostUrl: 'https://repository-old.oca.argo.colossi.network',
additionalOverlays
})
app.innerHTML = form
}
const readFile = (file) => {
return new Promise((resolve, reject) => {
var fr = new FileReader()
fr.onload = () => {
resolve(fr.result)
}
fr.onerror = reject
fr.readAsText(file)
})
}