This commit is contained in:
pbao9
2026-02-07 18:27:18 +07:00
parent e9f2218030
commit cfb6729349
8 changed files with 618 additions and 651 deletions
@@ -58,7 +58,6 @@
</div> </div>
</div> </div>
@yield('content') @yield('content')
<div id="fui-toast"></div>
</div> </div>
@include('administrator.layout.partials.footer') @include('administrator.layout.partials.footer')
</div> </div>
@@ -1,60 +1,74 @@
<!-- Toast Dependencies --> <!-- Notyf Dependencies -->
<link rel="stylesheet" type="text/css" href="{{ asset('lib/fui-toast/fuiToast.min.css') }}"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/notyf@3/notyf.min.css">
<script type="text/javascript" src="{{ asset('lib/fui-toast/fuiToast.min.js') }}"></script> <script src="https://cdn.jsdelivr.net/npm/notyf@3/notyf.min.js"></script>
<!-- Toast Logic --> <!-- Toast Logic -->
<script type="text/javascript"> <script type="text/javascript">
// Function to safely show toast notifications var notyf;
function showToast(message, type = 'error', title = '') {
// Check if FuiToast is available and container exists
if (typeof FuiToast !== 'undefined' && document.getElementById('fui-toast')) {
try {
if (type === 'success') {
FuiToast.success(message, title || 'Success!');
} else {
FuiToast.error(message, title || 'Error!');
}
return true;
} catch (e) {
console.error('FuiToast failed:', e);
return false;
}
}
return false;
}
// Function to show alerts with fallback // Initialize Notyf
function showAlerts() { document.addEventListener('DOMContentLoaded', function () {
@if ($errors->any() || session()->has('success')) notyf = new Notyf({
@foreach ($errors->all() as $item) duration: 5000,
if (!showToast('{{ addslashes($item) }}', 'error', 'Opp!')) { position: {
alert('{{ addslashes($item) }}'); x: 'right',
y: 'top',
},
types: [
{
type: 'success',
background: '#10b981',
dismissible: true
},
{
type: 'error',
background: '#ef4444',
dismissible: true
} }
@endforeach ]
@if (session()->has('success'))
if (!showToast('{{ addslashes(session()->get('success')) }}', 'success', 'Success!')) {
alert('{{ addslashes(session()->get('success')) }}');
}
@endif
@endif
}
// Wait for all scripts to load and DOM to be ready
document.addEventListener('DOMContentLoaded', function() {
// Initialize FuiToast configuration
if (typeof FuiToast !== 'undefined' && FuiToast.config) {
try {
FuiToast.config({
position: "top-center",
}); });
} catch (e) {
console.warn('FuiToast config failed:', e);
}
}
// Add a small delay to ensure everything is fully initialized // Show alerts from session
setTimeout(function() { setTimeout(function () {
showAlerts(); showAlerts();
}, 100); }, 100);
}); });
// Function to safely show toast notifications
function showToast(message, type = 'error', title = '') {
if (!notyf) {
console.warn('Notyf not initialized yet');
return false;
}
try {
if (type === 'success') {
notyf.success(message);
} else {
notyf.error(message);
}
return true;
} catch (e) {
console.error('Notyf failed:', e);
return false;
}
}
// Function to show alerts from Laravel session
function showAlerts() {
@if ($errors->any() || session()->has('success'))
@foreach ($errors->all() as $item)
showToast('{{ addslashes($item) }}', 'error');
@endforeach
@if (session()->has('success'))
showToast('{{ addslashes(session()->get('success')) }}', 'success');
@endif
@endif
}
// Compatibility layer with old FuiToast calls
window.FuiToast = {
success: function (message) { return showToast(message, 'success'); },
error: function (message) { return showToast(message, 'error'); }
};
</script> </script>
@@ -1,7 +1,7 @@
<div class="d-flex gap-2"> <div class="d-flex gap-2">
<x-button-crm type="button" variant="outline-primary" size="sm" route="products.group.edit" :params="['id' => $row->id]" icon="pencil" /> <x-button-crm type="button" variant="outline-primary" size="sm" route="products.group.edit" :params="['id' => $row->id]" icon="pencil" />
<x-button-crm type="button" variant="outline-danger" size="sm" icon="trash" <x-button-crm type="button" variant="outline-danger" size="sm" icon="trash"
data-micromodal-trigger="deleteModal-{{ $row->id }}" /> data-bs-toggle="modal" data-bs-target="#deleteModal-{{ $row->id }}" />
</div> </div>
@include('administrator.pages.product.categories.datatable.modal', [ @include('administrator.pages.product.categories.datatable.modal', [
@@ -1,7 +1,7 @@
<div class="d-flex gap-2"> <div class="d-flex gap-2">
<x-button-crm type="button" variant="outline-success" size="sm" route="products.group.restore" :params="['id' => $row->id]" icon="rotate-ccw" /> <x-button-crm type="button" variant="outline-success" size="sm" route="products.group.restore" :params="['id' => $row->id]" icon="rotate-ccw" />
<x-button-crm type="button" variant="outline-danger" size="sm" icon="trash-2" <x-button-crm type="button" variant="outline-danger" size="sm" icon="trash-2"
data-micromodal-trigger="forceDeleteModal-{{ $row->id }}" /> data-bs-toggle="modal" data-bs-target="#forceDeleteModal-{{ $row->id }}" />
</div> </div>
@include('administrator.pages.product.categories.datatable.modal', [ @include('administrator.pages.product.categories.datatable.modal', [
@@ -1,33 +1,36 @@
<!-- Delete Confirmation Modal --> <!-- Delete Confirmation Modal -->
<div class="modal micromodal-slide" id="{{ $modalId ?? 'deleteModal' }}" aria-hidden="true"> <div class="modal fade" id="{{ $modalId ?? 'deleteModal' }}" tabindex="-1"
<div class="modal__overlay" tabindex="-1" data-micromodal-close> aria-labelledby="deleteModalLabel-{{ $modalId ?? 'deleteModal' }}" aria-hidden="true">
<div class="modal__container modal--sm" role="dialog" aria-modal="true" aria-labelledby="deleteModalLabel-{{ $modalId ?? 'deleteModal' }}"> <div class="modal-dialog modal-dialog-centered modal-sm">
<header class="modal__header bg-primary text-white"> <div class="modal-content shadow-lg border-0">
<h6 class="modal__title" id="deleteModalLabel-{{ $modalId ?? 'deleteModal' }}"> <div class="modal-header bg-danger text-white py-2">
<i data-lucide="trash-2" class="w-15px h-15px me-2"></i> <h6 class="modal-title d-flex align-items-center" id="deleteModalLabel-{{ $modalId ?? 'deleteModal' }}">
Confirm Delete <i data-lucide="trash-2" class="me-2" style="width: 16px; height: 16px;"></i>
Xác nhận xóa
</h6> </h6>
<button class="modal__close" aria-label="Close modal" data-micromodal-close> <button type="button" class="btn-close btn-close-white shadow-none" data-bs-dismiss="modal" aria-label="Close"></button>
<i data-lucide="x"></i>
</button>
</header>
<main class="modal__content">
<div class="text-center">
<i data-lucide="alert-triangle" class="text-warning mb-3" style="width: 48px; height: 48px;"></i>
<h6 class="mb-2">Are you sure?</h6>
<p class="text-muted small mb-1">Delete {{ $itemLabel }}:</p>
<p class="fw-bold mb-2">{{ $itemName ?? '' }}</p>
<p class="text-danger small mb-0">This action cannot be undone!</p>
</div> </div>
</main> <div class="modal-body py-4">
<footer class="modal__footer"> <div class="text-center">
<x-button-crm type="button" variant="secondary" size="sm" icon="x" data-micromodal-close>Cancel</x-button-crm> <div class="mb-3">
<form action="{{ route($deleteRoute, ['id' => $itemId ?? 0]) }}" method="POST" class="d-inline"> <i data-lucide="alert-triangle" class="text-warning" style="width: 54px; height: 54px;"></i>
</div>
<h6 class="fw-bold mb-2">Bạn có chắc chắn không?</h6>
<p class="text-muted small mb-1">Xóa {{ $itemLabel }}:</p>
<p class="fw-bold mb-3 text-dark">{{ $itemName ?? '' }}</p>
<div class="px-3 py-2 bg-danger-subtle rounded-3">
<p class="text-danger small mb-0 fw-medium">Hành động này không thể hoàn tác!</p>
</div>
</div>
</div>
<div class="modal-footer bg-light border-0 py-2 d-flex justify-content-center gap-2">
<x-button-c-r-m type="button" variant="secondary" size="sm" icon="x" data-bs-dismiss="modal">Hủy bỏ</x-button-c-r-m>
<form action="{{ route($deleteRoute, ['id' => $itemId ?? 0]) }}" method="POST" class="d-inline m-0">
@csrf @csrf
@method('DELETE') @method('DELETE')
<x-button-crm type="submit" variant="danger" size="sm" icon="trash-2">Confirm Delete</x-button-crm> <x-button-c-r-m type="submit" variant="danger" size="sm" icon="trash-2">Xác nhận xóa</x-button-c-r-m>
</form> </form>
</footer> </div>
</div> </div>
</div> </div>
</div> </div>
@@ -64,36 +64,8 @@ $tabs = [
@push('custom-scripts') @push('custom-scripts')
<script> <script>
document.addEventListener('DOMContentLoaded', function () { document.addEventListener('DOMContentLoaded', function () {
// Function to initialize MicroModal // DataTable is already initialized in components/datatable
function initMicroModal() { // If we need custom behavior here, we can add it.
if (typeof MicroModal !== 'undefined') {
MicroModal.init({
onShow: modal => console.info(`${modal.id} is shown`),
onClose: modal => console.info(`${modal.id} is hidden`),
openTrigger: 'data-micromodal-trigger',
closeTrigger: 'data-micromodal-close',
disableScroll: true,
disableFocus: false,
awaitOpenAnimation: false,
awaitCloseAnimation: false,
debugMode: true
});
}
}
// Initialize on page load
initMicroModal();
// Re-initialize after DataTable draws (when action column renders)
$('#productTable').on('draw.dt', function() {
setTimeout(function() {
initMicroModal();
// Re-initialize Lucide icons for modal content
if (typeof lucide !== 'undefined') {
lucide.createIcons();
}
}, 100);
});
}); });
</script> </script>
@endpush @endpush
@@ -7,17 +7,17 @@
@section('breadcrumb') @section('breadcrumb')
@php @php
$breadcrumbItems = [ $breadcrumbItems = [
['label' => 'Product'], ['label' => 'Product'],
['label' => 'Product Group', 'route' => route('products.group.index')], ['label' => 'Product Group', 'route' => route('products.group.index')],
['label' => 'Trash List', 'active' => true] ['label' => 'Trash List', 'active' => true]
]; ];
@endphp @endphp
<x-admin-breadcrumb :items="$breadcrumbItems" /> <x-admin-breadcrumb :items="$breadcrumbItems" />
@endsection @endsection
@section('tab') @section('tab')
@php @php
$tabs = [ $tabs = [
[ [
'label' => 'Product', 'label' => 'Product',
'route' => 'products.index', 'route' => 'products.index',
@@ -28,7 +28,7 @@
'route' => 'products.group.index', 'route' => 'products.group.index',
'icon' => 'server', 'icon' => 'server',
], ],
]; ];
@endphp @endphp
<x-admin-tab :items="$tabs" /> <x-admin-tab :items="$tabs" />
@endsection @endsection
@@ -63,36 +63,7 @@
@push('custom-scripts') @push('custom-scripts')
<script> <script>
document.addEventListener('DOMContentLoaded', function () { document.addEventListener('DOMContentLoaded', function () {
// Function to initialize MicroModal // DataTable is already initialized in components/datatable
function initMicroModal() {
if (typeof MicroModal !== 'undefined') {
MicroModal.init({
onShow: modal => console.info(`${modal.id} is shown`),
onClose: modal => console.info(`${modal.id} is hidden`),
openTrigger: 'data-micromodal-trigger',
closeTrigger: 'data-micromodal-close',
disableScroll: true,
disableFocus: false,
awaitOpenAnimation: false,
awaitCloseAnimation: false,
debugMode: true
});
}
}
// Initialize on page load
initMicroModal();
// Re-initialize after DataTable draws (when action column renders)
$('#productTable').on('draw.dt', function() {
setTimeout(function() {
initMicroModal();
// Re-initialize Lucide icons for modal content
if (typeof lucide !== 'undefined') {
lucide.createIcons();
}
}, 100);
});
}); });
</script> </script>
@endpush @endpush
+58 -50
View File
@@ -1,7 +1,8 @@
@props(['id', 'columns', 'ajax', 'bulkDeleteUrl' => null]) @props(['id', 'columns', 'ajax', 'bulkDeleteUrl' => null])
@php @php
$dtColumns = collect($columns)->map(function ($c) { $dtColumns = collect($columns)
->map(function ($c) {
return [ return [
'data' => $c['key'], 'data' => $c['key'],
'name' => $c['key'], 'name' => $c['key'],
@@ -9,19 +10,20 @@ $dtColumns = collect($columns)->map(function ($c) {
'searchable' => $c['searchable'] ?? true, 'searchable' => $c['searchable'] ?? true,
'className' => $c['className'] ?? '', 'className' => $c['className'] ?? '',
]; ];
})->values(); })
->values();
@endphp @endphp
@if($bulkDeleteUrl) @if ($bulkDeleteUrl)
<div class="d-flex justify-content-start mb-3 align-items-center" id="{{ $id }}-bulk-actions" <div class="d-flex justify-content-start align-items-center mb-3" id="{{ $id }}-bulk-actions"
style="display: none !important;"> style="display: none !important;">
<div class="bg-danger-subtle text-danger px-4 py-2 rounded-3 d-flex align-items-center gap-3"> <div class="bg-danger-subtle text-danger rounded-3 d-flex align-items-center gap-3 px-4 py-2">
<div class="d-flex align-items-center gap-2"> <div class="d-flex align-items-center gap-2">
<i data-lucide="alert-circle" width="16" height="16"></i> <i data-lucide="alert-circle" width="16" height="16"></i>
<span class="fw-medium"><span id="{{ $id }}-selected-count">0</span> items selected</span> <span class="fw-medium"><span id="{{ $id }}-selected-count">0</span> items selected</span>
</div> </div>
<div class="vr bg-danger opacity-25"></div> <div class="vr bg-danger opacity-25"></div>
<x-button-c-r-m type="button" variant="danger" size="sm" icon="trash-2" id="{{ $id }}-bulk-delete-opener-btn" <x-button-c-r-m type="button" variant="danger" size="sm" icon="trash-2"
class="shadow-sm"> id="{{ $id }}-bulk-delete-opener-btn" class="shadow-sm">
Delete Selected Delete Selected
</x-button-c-r-m> </x-button-c-r-m>
</div> </div>
@@ -38,9 +40,10 @@ $dtColumns = collect($columns)->map(function ($c) {
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<p>Are you sure you want to delete <span id="{{ $id }}-bulk-delete-count-display" class="fw-bold"></span> <p>Are you sure you want to delete <span id="{{ $id }}-bulk-delete-count-display"
class="fw-bold"></span>
selected items?</p> selected items?</p>
<p class="text-danger mt-2 mb-0">This action cannot be undone.</p> <p class="text-danger mb-0 mt-2">This action cannot be undone.</p>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<x-button-c-r-m type="button" variant="danger" id="{{ $id }}-confirm-bulk-delete-btn"> <x-button-c-r-m type="button" variant="danger" id="{{ $id }}-confirm-bulk-delete-btn">
@@ -55,34 +58,34 @@ $dtColumns = collect($columns)->map(function ($c) {
</div> </div>
</div> </div>
@endif @endif
<div class="data-table-wrapper rounded-3 overflow-hidden border border-light position-relative"> <div class="data-table-wrapper rounded-3 border-light position-relative overflow-hidden border">
{{-- Loading Process Indicator --}} {{-- Loading Process Indicator --}}
<div class="loading-process" id="{{ $id }}-loading" style="display: none;"> <div class="loading-process" id="{{ $id }}-loading" style="display: none;">
<div class="loading-bar"></div> <div class="loading-bar"></div>
<div class="loading-overlay"></div> <div class="loading-overlay"></div>
</div> </div>
<table id="{{ $id }}" class="table table-hover align-middle mb-0 bg-white" <table id="{{ $id }}" class="table-hover mb-0 table bg-white align-middle"
style="width:100%; border-collapse: separate; border-spacing: 0;"> style="width:100%; border-collapse: separate; border-spacing: 0;">
<thead class="bg-light"> <thead class="bg-light">
<tr> <tr>
@foreach($columns as $col) @foreach ($columns as $col)
<th <th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 border-bottom position-relative py-3 ps-3"
class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 ps-3 py-3 border-bottom position-relative"
style="font-size: 0.75rem; letter-spacing: 0.5px;"> style="font-size: 0.75rem; letter-spacing: 0.5px;">
<div <div
class="d-flex align-items-center {{ $col['key'] === 'checkbox' ? 'justify-content-center' : 'justify-content-between' }}"> class="d-flex align-items-center {{ $col['key'] === 'checkbox' ? 'justify-content-center' : 'justify-content-between' }}">
<span> <span>
@if($col['key'] === 'checkbox') @if ($col['key'] === 'checkbox')
{!! $col['label'] !!} {!! $col['label'] !!}
@else @else
{{ $col['label'] }} {{ $col['label'] }}
@endif @endif
</span> </span>
@if($col['key'] !== 'checkbox' && ($col['orderable'] ?? true)) @if ($col['key'] !== 'checkbox' && ($col['orderable'] ?? true))
<div class="sort-icons d-flex flex-column ms-2"> <div class="sort-icons d-flex flex-column ms-2">
<i data-lucide="arrow-up" class="sort-icon-asc" width="10" height="10"></i> <i data-lucide="arrow-up" class="sort-icon-asc" width="10" height="10"></i>
<i data-lucide="arrow-down" class="sort-icon-desc" width="10" height="10" style="margin-top: -2px;"></i> <i data-lucide="arrow-down" class="sort-icon-desc" width="10" height="10"
style="margin-top: -2px;"></i>
</div> </div>
@endif @endif
</div> </div>
@@ -90,16 +93,17 @@ $dtColumns = collect($columns)->map(function ($c) {
@endforeach @endforeach
</tr> </tr>
<tr class="filter-row bg-light"> <tr class="filter-row bg-light">
@foreach($columns as $col) @foreach ($columns as $col)
<th class="p-2 border-bottom"> <th class="border-bottom p-2">
@if(($col['searchable'] ?? true)) @if ($col['searchable'] ?? true)
<div class="input-group input-group-sm"> <div class="input-group input-group-sm">
<span class="input-group-text bg-white border-end-0 ps-2 pe-2 text-muted border-light"> <span class="input-group-text border-end-0 text-muted border-light bg-white pe-2 ps-2">
<i data-lucide="search" style="font-size: 0.75rem;"></i> <i data-lucide="search" style="font-size: 0.75rem;"></i>
</span> </span>
<input type="text" <input type="text"
class="form-control form-control-sm border-start-0 ps-0 column-search shadow-none border-light bg-white" class="form-control form-control-sm border-start-0 column-search border-light bg-white ps-0 shadow-none"
placeholder="Filter..." data-column="{{ $loop->index }}" style="font-size: 0.8125rem;"> placeholder="Filter..." data-column="{{ $loop->index }}"
style="font-size: 0.8125rem;">
</div> </div>
@endif @endif
</th> </th>
@@ -110,10 +114,10 @@ $dtColumns = collect($columns)->map(function ($c) {
{{-- DataTables will populate this --}} {{-- DataTables will populate this --}}
</tbody> </tbody>
</table> </table>
</div> </div>
@push('custom-scripts') @push('custom-scripts')
<script> <script>
document.addEventListener('DOMContentLoaded', function () { document.addEventListener('DOMContentLoaded', function() {
$.fn.DataTable.ext.pager.numbers_length = 7; $.fn.DataTable.ext.pager.numbers_length = 7;
var table = $('#{{ $id }}').DataTable({ var table = $('#{{ $id }}').DataTable({
@@ -142,7 +146,7 @@ $dtColumns = collect($columns)->map(function ($c) {
}, },
dom: "<'row p-3'<'col-sm-12'tr>>" + dom: "<'row p-3'<'col-sm-12'tr>>" +
"<'row px-3 pb-3 pt-1 align-items-center'<'col-sm-12 col-md-5 text-muted small'i><'col-sm-12 col-md-7 d-flex align-items-center justify-content-end gap-2'lp>>", "<'row px-3 pb-3 pt-1 align-items-center'<'col-sm-12 col-md-5 text-muted small'i><'col-sm-12 col-md-7 d-flex align-items-center justify-content-end gap-2'lp>>",
initComplete: function () { initComplete: function() {
// Initialize select2 with custom styling // Initialize select2 with custom styling
$('.dataTables_length select').select2({ $('.dataTables_length select').select2({
minimumResultsForSearch: Infinity, minimumResultsForSearch: Infinity,
@@ -153,14 +157,14 @@ $dtColumns = collect($columns)->map(function ($c) {
// Debounced search for column inputs (ERP Standard: Reduce server load) // Debounced search for column inputs (ERP Standard: Reduce server load)
let searchTimeouts = {}; let searchTimeouts = {};
this.api().columns().every(function () { this.api().columns().every(function() {
var that = this; var that = this;
$('input', this.header()).on('keyup change clear', function () { $('input', this.header()).on('keyup change clear', function() {
const colIdx = that.index(); const colIdx = that.index();
const value = this.value; const value = this.value;
clearTimeout(searchTimeouts[colIdx]); clearTimeout(searchTimeouts[colIdx]);
searchTimeouts[colIdx] = setTimeout(function () { searchTimeouts[colIdx] = setTimeout(function() {
if (that.search() !== value) { if (that.search() !== value) {
that.search(value).draw(); that.search(value).draw();
} }
@@ -168,7 +172,7 @@ $dtColumns = collect($columns)->map(function ($c) {
}); });
}); });
}, },
drawCallback: function () { drawCallback: function() {
// Re-initialize Select2 on draw (if lost) // Re-initialize Select2 on draw (if lost)
if ($('.dataTables_length select').data('select2')) { if ($('.dataTables_length select').data('select2')) {
$('.dataTables_length select').select2('destroy'); $('.dataTables_length select').select2('destroy');
@@ -179,7 +183,7 @@ $dtColumns = collect($columns)->map(function ($c) {
}); });
// Re-initialize icons with slight delay to ensuring DOM is ready // Re-initialize icons with slight delay to ensuring DOM is ready
setTimeout(function () { setTimeout(function() {
if (window.lucide) { if (window.lucide) {
lucide.createIcons(); lucide.createIcons();
} }
@@ -188,7 +192,7 @@ $dtColumns = collect($columns)->map(function ($c) {
}); });
// ERP Standard: Double click row to edit // ERP Standard: Double click row to edit
$('#{{ $id }} tbody').on('dblclick', 'tr', function () { $('#{{ $id }} tbody').on('dblclick', 'tr', function() {
// Try to find an edit link in the row // Try to find an edit link in the row
const editLink = $(this).find('a.btn-outline-primary, a[href*="edit"]').first(); const editLink = $(this).find('a.btn-outline-primary, a[href*="edit"]').first();
if (editLink.length && editLink.attr('href')) { if (editLink.length && editLink.attr('href')) {
@@ -197,7 +201,7 @@ $dtColumns = collect($columns)->map(function ($c) {
}); });
// Custom Loading Process Logic // Custom Loading Process Logic
table.on('processing.dt', function (e, settings, processing) { table.on('processing.dt', function(e, settings, processing) {
const loadingEl = $('#{{ $id }}-loading'); const loadingEl = $('#{{ $id }}-loading');
if (processing) { if (processing) {
loadingEl.fadeIn(100); loadingEl.fadeIn(100);
@@ -207,19 +211,19 @@ $dtColumns = collect($columns)->map(function ($c) {
}); });
// Prevent sorting when clicking on the input // Prevent sorting when clicking on the input
$('#{{ $id }} thead tr:eq(1) th').on('click', function (e) { $('#{{ $id }} thead tr:eq(1) th').on('click', function(e) {
e.stopPropagation(); e.stopPropagation();
}); });
// External trigger for column search (redundant but kept for manual binding if needed) // External trigger for column search (redundant but kept for manual binding if needed)
$('#{{ $id }} .column-search').on('keyup change', function () { $('#{{ $id }} .column-search').on('keyup change', function() {
var columnIndex = $(this).data('column'); var columnIndex = $(this).data('column');
table.column(columnIndex).search(this.value).draw(); table.column(columnIndex).search(this.value).draw();
}); });
}); });
@if($bulkDeleteUrl) @if ($bulkDeleteUrl)
document.addEventListener('DOMContentLoaded', function () { document.addEventListener('DOMContentLoaded', function() {
const tableId = '#{{ $id }}'; const tableId = '#{{ $id }}';
const bulkActions = $('#{{ $id }}-bulk-actions'); const bulkActions = $('#{{ $id }}-bulk-actions');
const deleteBtn = $('#{{ $id }}-bulk-delete-btn'); const deleteBtn = $('#{{ $id }}-bulk-delete-btn');
@@ -228,13 +232,13 @@ $dtColumns = collect($columns)->map(function ($c) {
let selectedIds = []; let selectedIds = [];
// Handle Master Checkbox // Handle Master Checkbox
$(document).on('change', '#dt-master-checkbox', function () { $(document).on('change', '#dt-master-checkbox', function() {
const isChecked = $(this).is(':checked'); const isChecked = $(this).is(':checked');
$('.dt-checkbox').prop('checked', isChecked).trigger('change'); $('.dt-checkbox').prop('checked', isChecked).trigger('change');
}); });
// Handle Individual Checkbox // Handle Individual Checkbox
$(document).on('change', '.dt-checkbox', function () { $(document).on('change', '.dt-checkbox', function() {
const id = $(this).val(); const id = $(this).val();
if ($(this).is(':checked')) { if ($(this).is(':checked')) {
if (!selectedIds.includes(id)) selectedIds.push(id); if (!selectedIds.includes(id)) selectedIds.push(id);
@@ -269,7 +273,7 @@ $dtColumns = collect($columns)->map(function ($c) {
}); });
// Reset selection on table draw // Reset selection on table draw
$('#{{ $id }}').on('draw.dt', function () { $('#{{ $id }}').on('draw.dt', function() {
selectedIds = []; selectedIds = [];
bulkActions.hide(); bulkActions.hide();
masterCheckbox.prop('checked', false); masterCheckbox.prop('checked', false);
@@ -284,7 +288,7 @@ $dtColumns = collect($columns)->map(function ($c) {
const countDisplay = $('#{{ $id }}-bulk-delete-count-display'); const countDisplay = $('#{{ $id }}-bulk-delete-count-display');
let bsModal = null; let bsModal = null;
openerBtn.on('click', function () { openerBtn.on('click', function() {
if (selectedIds.length === 0) return; if (selectedIds.length === 0) return;
countDisplay.text(selectedIds.length); countDisplay.text(selectedIds.length);
@@ -295,7 +299,7 @@ $dtColumns = collect($columns)->map(function ($c) {
}); });
// Handle Confirm Delete // Handle Confirm Delete
confirmBtn.on('click', function () { confirmBtn.on('click', function() {
$.ajax({ $.ajax({
url: '{{ $bulkDeleteUrl }}', url: '{{ $bulkDeleteUrl }}',
type: 'DELETE', type: 'DELETE',
@@ -303,10 +307,10 @@ $dtColumns = collect($columns)->map(function ($c) {
ids: selectedIds, ids: selectedIds,
_token: '{{ csrf_token() }}' _token: '{{ csrf_token() }}'
}, },
beforeSend: function () { beforeSend: function() {
confirmBtn.prop('disabled', true).text('Deleting...'); confirmBtn.prop('disabled', true).text('Deleting...');
}, },
success: function (response) { success: function(response) {
if (bsModal) bsModal.hide(); if (bsModal) bsModal.hide();
$('#{{ $id }}').DataTable().ajax.reload(); $('#{{ $id }}').DataTable().ajax.reload();
selectedIds = []; selectedIds = [];
@@ -314,14 +318,16 @@ $dtColumns = collect($columns)->map(function ($c) {
// Show success toast // Show success toast
if (typeof FuiToast !== 'undefined') { if (typeof FuiToast !== 'undefined') {
FuiToast.success(response.message || 'Selected items have been deleted successfully.'); FuiToast.success(response.message ||
'Selected items have been deleted successfully.');
} }
// Re-render icons after reload // Re-render icons after reload
if (window.lucide) lucide.createIcons(); if (window.lucide) lucide.createIcons();
}, },
error: function (xhr) { error: function(xhr) {
const message = xhr.responseJSON?.message || 'Something went wrong.'; const message = xhr.responseJSON?.message ||
'Something went wrong.';
if (typeof FuiToast !== 'undefined') { if (typeof FuiToast !== 'undefined') {
FuiToast.error(message); FuiToast.error(message);
} else { } else {
@@ -329,7 +335,7 @@ $dtColumns = collect($columns)->map(function ($c) {
} }
if (bsModal) bsModal.hide(); if (bsModal) bsModal.hide();
}, },
complete: function () { complete: function() {
confirmBtn.prop('disabled', false).text('Delete'); confirmBtn.prop('disabled', false).text('Delete');
} }
}); });
@@ -550,6 +556,7 @@ $dtColumns = collect($columns)->map(function ($c) {
th.sorting_asc .sort-icons { th.sorting_asc .sort-icons {
opacity: 1; opacity: 1;
} }
th.sorting_asc .sort-icon-desc { th.sorting_asc .sort-icon-desc {
display: none !important; display: none !important;
} }
@@ -557,6 +564,7 @@ $dtColumns = collect($columns)->map(function ($c) {
th.sorting_desc .sort-icons { th.sorting_desc .sort-icons {
opacity: 1; opacity: 1;
} }
th.sorting_desc .sort-icon-asc { th.sorting_desc .sort-icon-asc {
display: none !important; display: none !important;
} }
@@ -577,4 +585,4 @@ $dtColumns = collect($columns)->map(function ($c) {
/* Hide default processing */ /* Hide default processing */
} }
</style> </style>
@endpush @endpush