Hides thumbnail from attachments list as well as document.

This commit is contained in:
mateuswetah 2020-11-11 13:03:48 -03:00
parent 8d8c487f45
commit e85d25f54b
5 changed files with 43 additions and 9 deletions

View File

@ -1296,7 +1296,13 @@ export default {
}) })
.then(() => { .then(() => {
this.isLoadingAttachments = true; 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) .then(() => this.isLoadingAttachments = false)
.catch(() => this.isLoadingAttachments = false); .catch(() => this.isLoadingAttachments = false);
}) })
@ -1335,7 +1341,13 @@ export default {
.then(() => { .then(() => {
this.isLoadingAttachments = true; 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) .then(() => this.isLoadingAttachments = false)
.catch(() => this.isLoadingAttachments = false); .catch(() => this.isLoadingAttachments = false);
}) })
@ -1361,6 +1373,7 @@ export default {
this.isLoading = true; this.isLoading = true;
this.form.document_type = 'attachment'; this.form.document_type = 'attachment';
this.form.document = file.id + ''; this.form.document = file.id + '';
this.updateItemDocument({ item_id: this.itemId, document: this.form.document, document_type: this.form.document_type }) this.updateItemDocument({ item_id: this.itemId, document: this.form.document, document_type: this.form.document_type })
.then((item) => { .then((item) => {
this.isLoading = false; this.isLoading = false;
@ -1414,10 +1427,17 @@ export default {
nonce: this.item.nonces ? this.item.nonces['update-post_' + this.item.id] : null, nonce: this.item.nonces ? this.item.nonces['update-post_' + this.item.id] : null,
relatedPostId: this.itemId, relatedPostId: this.itemId,
document: this.item.document_type == 'attachment' ? this.item.document : null, document: this.item.document_type == 'attachment' ? this.item.document : null,
thumbnailId: this.item.thumbnail_id ? this.item.thumbnail_id : null,
onSave: () => { onSave: () => {
// Fetch current existing attachments // Fetch current existing attachments
this.isLoadingAttachments = true; 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) .then(() => this.isLoadingAttachments = false)
.catch(() => this.isLoadingAttachments = false); .catch(() => this.isLoadingAttachments = false);
} }
@ -1523,7 +1543,12 @@ export default {
this.setLastUpdated(this.item.modification_date); this.setLastUpdated(this.item.modification_date);
// Fetch current existing attachments now that item.document // 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 // Initializes Media Frames now that itemId and item.document exists
this.initializeMediaFrames(); this.initializeMediaFrames();

View File

@ -165,7 +165,8 @@
page: this.attachmentsPage, page: this.attachmentsPage,
attachmentsPerPage: this.attachmentsPerPage, attachmentsPerPage: this.attachmentsPerPage,
itemId: this.item.id, itemId: this.item.id,
documentId: this.item.document documentId: this.item.document,
thumbnailId: this.item.thumbnail_id
}) })
.then((response) => { .then((response) => {
this.isLoading = false; this.isLoading = false;

View File

@ -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('cleanAttachments');
commit('setTotalAttachments', null); commit('setTotalAttachments', null);
let endpoint = '/items/' + itemId + '/attachments?order=ASC&orderby=menu_order&perpage=' + attachmentsPerPage + '&paged=' + page; 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; endpoint += '&exclude=' + documentId;
else if (thumbnailId && !isNaN(thumbnailId))
endpoint += '&exclude=' + thumbnailId;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.tainacan.get(endpoint) axios.tainacan.get(endpoint)

View File

@ -76,10 +76,13 @@ export default {
this.frame.$el.addClass( 'tainacan-item-attachments-modal' ); this.frame.$el.addClass( 'tainacan-item-attachments-modal' );
this.frame.$el['tainacan-document-id'] = this.params.document; 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({ wp.media.view.Attachment.Library = wp.media.view.Attachment.Library.extend({
className: function() { 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 ' : ' ');
} }
}); });

View File

@ -202,7 +202,8 @@
.tainacan-header-image-modal, .tainacan-header-image-modal,
.tainacan-thumbnail-modal, .tainacan-thumbnail-modal,
.tainacan-item-attachments-modal { .tainacan-item-attachments-modal {
.tainacan-document-attachment { .tainacan-document-attachment,
.tainacan-thumbnail-attachment {
display: none; display: none;
visibility: hidden; visibility: hidden;
} }