diff --git a/app/static/js/ResourceLists/CorpusFileList.js b/app/static/js/ResourceLists/CorpusFileList.js index 06f2f6f9..66bf3970 100644 --- a/app/static/js/ResourceLists/CorpusFileList.js +++ b/app/static/js/ResourceLists/CorpusFileList.js @@ -12,7 +12,7 @@ class CorpusFileList extends ResourceList { element.addEventListener('click', (event) => {this.onSelectionAction(event)}); }); this.isInitialized = false; - this.selectedItemIds = []; + this.selectedItemIds = new Set(); this.userId = listContainerElement.dataset.userId; this.corpusId = listContainerElement.dataset.corpusId; this.hasPermissionView = listContainerElement.dataset?.hasPermissionView == 'true' || false; @@ -35,7 +35,7 @@ class CorpusFileList extends ResourceList { @@ -80,7 +80,7 @@ class CorpusFileList extends ResourceList { @@ -158,7 +158,7 @@ class CorpusFileList extends ResourceList { window.location.reload(); }); } else { - Requests.corpora.entity.followers.entity.delete(this.corpusId, followerId); + Requests.corpora.entity.followers.entity.delete(this.corpusId, itemId); } }); modal.open(); @@ -173,13 +173,11 @@ class CorpusFileList extends ResourceList { break; } case 'select': { + if (event.target.checked) { - this.selectedItemIds.push(itemId); + this.selectedItemIds.add(itemId); } else { - let index = this.selectedItemIds.indexOf(itemId); - if (index > -1) { - this.selectedItemIds.splice(index, 1); - } + this.selectedItemIds.delete(itemId); } this.renderingItemSelection(); } @@ -195,18 +193,19 @@ class CorpusFileList extends ResourceList { let items = this.listjs.items; let selectableItems = Array.from(items) .filter(item => item.elm) - .map(item => item.elm.querySelector('input[type="checkbox"]')); + .map(item => item.elm.querySelector('.select-checkbox[type="checkbox"]')); switch (selectionAction) { case 'select-all': { - let selectedIds = Array.from(items) - .map(item => item.values().id); + let selectedIds = new Set(Array.from(items) + .map(item => item.values().id)) if (event.target.checked) { selectableItems.forEach(selectableItem => selectableItem.checked = true); this.selectedItemIds = selectedIds; } else { selectableItems.forEach(checkbox => checkbox.checked = false); - this.selectedItemIds = this.selectedItemIds.filter(id => !selectedIds.includes(id)); + this.selectedItemIds = new Set([...this.selectedItemIds].filter(id => !selectedIds.has(id))); + } this.renderingItemSelection(); break; @@ -249,9 +248,16 @@ class CorpusFileList extends ResourceList { let confirmElement = modalElement.querySelector('.action-button[data-action="confirm"]'); confirmElement.addEventListener('click', (event) => { this.selectedItemIds.forEach(selectedItemId => { - Requests.corpora.entity.files.ent.delete(this.corpusId, selectedItemId); + if (currentUserId != this.userId) { + Requests.corpora.entity.files.ent.delete(this.corpusId, selectedItemId) + .then(() => { + window.location.reload(); + }); + } else { + Requests.corpora.entity.files.ent.delete(this.corpusId, selectedItemId); + } }); - this.selectedItemIds = []; + this.selectedItemIds.clear(); this.renderingItemSelection(); }); modal.open(); @@ -265,7 +271,7 @@ class CorpusFileList extends ResourceList { downloadLink.click(); }); selectableItems.forEach(checkbox => checkbox.checked = false); - this.selectedItemIds = []; + this.selectedItemIds.clear(); this.renderingItemSelection(); break; } @@ -287,7 +293,7 @@ class CorpusFileList extends ResourceList { Object.values(selectableItems).forEach(selectableItem => { if (selectableItem.elm) { - let checkbox = selectableItem.elm.querySelector('input[type="checkbox"]'); + let checkbox = selectableItem.elm.querySelector('.select-checkbox[type="checkbox"]'); if (checkbox.checked) { selectableItem.elm.classList.add('grey', 'lighten-3'); } else { @@ -305,7 +311,7 @@ class CorpusFileList extends ResourceList { } }); // Hide item action buttons if > 0 item is selected and show selection action buttons - if (this.selectedItemIds.length > 0) { + if (this.selectedItemIds.size > 0) { selectionActionButtons.forEach(selectionActionButton => { selectionActionButton.classList.remove('hide'); });