allow to upload initial

pull/354/head
Pete Matsyburka 1 year ago
parent 5f3a8bf391
commit 9472a6b5b0

@ -50,6 +50,26 @@
</span> </span>
</a> </a>
</span> </span>
<span
class="tooltip"
:data-tip="t('click_to_upload')"
>
<label
class="btn btn-outline btn-sm font-medium inline-flex flex-nowrap"
>
<IconUpload :width="16" />
<input
:key="uploadImageInputKey"
type="file"
hidden
accept="image/*"
@change="drawImage"
>
<span class="hidden sm:inline">
{{ t('upload') }}
</span>
</label>
</span>
<a <a
v-if="modelValue || computedPreviousValue" v-if="modelValue || computedPreviousValue"
href="#" href="#"
@ -97,7 +117,7 @@
<img <img
v-if="modelValue || computedPreviousValue" v-if="modelValue || computedPreviousValue"
:src="attachmentsIndex[modelValue || computedPreviousValue].url" :src="attachmentsIndex[modelValue || computedPreviousValue].url"
class="mx-auto bg-white border border-base-300 rounded max-h-72" class="mx-auto bg-white border border-base-300 rounded max-h-44"
> >
<canvas <canvas
v-show="!modelValue && !computedPreviousValue" v-show="!modelValue && !computedPreviousValue"
@ -120,16 +140,18 @@
<script> <script>
import { cropCanvasAndExportToPNG } from './crop_canvas' import { cropCanvasAndExportToPNG } from './crop_canvas'
import { IconReload, IconTextSize, IconSignature, IconArrowsDiagonalMinimize2 } from '@tabler/icons-vue' import { IconReload, IconTextSize, IconUpload, IconSignature, IconArrowsDiagonalMinimize2 } from '@tabler/icons-vue'
import SignaturePad from 'signature_pad' import SignaturePad from 'signature_pad'
import AppearsOn from './appears_on' import AppearsOn from './appears_on'
import MarkdownContent from './markdown_content' import MarkdownContent from './markdown_content'
import SignatureStep from './signature_step'
const scale = 3 const scale = 3
export default { export default {
name: 'InitialsStep', name: 'InitialsStep',
components: { components: {
IconUpload,
AppearsOn, AppearsOn,
IconReload, IconReload,
IconTextSize, IconTextSize,
@ -178,7 +200,8 @@ export default {
return { return {
isInitialsStarted: !!this.previousValue, isInitialsStarted: !!this.previousValue,
isUsePreviousValue: true, isUsePreviousValue: true,
isDrawInitials: false isDrawInitials: false,
uploadImageInputKey: Math.random().toString()
} }
}, },
computed: { computed: {
@ -229,6 +252,15 @@ export default {
this.intersectionObserver?.disconnect() this.intersectionObserver?.disconnect()
}, },
methods: { methods: {
drawOnCanvas: SignatureStep.methods.drawOnCanvas,
drawImage (event) {
this.remove()
this.isInitialsStarted = true
this.drawOnCanvas(this.$refs.canvas)
this.uploadImageInputKey = Math.random().toString()
},
remove () { remove () {
this.$emit('update:model-value', '') this.$emit('update:model-value', '')

@ -569,6 +569,11 @@ export default {
this.remove() this.remove()
this.isSignatureStarted = true this.isSignatureStarted = true
this.drawOnCanvas(this.$refs.canvas)
this.uploadImageInputKey = Math.random().toString()
},
drawOnCanvas (canvas) {
const file = event.target.files[0] const file = event.target.files[0]
if (file && file.type.match('image.*')) { if (file && file.type.match('image.*')) {
@ -580,7 +585,6 @@ export default {
img.src = event.target.result img.src = event.target.result
img.onload = () => { img.onload = () => {
const canvas = this.$refs.canvas
const context = canvas.getContext('2d') const context = canvas.getContext('2d')
const aspectRatio = img.width / img.height const aspectRatio = img.width / img.height
@ -615,8 +619,6 @@ export default {
} }
reader.readAsDataURL(file) reader.readAsDataURL(file)
this.uploadImageInputKey = Math.random().toString()
} }
}, },
maybeSetSignedUuid (signedUuid) { maybeSetSignedUuid (signedUuid) {

Loading…
Cancel
Save