| 1 |
/** |
| 2 |
* MetaSync redirections — filter auto-submit and pagination tab fix. |
| 3 |
* |
| 4 |
* Extracted from views/metasync-redirection.php (Phase 5, #887). |
| 5 |
*/ |
| 6 |
document.addEventListener('DOMContentLoaded', function() { |
| 7 |
// Auto-submit filters when changed |
| 8 |
var filterSelects = document.querySelectorAll('#status-filter, #pattern-filter, #http-code-filter'); |
| 9 |
var form = document.getElementById('redirection-form'); |
| 10 |
filterSelects.forEach(function(select) { |
| 11 |
select.addEventListener('change', function() { |
| 12 |
var formAction = form.getAttribute('action') || window.location.href; |
| 13 |
var url = new URL(formAction, window.location.origin); |
| 14 |
url.searchParams.delete('paged_redir'); |
| 15 |
form.setAttribute('action', url.pathname + url.search); |
| 16 |
|
| 17 |
// Also add hidden field to ensure pagination resets |
| 18 |
var pagedInput = form.querySelector('input[name="paged_redir"]'); |
| 19 |
if (!pagedInput) { |
| 20 |
pagedInput = document.createElement('input'); |
| 21 |
pagedInput.type = 'hidden'; |
| 22 |
pagedInput.name = 'paged_redir'; |
| 23 |
form.appendChild(pagedInput); |
| 24 |
} |
| 25 |
pagedInput.value = '1'; |
| 26 |
|
| 27 |
form.submit(); |
| 28 |
}); |
| 29 |
}); |
| 30 |
|
| 31 |
// Add tab parameter to all pagination links in redirections tab |
| 32 |
function addTabToPaginationLinks() { |
| 33 |
// Find all pagination links within redirections-content |
| 34 |
var redirectionsContent = document.getElementById('redirections-content'); |
| 35 |
if (redirectionsContent) { |
| 36 |
var paginationLinks = redirectionsContent.querySelectorAll('.tablenav-pages a'); |
| 37 |
paginationLinks.forEach(function(link) { |
| 38 |
var url = new URL(link.href); |
| 39 |
url.searchParams.set('tab', 'redirections'); |
| 40 |
link.href = url.toString(); |
| 41 |
}); |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
// Run immediately and after a short delay |
| 46 |
addTabToPaginationLinks(); |
| 47 |
setTimeout(addTabToPaginationLinks, 100); |
| 48 |
setTimeout(addTabToPaginationLinks, 500); |
| 49 |
}); |
| 50 |
|