Merge branch 'multiToolSelectButtonsBug' of https://github.com/PedroPF1234/Stirling-PDF into multiToolSelectButtonsBug

This commit is contained in:
JoseQuintas2021 2025-04-22 23:08:00 +01:00
commit 18b1d1178a
2 changed files with 64 additions and 25 deletions

View File

@ -35,6 +35,7 @@ class PdfContainer {
this.splitAll = this.splitAll.bind(this); this.splitAll = this.splitAll.bind(this);
this.deleteSelected = this.deleteSelected.bind(this); this.deleteSelected = this.deleteSelected.bind(this);
this.toggleSelectAll = this.toggleSelectAll.bind(this); this.toggleSelectAll = this.toggleSelectAll.bind(this);
this.toggleDeselectAll = this.toggleDeselectAll.bind(this);
this.updateSelectedPagesDisplay = this.updateSelectedPagesDisplay.bind(this); this.updateSelectedPagesDisplay = this.updateSelectedPagesDisplay.bind(this);
this.toggleSelectPageVisibility = this.toggleSelectPageVisibility.bind(this); this.toggleSelectPageVisibility = this.toggleSelectPageVisibility.bind(this);
this.updatePagesFromCSV = this.updatePagesFromCSV.bind(this); this.updatePagesFromCSV = this.updatePagesFromCSV.bind(this);
@ -64,6 +65,7 @@ class PdfContainer {
window.splitAll = this.splitAll; window.splitAll = this.splitAll;
window.deleteSelected = this.deleteSelected; window.deleteSelected = this.deleteSelected;
window.toggleSelectAll = this.toggleSelectAll; window.toggleSelectAll = this.toggleSelectAll;
window.toggleDeselectAll = this.toggleDeselectAll;
window.updateSelectedPagesDisplay = this.updateSelectedPagesDisplay; window.updateSelectedPagesDisplay = this.updateSelectedPagesDisplay;
window.toggleSelectPageVisibility = this.toggleSelectPageVisibility; window.toggleSelectPageVisibility = this.toggleSelectPageVisibility;
window.updatePagesFromCSV = this.updatePagesFromCSV; window.updatePagesFromCSV = this.updatePagesFromCSV;
@ -435,31 +437,43 @@ class PdfContainer {
toggleSelectAll() { toggleSelectAll() {
const checkboxes = document.querySelectorAll('.pdf-actions_checkbox'); const checkboxes = document.querySelectorAll('.pdf-actions_checkbox');
window.selectAll = !window.selectAll; window.selectAll = true;
const selectIcon = document.getElementById('select-All-Container'); const selectIcon = document.getElementById('select-All-Container');
const deselectIcon = document.getElementById('deselect-All-Container'); const deselectIcon = document.getElementById('deselect-All-Container');
if (!window.selectAll) { this.showButton(selectIcon, false);
this.showButton(selectIcon, true); this.showButton(deselectIcon, true);
this.showButton(deselectIcon, false);
} else {
this.showButton(selectIcon, false);
this.showButton(deselectIcon, true);
}
checkboxes.forEach((checkbox) => { checkboxes.forEach((checkbox) => {
checkbox.checked = window.selectAll; checkbox.checked = true;
const pageNumber = Array.from(checkbox.parentNode.parentNode.children).indexOf(checkbox.parentNode) + 1; const pageNumber = Array.from(checkbox.parentNode.parentNode.children).indexOf(checkbox.parentNode) + 1;
if (checkbox.checked) { if (!window.selectedPages.includes(pageNumber)) {
if (!window.selectedPages.includes(pageNumber)) { window.selectedPages.push(pageNumber);
window.selectedPages.push(pageNumber); }
} });
} else {
const index = window.selectedPages.indexOf(pageNumber); this.updateSelectedPagesDisplay();
if (index !== -1) { }
window.selectedPages.splice(index, 1);
} toggleDeselectAll() {
const checkboxes = document.querySelectorAll('.pdf-actions_checkbox');
window.selectAll = false;
const selectIcon = document.getElementById('select-All-Container');
const deselectIcon = document.getElementById('deselect-All-Container');
this.showButton(selectIcon, true);
this.showButton(deselectIcon, false);
checkboxes.forEach((checkbox) => {
checkbox.checked = false;
const pageNumber = Array.from(checkbox.parentNode.parentNode.children).indexOf(checkbox.parentNode) + 1;
const index = window.selectedPages.indexOf(pageNumber);
if (index !== -1) {
window.selectedPages.splice(index, 1);
} }
}); });
@ -569,6 +583,27 @@ class PdfContainer {
// Update the input field with the formatted page list // Update the input field with the formatted page list
selectedPagesInput.value = this.formatSelectedPages(window.selectedPages); selectedPagesInput.value = this.formatSelectedPages(window.selectedPages);
const selectIcon = document.getElementById('select-All-Container');
const deselectIcon = document.getElementById('deselect-All-Container');
//Check if no pages are selected
if (window.selectedPages.length === 0) {
this.showButton(selectIcon, true);
this.showButton(deselectIcon, false);
} else {
this.showButton(deselectIcon, true);
}
//Check if all pages are selected
const allCheckboxes = document.querySelectorAll('.pdf-actions_checkbox');
const allSelected = Array.from(allCheckboxes).every((checkbox) => checkbox.checked);
if (allSelected) {
this.showButton(selectIcon, false);
this.showButton(deselectIcon, true);
} else {
this.showButton(selectIcon, true);
}
} }
parsePageRanges(ranges) { parsePageRanges(ranges) {
@ -852,18 +887,22 @@ class PdfContainer {
deleteButton.classList.toggle('hidden', !window.selectPage); deleteButton.classList.toggle('hidden', !window.selectPage);
const selectedPages = document.getElementById('selected-pages-display'); const selectedPages = document.getElementById('selected-pages-display');
selectedPages.classList.toggle('hidden', !window.selectPage); selectedPages.classList.toggle('hidden', !window.selectPage);
if(!window.selectPage) if(!window.selectPage)
{ {
this.showButton(document.getElementById('deselect-All-Container'), false); this.showButton(document.getElementById('deselect-All-Container'), false);
this.showButton(document.getElementById('select-All-Container'), false); this.showButton(document.getElementById('select-All-Container'), false);
} }
else if(window.selectAll){
this.showButton(document.getElementById('deselect-All-Container'), true);
this.showButton(document.getElementById('select-All-Container'), false);
}
else{ else{
this.showButton(document.getElementById('deselect-All-Container'), false); const allCheckboxes = document.querySelectorAll('.pdf-actions_checkbox');
this.showButton(document.getElementById('select-All-Container'), true); const allSelected = Array.from(allCheckboxes).every((checkbox) => checkbox.checked);
if (!allSelected) {
this.showButton(document.getElementById('select-All-Container'), true);
}
if (window.selectedPages.length > 0) {
this.showButton(document.getElementById('deselect-All-Container'), true);
}
} }
const exportSelected = document.getElementById('export-selected-button'); const exportSelected = document.getElementById('export-selected-button');

View File

@ -94,7 +94,7 @@
</span> </span>
</button> </button>
<button id="deselect-All-Container" th:title="#{multiTool.deselectAll}" <button id="deselect-All-Container" th:title="#{multiTool.deselectAll}"
class="btn btn-secondary enable-on-file hidden" onclick="toggleSelectAll()" disabled> class="btn btn-secondary enable-on-file hidden" onclick="toggleDeselectAll()" disabled>
<span class="material-symbols-rounded" id="deselect-icon">deselect</span> <span class="material-symbols-rounded" id="deselect-icon">deselect</span>
</button> </button>
<button id="select-All-Container" th:title="#{multiTool.selectAll}" <button id="select-All-Container" th:title="#{multiTool.selectAll}"