2023-05-25 22:47:52 +03:00
|
|
|
import { createApp, reactive } from 'vue'
|
|
|
|
|
|
2023-05-31 23:19:20 +03:00
|
|
|
import Form from './submission_form/form'
|
2023-06-20 20:50:15 +00:00
|
|
|
import DownloadButton from './elements/download_button'
|
2024-05-31 14:33:00 +03:00
|
|
|
import ToggleSubmit from './elements/toggle_submit'
|
2025-04-08 15:24:17 +03:00
|
|
|
import FetchForm from './elements/fetch_form'
|
2023-05-25 22:47:52 +03:00
|
|
|
|
2024-05-23 13:44:00 +03:00
|
|
|
const safeRegisterElement = (name, element, options = {}) => !window.customElements.get(name) && window.customElements.define(name, element, options)
|
|
|
|
|
|
|
|
|
|
safeRegisterElement('download-button', DownloadButton)
|
2024-05-31 14:33:00 +03:00
|
|
|
safeRegisterElement('toggle-submit', ToggleSubmit)
|
2025-04-08 15:24:17 +03:00
|
|
|
safeRegisterElement('fetch-form', FetchForm)
|
2024-05-23 13:44:00 +03:00
|
|
|
safeRegisterElement('submission-form', class extends HTMLElement {
|
2023-05-25 22:47:52 +03:00
|
|
|
connectedCallback () {
|
|
|
|
|
this.appElem = document.createElement('div')
|
|
|
|
|
|
2023-05-31 23:19:20 +03:00
|
|
|
this.app = createApp(Form, {
|
2023-09-03 14:05:31 +03:00
|
|
|
submitter: JSON.parse(this.dataset.submitter),
|
2024-09-12 17:31:37 +03:00
|
|
|
inviteSubmitters: JSON.parse(this.dataset.inviteSubmitters),
|
2024-12-19 17:17:34 +02:00
|
|
|
optionalInviteSubmitters: JSON.parse(this.dataset.optionalInviteSubmitters),
|
2024-12-07 01:35:59 +02:00
|
|
|
schema: JSON.parse(this.dataset.schema),
|
2023-06-30 20:31:17 +03:00
|
|
|
canSendEmail: this.dataset.canSendEmail === 'true',
|
2024-06-11 18:19:21 +03:00
|
|
|
previousSignatureValue: this.dataset.previousSignatureValue,
|
2023-09-22 21:50:39 +03:00
|
|
|
goToLast: this.dataset.goToLast === 'true',
|
2023-07-12 01:24:25 +03:00
|
|
|
isDemo: this.dataset.isDemo === 'true',
|
2023-09-03 20:44:54 +03:00
|
|
|
attribution: this.dataset.attribution !== 'false',
|
2024-07-02 20:27:25 +03:00
|
|
|
scrollPadding: this.dataset.scrollPadding || '-80px',
|
2024-09-28 01:21:35 +03:00
|
|
|
language: this.dataset.language,
|
2024-07-02 20:27:25 +03:00
|
|
|
dryRun: this.dataset.dryRun === 'true',
|
|
|
|
|
expand: ['true', 'false'].includes(this.dataset.expand) ? this.dataset.expand === 'true' : null,
|
2024-07-24 20:55:35 +03:00
|
|
|
withSignatureId: this.dataset.withSignatureId === 'true',
|
2024-08-06 00:19:33 +03:00
|
|
|
requireSigningReason: this.dataset.requireSigningReason === 'true',
|
2024-01-26 17:43:52 +02:00
|
|
|
withConfetti: this.dataset.withConfetti !== 'false',
|
2024-05-12 12:08:18 +03:00
|
|
|
withDisclosure: this.dataset.withDisclosure === 'true',
|
2024-10-10 13:14:49 +03:00
|
|
|
reuseSignature: this.dataset.reuseSignature !== 'false',
|
2023-12-02 16:26:34 +02:00
|
|
|
withTypedSignature: this.dataset.withTypedSignature !== 'false',
|
2024-03-23 23:16:40 +02:00
|
|
|
authenticityToken: document.querySelector('meta[name="csrf-token"]')?.content,
|
2024-06-15 15:55:09 +03:00
|
|
|
rememberSignature: this.dataset.rememberSignature === 'true',
|
2023-05-25 22:47:52 +03:00
|
|
|
values: reactive(JSON.parse(this.dataset.values)),
|
2024-04-05 16:16:30 +03:00
|
|
|
completedButton: JSON.parse(this.dataset.completedButton || '{}'),
|
2024-06-02 14:50:37 +03:00
|
|
|
withQrButton: true,
|
2024-04-05 16:16:30 +03:00
|
|
|
completedMessage: JSON.parse(this.dataset.completedMessage || '{}'),
|
2024-01-14 12:11:13 +02:00
|
|
|
completedRedirectUrl: this.dataset.completedRedirectUrl,
|
2023-05-25 22:47:52 +03:00
|
|
|
attachments: reactive(JSON.parse(this.dataset.attachments)),
|
|
|
|
|
fields: JSON.parse(this.dataset.fields)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
this.app.mount(this.appElem)
|
|
|
|
|
|
|
|
|
|
this.appendChild(this.appElem)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
disconnectedCallback () {
|
|
|
|
|
this.app?.unmount()
|
|
|
|
|
this.appElem?.remove()
|
|
|
|
|
}
|
|
|
|
|
})
|