add blank page button
This commit is contained in:
@@ -177,7 +177,7 @@
|
|||||||
@change="save"
|
@change="save"
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
class="sticky bottom-0 py-2"
|
class="sticky bottom-0 py-2 space-y-2"
|
||||||
:style="{ backgroundColor }"
|
:style="{ backgroundColor }"
|
||||||
>
|
>
|
||||||
<Upload
|
<Upload
|
||||||
@@ -186,6 +186,22 @@
|
|||||||
:template-id="template.id"
|
:template-id="template.id"
|
||||||
@success="updateFromUpload"
|
@success="updateFromUpload"
|
||||||
/>
|
/>
|
||||||
|
<button
|
||||||
|
v-if="sortedDocuments.length && editable && withAddPageButton"
|
||||||
|
id="add_blank_page_button"
|
||||||
|
class="btn btn-outline w-full"
|
||||||
|
@click.prevent="addBlankPage"
|
||||||
|
>
|
||||||
|
<IconInnerShadowTop
|
||||||
|
v-if="isLoadingBlankPage"
|
||||||
|
class="animate-spin w-5 h-5"
|
||||||
|
/>
|
||||||
|
<IconPlus
|
||||||
|
v-else
|
||||||
|
class="w-5 h-5"
|
||||||
|
/>
|
||||||
|
{{ t('add_blank_page') }}
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
@@ -196,12 +212,30 @@
|
|||||||
ref="documents"
|
ref="documents"
|
||||||
class="pr-3.5 pl-0.5"
|
class="pr-3.5 pl-0.5"
|
||||||
>
|
>
|
||||||
<Dropzone
|
<template v-if="!sortedDocuments.length && (withUploadButton || withAddPageButton)">
|
||||||
v-if="!sortedDocuments.length && withUploadButton"
|
<Dropzone
|
||||||
:template-id="template.id"
|
v-if="withUploadButton"
|
||||||
:accept-file-types="acceptFileTypes"
|
:template-id="template.id"
|
||||||
@success="updateFromUpload"
|
:accept-file-types="acceptFileTypes"
|
||||||
/>
|
@success="updateFromUpload"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
v-if="withAddPageButton"
|
||||||
|
id="add_blank_page_button"
|
||||||
|
class="btn btn-outline w-full mt-4"
|
||||||
|
@click.prevent="addBlankPage"
|
||||||
|
>
|
||||||
|
<IconInnerShadowTop
|
||||||
|
v-if="isLoadingBlankPage"
|
||||||
|
class="animate-spin w-5 h-5"
|
||||||
|
/>
|
||||||
|
<IconPlus
|
||||||
|
v-else
|
||||||
|
class="w-5 h-5"
|
||||||
|
/>
|
||||||
|
{{ t('add_blank_page') }}
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<template
|
<template
|
||||||
v-for="document in sortedDocuments"
|
v-for="document in sortedDocuments"
|
||||||
@@ -242,7 +276,7 @@
|
|||||||
</template>
|
</template>
|
||||||
<div
|
<div
|
||||||
v-if="sortedDocuments.length && isBreakpointLg && editable"
|
v-if="sortedDocuments.length && isBreakpointLg && editable"
|
||||||
class="pb-4"
|
class="pb-4 space-y-2"
|
||||||
>
|
>
|
||||||
<Upload
|
<Upload
|
||||||
v-if="withUploadButton"
|
v-if="withUploadButton"
|
||||||
@@ -250,6 +284,22 @@
|
|||||||
:accept-file-types="acceptFileTypes"
|
:accept-file-types="acceptFileTypes"
|
||||||
@success="updateFromUpload"
|
@success="updateFromUpload"
|
||||||
/>
|
/>
|
||||||
|
<button
|
||||||
|
v-if="withAddPageButton"
|
||||||
|
id="add_blank_page_button"
|
||||||
|
class="btn btn-outline w-full mt-4"
|
||||||
|
@click.prevent="addBlankPage"
|
||||||
|
>
|
||||||
|
<IconInnerShadowTop
|
||||||
|
v-if="isLoadingBlankPage"
|
||||||
|
class="animate-spin w-5 h-5"
|
||||||
|
/>
|
||||||
|
<IconPlus
|
||||||
|
v-else
|
||||||
|
class="w-5 h-5"
|
||||||
|
/>
|
||||||
|
{{ t('add_blank_page') }}
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
@@ -350,7 +400,7 @@ import Contenteditable from './contenteditable'
|
|||||||
import DocumentPreview from './preview'
|
import DocumentPreview from './preview'
|
||||||
import DocumentControls from './controls'
|
import DocumentControls from './controls'
|
||||||
import MobileFields from './mobile_fields'
|
import MobileFields from './mobile_fields'
|
||||||
import { IconUsersPlus, IconDeviceFloppy, IconChevronDown, IconEye, IconWritingSign, IconInnerShadowTop, IconInfoCircle } from '@tabler/icons-vue'
|
import { IconPlus, IconUsersPlus, IconDeviceFloppy, IconChevronDown, IconEye, IconWritingSign, IconInnerShadowTop, IconInfoCircle } from '@tabler/icons-vue'
|
||||||
import { v4 } from 'uuid'
|
import { v4 } from 'uuid'
|
||||||
import { ref, computed } from 'vue'
|
import { ref, computed } from 'vue'
|
||||||
import { en as i18nEn } from './i18n'
|
import { en as i18nEn } from './i18n'
|
||||||
@@ -363,6 +413,7 @@ export default {
|
|||||||
Fields,
|
Fields,
|
||||||
IconInfoCircle,
|
IconInfoCircle,
|
||||||
MobileDrawField,
|
MobileDrawField,
|
||||||
|
IconPlus,
|
||||||
IconWritingSign,
|
IconWritingSign,
|
||||||
MobileFields,
|
MobileFields,
|
||||||
Logo,
|
Logo,
|
||||||
@@ -420,6 +471,11 @@ export default {
|
|||||||
required: false,
|
required: false,
|
||||||
default: true
|
default: true
|
||||||
},
|
},
|
||||||
|
withAddPageButton: {
|
||||||
|
type: Boolean,
|
||||||
|
required: false,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
autosave: {
|
autosave: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
required: false,
|
required: false,
|
||||||
@@ -566,6 +622,7 @@ export default {
|
|||||||
return {
|
return {
|
||||||
documentRefs: [],
|
documentRefs: [],
|
||||||
isBreakpointLg: false,
|
isBreakpointLg: false,
|
||||||
|
isLoadingBlankPage: false,
|
||||||
isSaving: false,
|
isSaving: false,
|
||||||
selectedSubmitter: null,
|
selectedSubmitter: null,
|
||||||
showDrawField: false,
|
showDrawField: false,
|
||||||
@@ -1148,6 +1205,35 @@ export default {
|
|||||||
|
|
||||||
document.activeElement?.blur()
|
document.activeElement?.blur()
|
||||||
},
|
},
|
||||||
|
addBlankPage () {
|
||||||
|
this.isLoadingBlankPage = true
|
||||||
|
|
||||||
|
const canvas = document.createElement('canvas')
|
||||||
|
|
||||||
|
canvas.width = 816
|
||||||
|
canvas.height = 1056
|
||||||
|
|
||||||
|
const ctx = canvas.getContext('2d')
|
||||||
|
|
||||||
|
ctx.fillStyle = 'white'
|
||||||
|
ctx.fillRect(0, 0, canvas.width, canvas.height)
|
||||||
|
|
||||||
|
canvas.toBlob((blob) => {
|
||||||
|
const file = new File([blob], `Page ${this.template.schema.length + 1}.png`, { type: blob.type, lastModified: Date.now() })
|
||||||
|
|
||||||
|
const formData = new FormData()
|
||||||
|
formData.append('files[]', file)
|
||||||
|
|
||||||
|
this.baseFetch(`/templates/${this.template.id}/documents`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData
|
||||||
|
}).then(async (resp) => {
|
||||||
|
this.updateFromUpload(await resp.json())
|
||||||
|
}).finally(() => {
|
||||||
|
this.isLoadingBlankPage = false
|
||||||
|
})
|
||||||
|
}, 'image/png')
|
||||||
|
},
|
||||||
updateFromUpload (data) {
|
updateFromUpload (data) {
|
||||||
this.template.schema.push(...data.schema)
|
this.template.schema.push(...data.schema)
|
||||||
this.template.documents.push(...data.documents)
|
this.template.documents.push(...data.documents)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
@drop.prevent="onDropFiles"
|
@drop.prevent="onDropFiles"
|
||||||
>
|
>
|
||||||
<label
|
<label
|
||||||
|
id="document_dropzone"
|
||||||
class="w-full relative hover:bg-base-200/30 rounded-md border border-2 border-base-content/10 border-dashed"
|
class="w-full relative hover:bg-base-200/30 rounded-md border border-2 border-base-content/10 border-dashed"
|
||||||
:for="inputId"
|
:for="inputId"
|
||||||
:class="{ 'opacity-50': isLoading || isProcessing }"
|
:class="{ 'opacity-50': isLoading || isProcessing }"
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ const en = {
|
|||||||
keep: 'Keep',
|
keep: 'Keep',
|
||||||
left: 'Left',
|
left: 'Left',
|
||||||
validation: 'Validation',
|
validation: 'Validation',
|
||||||
|
add_blank_page: 'Add blank page',
|
||||||
right: 'Right',
|
right: 'Right',
|
||||||
center: 'Center',
|
center: 'Center',
|
||||||
description: 'Description',
|
description: 'Description',
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<label
|
<label
|
||||||
|
id="add_document_button"
|
||||||
:for="inputId"
|
:for="inputId"
|
||||||
class="btn btn-outline w-full"
|
class="btn btn-outline w-full"
|
||||||
:class="{ 'btn-disabled': isLoading || isProcessing }"
|
:class="{ 'btn-disabled': isLoading || isProcessing }"
|
||||||
|
|||||||
Reference in New Issue
Block a user