From 156e75678f508b2f15c5d8667c6de69e54ad5f08 Mon Sep 17 00:00:00 2001 From: Remko Date: Mon, 12 Aug 2024 11:48:05 +0200 Subject: [PATCH] Add attachment and delete attachment now live update --- .../attachment/DeleteAttachmentDialog.vue | 32 ++++++++++++++++++- src/modals/attachment/AddAttachmentModal.vue | 9 +++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/dialogs/attachment/DeleteAttachmentDialog.vue b/src/dialogs/attachment/DeleteAttachmentDialog.vue index 9d6b36b0..f85bb7cf 100644 --- a/src/dialogs/attachment/DeleteAttachmentDialog.vue +++ b/src/dialogs/attachment/DeleteAttachmentDialog.vue @@ -61,7 +61,7 @@ export default { }, data() { return { - + filterdAttachments: [], loading: false, succes: false, error: false, @@ -87,6 +87,36 @@ export default { publicationStore.getPublicationAttachments(publicationStore.publicationItem.id) // @todo update the publication item } + + this.filterdAttachments = publicationStore.publicationItem.attachments.filter((attachment) => { return parseInt(attachment) !== parseInt(publicationStore.attachmentItem.id) }) + + fetch( + `/index.php/apps/opencatalogi/api/publications/${publicationStore.publicationItem.id}`, + { + method: 'PUT', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + ...publicationStore.publicationItem, + attachments: [...this.filterdAttachments], + }), + }, + ) + .then((response) => { + this.loading = false + + // Lets refresh the publicationList + publicationStore.refreshPublicationList() + response.json().then((data) => { + publicationStore.setPublicationItem(data) + }) + }) + .catch((err) => { + this.error = err + this.loading = false + }) + // Wait for the user to read the feedback then close the model const self = this setTimeout(function() { diff --git a/src/modals/attachment/AddAttachmentModal.vue b/src/modals/attachment/AddAttachmentModal.vue index 8debc823..118f0591 100644 --- a/src/modals/attachment/AddAttachmentModal.vue +++ b/src/modals/attachment/AddAttachmentModal.vue @@ -158,8 +158,15 @@ export default { }), }, ) - .then(() => { + .then((response) => { this.loading = false + + // Lets refresh the publicationList + publicationStore.refreshPublicationList() + response.json().then((data) => { + publicationStore.setPublicationItem(data) + }) + }) .catch((err) => { this.error = err