diff --git a/app/Jobs/Form/StoreFormSubmissionJob.php b/app/Jobs/Form/StoreFormSubmissionJob.php index ef2f1814..3cbaf224 100644 --- a/app/Jobs/Form/StoreFormSubmissionJob.php +++ b/app/Jobs/Form/StoreFormSubmissionJob.php @@ -216,6 +216,10 @@ class StoreFormSubmissionJob implements ShouldQueue private function storeSignature(?string $value) { + if ($value && preg_match('/^[\/\w\-. ]+$/', $value)) { // If it's filename + return $this->storeFile($value); + } + if ($value == null || !isset(explode(',', $value)[1])) { return null; } diff --git a/client/components/forms/SignatureInput.vue b/client/components/forms/SignatureInput.vue index 677c6b62..4b04aaa1 100644 --- a/client/components/forms/SignatureInput.vue +++ b/client/components/forms/SignatureInput.vue @@ -4,7 +4,42 @@ +
+
+ +

+ Uploading your file... +

+
+ + +
+ + + Upload file instead + + ({ + file: null, + loading: false + }), + + watch: { + file: { + handler(file) { + this.compVal = file?.url || null + } + } + }, + methods: { clear() { - this.$refs.signaturePad.clearSignature() + this.file = null + this.$refs.signaturePad?.clearSignature() this.onEnd() }, onEnd() { + if (!this.$refs.signaturePad) { + this.form[this.name] = null + return + } + if (this.disabled) { this.$refs.signaturePad.clearSignature() } else { @@ -71,6 +146,39 @@ export default { this.form[this.name] = !isEmpty && data ? data : null } }, + openFileUpload() { + if (this.disabled || !this.$refs['actual-input']) return + this.$refs['actual-input'].click() + }, + manualFileUpload(e) { + const files = e.target.files + for (let i = 0; i < files.length; i++) { + this.uploadFileToServer(files.item(i)) + } + }, + uploadFileToServer(file) { + if (this.disabled) return + this.loading = true + storeFile(file) + .then((response) => { + this.file = { + file: file, + url: file.name.split('.').slice(0, -1).join('.') + '_' + response.uuid + '.' + response.extension, + src: this.getFileSrc(file) + } + this.loading = false + }) + .catch((error) => { + this.loading = false + this.file = null + }) + }, + getFileSrc(file) { + if (file.type && file.type.split('/')[0] === 'image') { + return URL.createObjectURL(file) + } + return null + } }, } diff --git a/client/components/forms/components/UploadedFile.vue b/client/components/forms/components/UploadedFile.vue index cae51792..f0bd361e 100644 --- a/client/components/forms/components/UploadedFile.vue +++ b/client/components/forms/components/UploadedFile.vue @@ -37,6 +37,7 @@ {{ file.file.name }}

{ const theme = inject("theme", null)