prefill signature

This commit is contained in:
Pete Matsyburka
2024-06-15 15:55:09 +03:00
parent 9e66f8412c
commit f9d52e56a2
14 changed files with 195 additions and 30 deletions
+1
View File
@@ -70,6 +70,7 @@ window.customElements.define('draw-signature', class extends HTMLElement {
formData.append('file', file)
formData.append('submitter_slug', this.dataset.slug)
formData.append('name', 'attachments')
formData.append('remember_signature', 'true')
return fetch('/api/attachments', {
method: 'POST',
+1
View File
@@ -23,6 +23,7 @@ safeRegisterElement('submission-form', class extends HTMLElement {
withDisclosure: this.dataset.withDisclosure === 'true',
withTypedSignature: this.dataset.withTypedSignature !== 'false',
authenticityToken: document.querySelector('meta[name="csrf-token"]')?.content,
rememberSignature: this.dataset.rememberSignature === 'true',
values: reactive(JSON.parse(this.dataset.values)),
completedButton: JSON.parse(this.dataset.completedButton || '{}'),
withQrButton: true,
+7 -1
View File
@@ -323,11 +323,12 @@
:field="currentField"
:previous-value="previousSignatureValueFor(currentField) || previousSignatureValue"
:with-typed-signature="withTypedSignature"
:remember-signature="rememberSignature"
:attachments-index="attachmentsIndex"
:button-text="buttonText"
:with-disclosure="withDisclosure"
:with-qr-button="withQrButton"
:submitter-slug="submitterSlug"
:submitter="submitter"
:show-field-names="showFieldNames"
@attached="attachments.push($event)"
@start="scrollIntoField(currentField)"
@@ -549,6 +550,11 @@ export default {
required: false,
default: null
},
rememberSignature: {
type: Boolean,
required: false,
default: false
},
minimize: {
type: Boolean,
required: false,
@@ -255,8 +255,8 @@ export default {
type: Object,
required: true
},
submitterSlug: {
type: String,
submitter: {
type: Object,
required: true
},
showFieldNames: {
@@ -284,6 +284,11 @@ export default {
required: false,
default: true
},
rememberSignature: {
type: Boolean,
required: false,
default: false
},
attachmentsIndex: {
type: Object,
required: false,
@@ -311,6 +316,9 @@ export default {
}
},
computed: {
submitterSlug () {
return this.submitter.slug
},
computedPreviousValue () {
if (this.isUsePreviousValue) {
return this.previousValue
@@ -521,6 +529,27 @@ export default {
this.uploadImageInputKey = Math.random().toString()
}
},
maybeSetSignedUuid (signedUuid) {
try {
if (window.localStorage && signedUuid && this.rememberSignature) {
const values = window.localStorage.getItem('signed_signature_uuids')
let data
if (values) {
data = JSON.parse(values)
} else {
data = {}
}
data[this.submitter.email] = signedUuid
window.localStorage.setItem('signed_signature_uuids', JSON.stringify(data))
}
} catch (e) {
console.error(e)
}
},
async submit () {
if (this.modelValue || this.computedPreviousValue) {
if (this.computedPreviousValue) {
@@ -539,6 +568,7 @@ export default {
formData.append('file', file)
formData.append('submitter_slug', this.submitterSlug)
formData.append('name', 'attachments')
formData.append('remember_signature', this.rememberSignature)
return fetch(this.baseUrl + '/api/attachments', {
method: 'POST',
@@ -547,6 +577,8 @@ export default {
this.$emit('attached', attachment)
this.$emit('update:model-value', attachment.uuid)
this.maybeSetSignedUuid(attachment.signed_uuid)
return resolve(attachment)
})
}).catch((error) => {