implement signature preview

This commit is contained in:
Alex Turchyn
2023-05-24 01:22:17 +03:00
parent f1da37d1ec
commit b5b4f286cf
6 changed files with 73 additions and 19 deletions
+20 -4
View File
@@ -9,7 +9,10 @@ export default actionable(targetable(class extends HTMLElement {
'canvas',
'input',
'okButton',
'clearButton'
'image',
'clearButton',
'redrawButton',
'nextButton'
]
connectedCallback () {
@@ -22,7 +25,7 @@ export default actionable(targetable(class extends HTMLElement {
this.okButton.disabled = true
this.canvas.toBlob((blob) => {
const file = new File([blob], 'signature.jpg', { type: 'image/jpg' })
const file = new File([blob], 'signature.png', { type: 'image/png' })
new DirectUpload(
file,
@@ -38,10 +41,23 @@ export default actionable(targetable(class extends HTMLElement {
headers: { 'Content-Type': 'application/json' }
}).then((resp) => resp.json()).then((attachment) => {
this.input.value = attachment.uuid
this.dispatchEvent(new CustomEvent('upload', { details: attachment }))
this.dispatchEvent(new CustomEvent('upload', { detail: attachment }))
})
})
}, 'image/jpeg', 0.95)
}, 'image/png')
}
redraw (e) {
e?.preventDefault()
this.input.value = ''
this.canvas.classList.remove('hidden')
this.clearButton.classList.remove('hidden')
this.okButton.classList.remove('hidden')
this.image.remove()
this.redrawButton.remove()
this.nextButton.remove()
}
clear (e) {