window.refreshAdminTabContent = function (adminTab, url) { window.captureAdminTabUiState(adminTab); window.navigateDashboardContent(url); }; window.submitAdminActionWithoutReload = function (form, adminTab, successTitle) { if (!form || form.dataset.submitting === '1') { return Promise.resolve(); } form.dataset.submitting = '1'; return fetch(form.action, { method: 'POST', headers: { 'X-Requested-With': 'XMLHttpRequest', 'Accept': 'application/json' }, body: new FormData(form) }) .then(function (response) { return response.json().catch(function () { return {}; }).then(function (payload) { if (!response.ok) { throw new Error(payload.message || '{{ __('Unable to complete this action.') }}'); } return payload; }); }) .then(function (payload) { return Swal.fire({ title: successTitle || '{{ __('Deleted') }}', text: payload.message || '{{ __('Deleted successfully.') }}', icon: 'success', confirmButtonText: '{{ __('OK') }}', customClass: { confirmButton: 'btn btn-primary w-xs mt-2' }, buttonsStyling: false }); }) .then(function () { var targetUrl = new URL(@json(route('role.dashboard')), window.location.origin); targetUrl.searchParams.set('admin_tab', adminTab); window.refreshAdminTabContent(adminTab, targetUrl.toString()); }) .catch(function (error) { return Swal.fire({ title: '{{ __('Action Failed') }}', text: error && error.message ? error.message : '{{ __('Please try again.') }}', icon: 'error', confirmButtonText: '{{ __('OK') }}', customClass: { confirmButton: 'btn btn-primary w-xs mt-2' }, buttonsStyling: false }); }) .finally(function () { delete form.dataset.submitting; }); }; function getResponsiveAdminTablePageSize() { return 10; } function normalizeAdminDashboardSortText(value) { return (value || '').toString().replace(/\s+/g, ' ').trim(); } function adminDashboardSortValue(row, columnIndex) { var cell = row && row.cells ? row.cells[columnIndex] : null; if (!cell) { return ''; } var timestampSource = cell.matches('[data-timestamp]') ? cell : cell.querySelector('[data-timestamp]'); if (timestampSource && timestampSource.dataset.timestamp) { var timestamp = Number(timestampSource.dataset.timestamp); if (!Number.isNaN(timestamp)) { return timestamp; } } var checkbox = cell.querySelector('input[type="checkbox"]'); if (checkbox) { return checkbox.checked ? 1 : 0; } var text = normalizeAdminDashboardSortText(cell.textContent || ''); var numericText = text.replace(/,/g, ''); var number = Number(numericText); if (text !== '' && !Number.isNaN(number) && /^-?\d+(?:\.\d+)?$/.test(numericText)) { return number; } return text.toLowerCase(); } function compareAdminDashboardRows(rowA, rowB, columnIndex, order) { var a = adminDashboardSortValue(rowA, columnIndex); var b = adminDashboardSortValue(rowB, columnIndex); var result; if (typeof a === 'number' && typeof b === 'number') { result = a - b; } else { result = String(a).localeCompare(String(b), undefined, { numeric: true, sensitivity: 'base' }); } return order === 'desc' ? result * -1 : result; } function sortAdminDashboardRows(rows, columnIndex, order) { var sortedRows = Array.prototype.slice.call(rows || []).sort(function (rowA, rowB) { return compareAdminDashboardRows(rowA, rowB, columnIndex, order); }); var tbody = sortedRows.length > 0 ? sortedRows[0].parentNode : null; if (tbody) { sortedRows.forEach(function (row) { tbody.appendChild(row); }); } return sortedRows; } (function () {