Fix bulk actions selection and set timezone earlier

Improves bulk actions in the domains view by ensuring unique domain IDs are counted and selected, preventing double-counting from desktop and mobile checkboxes. Adds CSRF token to bulk actions forms for security. Moves timezone initialization to public/index.php to ensure it is set before any date operations, and updates base layout to reflect this change.
This commit is contained in:
Hosteroid
2025-10-11 21:22:39 +03:00
parent dcb7f685dd
commit 26ad852451
3 changed files with 44 additions and 8 deletions

View File

@@ -452,20 +452,26 @@ function updateBulkActions() {
const selectedCount = document.getElementById('selected-count');
const selectAllCheckbox = document.getElementById('select-all');
if (checkboxes.length > 0) {
// Get unique domain IDs (avoid counting both desktop and mobile checkboxes)
const uniqueIds = new Set(Array.from(checkboxes).map(cb => cb.value));
const count = uniqueIds.size;
if (count > 0) {
bulkActions.classList.remove('hidden');
bulkActions.classList.add('flex');
selectedCount.textContent = `${checkboxes.length} domain(s) selected`;
selectedCount.textContent = `${count} domain(s) selected`;
} else {
bulkActions.classList.add('hidden');
bulkActions.classList.remove('flex');
}
// Update select all checkbox state
const allCheckboxes = document.querySelectorAll('.domain-checkbox, .domain-checkbox-mobile');
// Only count desktop checkboxes to avoid double counting
const allCheckboxes = document.querySelectorAll('.domain-checkbox');
const checkedDesktopBoxes = document.querySelectorAll('.domain-checkbox:checked');
if (selectAllCheckbox) {
selectAllCheckbox.checked = allCheckboxes.length > 0 && checkboxes.length === allCheckboxes.length;
selectAllCheckbox.indeterminate = checkboxes.length > 0 && checkboxes.length < allCheckboxes.length;
selectAllCheckbox.checked = allCheckboxes.length > 0 && checkedDesktopBoxes.length === allCheckboxes.length;
selectAllCheckbox.indeterminate = checkedDesktopBoxes.length > 0 && checkedDesktopBoxes.length < allCheckboxes.length;
}
}
@@ -480,7 +486,9 @@ function clearSelection() {
function getSelectedIds() {
const checkboxes = document.querySelectorAll('.domain-checkbox:checked, .domain-checkbox-mobile:checked');
return Array.from(checkboxes).map(cb => cb.value);
// Return unique IDs only (avoid duplicates from desktop and mobile views)
const ids = Array.from(checkboxes).map(cb => cb.value);
return [...new Set(ids)];
}
function bulkRefresh() {
@@ -491,6 +499,13 @@ function bulkRefresh() {
form.method = 'POST';
form.action = '/domains/bulk-refresh';
// Add CSRF token
const csrfInput = document.createElement('input');
csrfInput.type = 'hidden';
csrfInput.name = 'csrf_token';
csrfInput.value = '<?= csrf_token() ?>';
form.appendChild(csrfInput);
ids.forEach(id => {
const input = document.createElement('input');
input.type = 'hidden';
@@ -515,6 +530,13 @@ function bulkDelete() {
form.method = 'POST';
form.action = '/domains/bulk-delete';
// Add CSRF token
const csrfInput = document.createElement('input');
csrfInput.type = 'hidden';
csrfInput.name = 'csrf_token';
csrfInput.value = '<?= csrf_token() ?>';
form.appendChild(csrfInput);
ids.forEach(id => {
const input = document.createElement('input');
input.type = 'hidden';