Adding loader on processing of add and remove page button

pull/150/merge^2
iozeey 2 years ago
parent 5f790125f2
commit 386288d3d5

@ -80,6 +80,8 @@
:editable="editable" :editable="editable"
:template="template" :template="template"
:is-direct-upload="isDirectUpload" :is-direct-upload="isDirectUpload"
:is-loading="isLoading"
:is-deleting="isDeleting"
@scroll-to="scrollIntoDocument" @scroll-to="scrollIntoDocument"
@add-blank-page="addBlankPage" @add-blank-page="addBlankPage"
@remove="onDocumentRemove" @remove="onDocumentRemove"
@ -336,7 +338,9 @@ export default {
isSaving: false, isSaving: false,
selectedSubmitter: null, selectedSubmitter: null,
drawField: null, drawField: null,
dragFieldType: null dragFieldType: null,
isLoading: false,
isDeleting: false
} }
}, },
computed: { computed: {
@ -750,6 +754,7 @@ export default {
if (indexToRemove !== -1) { if (indexToRemove !== -1) {
const confirmed = window.confirm('Are you sure you want to delete this image?') const confirmed = window.confirm('Are you sure you want to delete this image?')
if (confirmed) { if (confirmed) {
this.isDeleting = true
const documentId = document.id const documentId = document.id
const apiUrl = `/api/templates/${this.template.id}/documents/${documentId}/del_image` const apiUrl = `/api/templates/${this.template.id}/documents/${documentId}/del_image`
fetch(apiUrl, { fetch(apiUrl, {
@ -777,6 +782,9 @@ export default {
.catch((error) => { .catch((error) => {
console.error('Error:', error) console.error('Error:', error)
}) })
.finally(() => {
this.isDeleting = false
})
} }
} }
} }
@ -785,6 +793,7 @@ export default {
const documentRef = this.documentRefs.find((e) => e.document.uuid === item.attachment_uuid) const documentRef = this.documentRefs.find((e) => e.document.uuid === item.attachment_uuid)
const confirmed = window.confirm('Are you sure you want to create new image?') const confirmed = window.confirm('Are you sure you want to create new image?')
if (confirmed) { if (confirmed) {
this.isLoading = true
const documentId = documentRef.document.id const documentId = documentRef.document.id
const apiUrl = `/api/templates/${this.template.id}/documents/${documentId}/add_new_image` const apiUrl = `/api/templates/${this.template.id}/documents/${documentId}/add_new_image`
fetch(apiUrl, { fetch(apiUrl, {
@ -811,6 +820,9 @@ export default {
.catch((error) => { .catch((error) => {
console.error('Error: ---', error) console.error('Error: ---', error)
}) })
.finally(() => {
this.isLoading = false
})
} }
} }
} }

@ -84,8 +84,15 @@
<button <button
class="btn border-base-200 bg-white text-base-content btn-xs rounded hover:text-base-100 hover:bg-base-content hover:border-base-content w-full transition-colors" class="btn border-base-200 bg-white text-base-content btn-xs rounded hover:text-base-100 hover:bg-base-content hover:border-base-content w-full transition-colors"
style="width: 24px; height: 24px" style="width: 24px; height: 24px"
:class="{ disabled: isDeleting }"
:disabled="isDeleting"
@click.stop="$emit('remove-image', item, previewImage.id)" @click.stop="$emit('remove-image', item, previewImage.id)"
> >
<IconInnerShadowTop
v-if="isDeleting"
width="22"
class="animate-spin"
/>
&times; &times;
</button> </button>
</div> </div>
@ -94,9 +101,17 @@
</div> </div>
<button <button
class="btn btn-outline w-full mt-2" class="btn btn-outline w-full mt-2"
:class="{ disabled: isLoading }"
:disabled="isLoading"
@click="$emit('add-blank-page', item)" @click="$emit('add-blank-page', item)"
> >
<span> Add blank page </span> <IconInnerShadowTop
v-if="isLoading"
width="22"
class="animate-spin"
/>
<span v-if="isLoading"> Add blank page </span>
<span v-else>Add blank page</span>
</button> </button>
<div class="flex pb-2 pt-1.5"> <div class="flex pb-2 pt-1.5">
@ -115,12 +130,14 @@
import Contenteditable from './contenteditable' import Contenteditable from './contenteditable'
import Upload from './upload' import Upload from './upload'
import ReplaceButton from './replace' import ReplaceButton from './replace'
import { IconInnerShadowTop } from '@tabler/icons-vue'
export default { export default {
name: 'DocumentPreview', name: 'DocumentPreview',
components: { components: {
Contenteditable, Contenteditable,
ReplaceButton ReplaceButton,
IconInnerShadowTop
}, },
props: { props: {
item: { item: {
@ -154,6 +171,16 @@ export default {
type: Boolean, type: Boolean,
required: false, required: false,
default: true default: true
},
isLoading: {
type: Boolean,
required: true,
default: false
},
isDeleting: {
type: Boolean,
required: true,
default: false
} }
}, },
emits: ['scroll-to', 'change', 'remove', 'up', 'down', 'replace', 'remove-image', 'add-blank-page'], emits: ['scroll-to', 'change', 'remove', 'up', 'down', 'replace', 'remove-image', 'add-blank-page'],

Loading…
Cancel
Save