Skip to content

Commit

Permalink
Add attachment and delete attachment now live update
Browse files Browse the repository at this point in the history
  • Loading branch information
remko48 committed Aug 12, 2024
1 parent 18ca413 commit 156e756
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
32 changes: 31 additions & 1 deletion src/dialogs/attachment/DeleteAttachmentDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default {
},
data() {
return {
filterdAttachments: [],
loading: false,
succes: false,
error: false,
Expand All @@ -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() {
Expand Down
9 changes: 8 additions & 1 deletion src/modals/attachment/AddAttachmentModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 156e756

Please sign in to comment.