diff --git a/src/views/admin/components/edition/item-edition-form.vue b/src/views/admin/components/edition/item-edition-form.vue index 972d9ae83..175749110 100644 --- a/src/views/admin/components/edition/item-edition-form.vue +++ b/src/views/admin/components/edition/item-edition-form.vue @@ -1296,7 +1296,13 @@ export default { }) .then(() => { this.isLoadingAttachments = true; - this.fetchAttachments({ page: 1, attachmentsPerPage: 24, itemId: this.itemId, documentId: this.item.document }) + this.fetchAttachments({ + page: 1, + attachmentsPerPage: 24, + itemId: this.itemId, + documentId: this.item.document, + thumbnailId: this.item.thumbnail_id + }) .then(() => this.isLoadingAttachments = false) .catch(() => this.isLoadingAttachments = false); }) @@ -1335,7 +1341,13 @@ export default { .then(() => { this.isLoadingAttachments = true; - this.fetchAttachments({ page: 1, attachmentsPerPage: 24, itemId: this.itemId, documentId: this.item.document }) + this.fetchAttachments({ + page: 1, + attachmentsPerPage: 24, + itemId: this.itemId, + documentId: this.item.document, + thumbnailId: this.item.thumbnail_id + }) .then(() => this.isLoadingAttachments = false) .catch(() => this.isLoadingAttachments = false); }) @@ -1361,6 +1373,7 @@ export default { this.isLoading = true; this.form.document_type = 'attachment'; this.form.document = file.id + ''; + this.updateItemDocument({ item_id: this.itemId, document: this.form.document, document_type: this.form.document_type }) .then((item) => { this.isLoading = false; @@ -1414,10 +1427,17 @@ export default { nonce: this.item.nonces ? this.item.nonces['update-post_' + this.item.id] : null, relatedPostId: this.itemId, document: this.item.document_type == 'attachment' ? this.item.document : null, + thumbnailId: this.item.thumbnail_id ? this.item.thumbnail_id : null, onSave: () => { // Fetch current existing attachments this.isLoadingAttachments = true; - this.fetchAttachments({ page: 1, attachmentsPerPage: 24, itemId: this.itemId, documentId: this.item.document }) + this.fetchAttachments({ + page: 1, + attachmentsPerPage: 24, + itemId: this.itemId, + documentId: this.item.document, + thumbnailId: this.item.thumbnail_id + }) .then(() => this.isLoadingAttachments = false) .catch(() => this.isLoadingAttachments = false); } @@ -1523,7 +1543,12 @@ export default { this.setLastUpdated(this.item.modification_date); // Fetch current existing attachments now that item.document - this.fetchAttachments({ page: 1, attachmentsPerPage: 24, itemId: this.itemId, documentId: this.item.document }); + this.fetchAttachments({ + page: 1, + attachmentsPerPage: 24, + itemId: this.itemId, + documentId: this.item.document, + thumbnailId: this.item.thumbnail_id }); // Initializes Media Frames now that itemId and item.document exists this.initializeMediaFrames(); diff --git a/src/views/admin/components/lists/attachments-list.vue b/src/views/admin/components/lists/attachments-list.vue index 8fb8ddb53..c872204a9 100644 --- a/src/views/admin/components/lists/attachments-list.vue +++ b/src/views/admin/components/lists/attachments-list.vue @@ -165,7 +165,8 @@ page: this.attachmentsPage, attachmentsPerPage: this.attachmentsPerPage, itemId: this.item.id, - documentId: this.item.document + documentId: this.item.document, + thumbnailId: this.item.thumbnail_id }) .then((response) => { this.isLoading = false; diff --git a/src/views/admin/js/store/modules/item/actions.js b/src/views/admin/js/store/modules/item/actions.js index 648f04036..47bb293d0 100644 --- a/src/views/admin/js/store/modules/item/actions.js +++ b/src/views/admin/js/store/modules/item/actions.js @@ -250,14 +250,18 @@ export const deletePermanentlyAttachment = ( { commit }, attachmentId) => { }); }; -export const fetchAttachments = ({ commit }, { page, attachmentsPerPage, itemId, documentId }) => { +export const fetchAttachments = ({ commit }, { page, attachmentsPerPage, itemId, documentId, thumbnailId }) => { commit('cleanAttachments'); commit('setTotalAttachments', null); let endpoint = '/items/' + itemId + '/attachments?order=ASC&orderby=menu_order&perpage=' + attachmentsPerPage + '&paged=' + page; - if (documentId && !isNaN(documentId)) + if (documentId && !isNaN(documentId) && thumbnailId && !isNaN(thumbnailId)) + endpoint += '&exclude=' + documentId + ',' + thumbnailId; + else if (documentId && !isNaN(documentId)) endpoint += '&exclude=' + documentId; + else if (thumbnailId && !isNaN(thumbnailId)) + endpoint += '&exclude=' + thumbnailId; return new Promise((resolve, reject) => { axios.tainacan.get(endpoint) diff --git a/src/views/admin/js/wp-media-frames.js b/src/views/admin/js/wp-media-frames.js index bcc2404e0..6e85976bc 100644 --- a/src/views/admin/js/wp-media-frames.js +++ b/src/views/admin/js/wp-media-frames.js @@ -76,10 +76,13 @@ export default { this.frame.$el.addClass( 'tainacan-item-attachments-modal' ); this.frame.$el['tainacan-document-id'] = this.params.document; + this.frame.$el['tainacan-thumbnail-id'] = this.params.thumbnailId; wp.media.view.Attachment.Library = wp.media.view.Attachment.Library.extend({ className: function() { - return 'attachment ' + ((this.controller.$el['tainacan-document-id'] && (this.model.get('id') == this.controller.$el['tainacan-document-id'])) ? 'tainacan-document-attachment' : ''); + return 'attachment ' + + ((this.controller.$el['tainacan-document-id'] && (this.model.get('id') == this.controller.$el['tainacan-document-id'])) ? 'tainacan-document-attachment ' : ' ') + + ((this.controller.$el['tainacan-thumbnail-id'] && (this.model.get('id') == this.controller.$el['tainacan-thumbnail-id'])) ? 'tainacan-thumbnail-attachment ' : ' '); } }); diff --git a/src/views/admin/scss/_modals.scss b/src/views/admin/scss/_modals.scss index 4ad94e1d2..f8e910d53 100644 --- a/src/views/admin/scss/_modals.scss +++ b/src/views/admin/scss/_modals.scss @@ -202,7 +202,8 @@ .tainacan-header-image-modal, .tainacan-thumbnail-modal, .tainacan-item-attachments-modal { - .tainacan-document-attachment { + .tainacan-document-attachment, + .tainacan-thumbnail-attachment { display: none; visibility: hidden; }