feat: Implement addon functionality with schema updates, seeder, and administrator UI adjustments, including new favicons and a migration snapshot.

This commit is contained in:
pbao9
2026-02-13 10:07:24 +07:00
parent 64c3182b00
commit b127fa7c66
13 changed files with 4441 additions and 525 deletions
+3841
View File
File diff suppressed because it is too large Load Diff
+3 -1
View File
@@ -12,6 +12,7 @@ class Addon extends Model
protected $table = 'product_addon'; protected $table = 'product_addon';
protected $fillable = [ protected $fillable = [
'type_id',
'code', 'code',
'name', 'name',
'price', 'price',
@@ -19,6 +20,7 @@ class Addon extends Model
'max', 'max',
'step', 'step',
'prefix', 'prefix',
'status' 'status',
'sort_order'
]; ];
} }
@@ -14,6 +14,7 @@ return new class extends Migration {
{ {
Schema::create('product_addon', function (Blueprint $table) { Schema::create('product_addon', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('type_id', 50)->default('vps')->index();
$table->string('code', 50)->unique(); $table->string('code', 50)->unique();
$table->string('name', 100); $table->string('name', 100);
$table->string('prefix', 50)->nullable(); $table->string('prefix', 50)->nullable();
@@ -24,6 +25,7 @@ return new class extends Migration {
$table->enum('input_type', ['number', 'slider', 'select']) $table->enum('input_type', ['number', 'slider', 'select'])
->default('number'); ->default('number');
$table->boolean('status')->default(true); $table->boolean('status')->default(true);
$table->integer('sort_order')->default(0)->index();
$table->timestamps(); $table->timestamps();
}); });
} }
+6
View File
@@ -11,6 +11,7 @@ class AddonSeeder extends Seeder
{ {
$addons = [ $addons = [
[ [
'type_id' => 'vps',
'code' => 'cpu', 'code' => 'cpu',
'name' => 'CPU', 'name' => 'CPU',
'price' => 100000, 'price' => 100000,
@@ -19,8 +20,10 @@ class AddonSeeder extends Seeder
'step' => 1, 'step' => 1,
'prefix' => 'vCore', 'prefix' => 'vCore',
'status' => true, 'status' => true,
'sort_order' => 0,
], ],
[ [
'type_id' => 'vps',
'code' => 'ram', 'code' => 'ram',
'name' => 'RAM', 'name' => 'RAM',
'price' => 50000, 'price' => 50000,
@@ -29,8 +32,10 @@ class AddonSeeder extends Seeder
'step' => 1, 'step' => 1,
'prefix' => 'GB', 'prefix' => 'GB',
'status' => true, 'status' => true,
'sort_order' => 1,
], ],
[ [
'type_id' => 'vps',
'code' => 'disk', 'code' => 'disk',
'name' => 'SSD', 'name' => 'SSD',
'price' => 4000, 'price' => 4000,
@@ -39,6 +44,7 @@ class AddonSeeder extends Seeder
'step' => 10, 'step' => 10,
'prefix' => 'GB', 'prefix' => 'GB',
'status' => true, 'status' => true,
'sort_order' => 2,
], ],
]; ];
File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 82 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 82 KiB

@@ -30,7 +30,7 @@
<!-- CSRF Token --> <!-- CSRF Token -->
<meta name="_token" content="{{ csrf_token() }}"> <meta name="_token" content="{{ csrf_token() }}">
<link rel="shortcut icon" href="{{ asset('/favicon.ico') }}"> <link rel="shortcut icon" href="{{ asset('/images/favi.svg') }}">
<!-- plugin css --> <!-- plugin css -->
@foreach (config('assets.static.css') as $css) @foreach (config('assets.static.css') as $css)
@@ -51,7 +51,7 @@
<div class="page-wrapper"> <div class="page-wrapper">
@include('administrator.layout.partials.header') @include('administrator.layout.partials.header')
<div class="page-content"> <div class="page-content">
<div class="card mb-4 bg-white shadow-sm"> <div class="card mb-4 bg-white rounded-4 shadow-none">
<div class="card-body p-3"> <div class="card-body p-3">
@yield('breadcrumb') @yield('breadcrumb')
@yield('tab') @yield('tab')
@@ -43,16 +43,16 @@
@endsection @endsection
@section('content') @section('content')
@if(auth()->guard('admins')->user()->can("manager module vcenter")) @if(auth()->guard('admins')->user()->can("manager module vcenter"))
<div class="card card-primary card-outline"> <div class="card rounded-4 shadow-none">
<div class="card-header d-flex justify-content-end gap-2"> <div class="card-header d-flex justify-content-end gap-2">
@include("administrator.pages.block.ModuleVCenter") @include("administrator.pages.block.ModuleVCenter")
</div> </div>
<div class="card-body"> <div class="card-body p-0">
<x-datatable id="vcenterTable" ajax="{{ route('module.vcenter.datatable') }}" :columns="[ <x-datatable id="vcenterTable" ajax="{{ route('module.vcenter.datatable') }}" :columns="[
['key' => 'host', 'label' => 'Host'], ['key' => 'host', 'label' => 'Host'],
['key' => 'user', 'label' => 'User'], ['key' => 'user', 'label' => 'User'],
['key' => 'status', 'label' => 'Status'], ['key' => 'status', 'label' => 'Status'],
['key' => 'action', 'label' => 'Action', 'searchable' => false], ['key' => 'action', 'label' => 'Action', 'searchable' => false],
]" /> ]" />
</div> </div>
</div> </div>
@@ -39,7 +39,7 @@
@csrf @csrf
<div class="row"> <div class="row">
<div class="col-md-8"> <div class="col-md-8">
<div class="card card-primary card-outline"> <div class="card card-primary card-outline rounded-4 shadow-none">
<div class="card-header"> <div class="card-header">
<h5 class="card-title m-0">Basic Information</h5> <h5 class="card-title m-0">Basic Information</h5>
</div> </div>
@@ -63,7 +63,8 @@
@if(isset($categories)) @if(isset($categories))
@foreach($categories as $category) @foreach($categories as $category)
<option value="{{ $category->id }}" {{ old('parent_id') == $category->id ? 'selected' : '' }}> <option value="{{ $category->id }}" {{ old('parent_id') == $category->id ? 'selected' : '' }}>
{{ $category->name }}</option> {{ $category->name }}
</option>
@endforeach @endforeach
@endif @endif
</select> </select>
@@ -73,7 +74,7 @@
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<div class="card card-secondary card-outline"> <div class="card card-secondary card-outline shadow-none rounded-4">
<div class="card-header"> <div class="card-header">
<h5 class="card-title m-0">Classification</h5> <h5 class="card-title m-0">Classification</h5>
</div> </div>
@@ -100,9 +101,10 @@
</div> </div>
<x-fixed-action-bar> <x-fixed-action-bar>
<x-button-crm type="button" variant="secondary" size="sm" icon="arrow-left" <x-button-crm type="button" variant="outline-info" size="sm" icon="arrow-left"
route="products.group.index">Cancel</x-button-crm> route="products.group.index">Back</x-button-crm>
<x-button-crm type="submit" variant="primary" size="sm" icon="plus-circle">Create Category</x-button-crm> <x-button-crm type="submit" variant="outline-primary" size="sm" icon="plus-circle">Create
Category</x-button-crm>
</x-fixed-action-bar> </x-fixed-action-bar>
</form> </form>
@endsection @endsection
@@ -7,46 +7,46 @@
@section('breadcrumb') @section('breadcrumb')
@php @php
$breadcrumbItems = [ $breadcrumbItems = [
['label' => 'Product'], ['label' => 'Product'],
['label' => 'Product Group'], ['label' => 'Product Group'],
['label' => 'Product Group List', 'active' => true] ['label' => 'Product Group 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',
'icon' => 'server', 'icon' => 'server',
], ],
[ [
'label' => 'Product Group', 'label' => 'Product Group',
'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
@section('content') @section('content')
@if (auth()->guard('admins')->user()->can('manager product')) @if (auth()->guard('admins')->user()->can('manager product'))
<div class="card card-primary card-outline"> <div class="card rounded-4 shadow-none">
<div class="card-header d-flex justify-content-end gap-2"> <div class="card-header d-flex justify-content-end gap-2 rounded-top-4">
@include('administrator.pages.block.product.btn') @include('administrator.pages.block.product.btn')
</div> </div>
<div class="card-body"> <div class="card-body p-0">
<x-datatable id="productTable" ajax="{{ route('products.group.datatable') }}" <x-datatable id="productTable" ajax="{{ route('products.group.datatable') }}"
bulkDeleteUrl="{{ route('products.group.bulkDelete') }}" :columns="[ bulkDeleteUrl="{{ route('products.group.bulkDelete') }}" :columns="[
['key' => 'details_control', 'label' => '', 'orderable' => false, 'searchable' => false, 'className' => 'details-control text-center cursor-pointer'], ['key' => 'details_control', 'label' => '', 'orderable' => false, 'searchable' => false, 'className' => 'details-control text-center cursor-pointer'],
['key' => 'name', 'label' => 'Group'], ['key' => 'name', 'label' => 'Group'],
['key' => 'slug', 'label' => 'Slug'], ['key' => 'slug', 'label' => 'Slug'],
['key' => 'is_active', 'label' => 'Status'], ['key' => 'is_active', 'label' => 'Status'],
['key' => 'action', 'label' => 'Action', 'searchable' => false], ['key' => 'action', 'label' => 'Action', 'searchable' => false],
]" /> ]" />
</div> </div>
</div> </div>
@@ -38,8 +38,8 @@
<div class="row align-items-start"> <div class="row align-items-start">
{{-- Left Column: Basic Info & Pricing --}} {{-- Left Column: Basic Info & Pricing --}}
<div class="col-md-8"> <div class="col-md-8">
<div class="card card-primary card-outline"> <div class="card card-primary card-outline rounded-4 shadow-none">
<div class="card-header"> <div class="card-header rounded-top-4">
<h5 class="card-title m-0">Basic Information</h5> <h5 class="card-title m-0">Basic Information</h5>
</div> </div>
<div class="card-body"> <div class="card-body">
@@ -195,8 +195,8 @@
{{-- Right Column: Classification & Settings --}} {{-- Right Column: Classification & Settings --}}
<div class="col-md-4 sticky-top top-10 z-0"> <div class="col-md-4 sticky-top top-10 z-0">
<div class="card card-secondary card-outline mb-3"> <div class="card card-secondary card-outline mb-3 rounded-4 shadow-none">
<div class="card-header"> <div class="card-header rounded-top-4">
<h5 class="card-title m-0">Classification</h5> <h5 class="card-title m-0">Classification</h5>
</div> </div>
<div class="card-body"> <div class="card-body">
@@ -305,8 +305,8 @@
</div> </div>
</div> </div>
<div class="card card-secondary card-outline"> <div class="card card-secondary card-outline rounded-4 shadow-none">
<div class="card-header"> <div class="card-header rounded-top-4">
<h5 class="card-title m-0">Inventory & Limits</h5> <h5 class="card-title m-0">Inventory & Limits</h5>
</div> </div>
<div class="card-body"> <div class="card-body">
@@ -1,58 +1,58 @@
@php @php
$tag = 'button';
$href = null;
$buttonType = $type;
if ($type === 'delete' || $confirm) {
$tag = 'button'; $tag = 'button';
$buttonType = 'button'; $href = null;
$attributes = $attributes->merge([ $buttonType = $type;
'onclick' => "confirmDelete('$confirmUrl', '$confirmName')",
]);
} elseif ($route) {
$href = route($route, $params);
$tag = 'a';
} elseif ($url) {
$href = $url;
$tag = 'a';
} elseif ($attributes->has('href')) {
$href = $attributes->get('href');
$tag = 'a';
}
$variants = [ if ($type === 'delete' || $confirm) {
'primary' => 'btn-primary', $tag = 'button';
'secondary' => 'btn-secondary', $buttonType = 'button';
'outline' => 'btn-outline-primary', $attributes = $attributes->merge([
'outline-primary' => 'btn-outline-primary', 'onclick' => "confirmDelete('$confirmUrl', '$confirmName')",
'outline-secondary' => 'btn-outline-secondary', ]);
'outline-success' => 'btn-outline-success', } elseif ($route) {
'outline-danger' => 'btn-outline-danger', $href = route($route, $params);
'outline-warning' => 'btn-outline-warning', $tag = 'a';
'outline-info' => 'btn-outline-info', } elseif ($url) {
'ghost' => 'btn-light', $href = $url;
'link' => 'btn-link', $tag = 'a';
'danger' => 'btn-danger', } elseif ($attributes->has('href')) {
'destructive' => 'btn-danger', $href = $attributes->get('href');
'success' => 'btn-success', $tag = 'a';
'warning' => 'btn-warning', }
'info' => 'btn-info',
'light' => 'btn-light',
'dark' => 'btn-dark',
];
$sizes = [ $variants = [
'default' => '', 'primary' => 'btn-primary',
'sm' => 'btn-sm', 'secondary' => 'btn-secondary',
'lg' => 'btn-lg', 'outline' => 'btn-outline-primary',
'xs' => 'btn-xs', 'outline-primary' => 'btn-outline-primary',
'icon' => 'btn-icon', 'outline-secondary' => 'btn-outline-secondary',
]; 'outline-success' => 'btn-outline-success',
'outline-danger' => 'btn-outline-danger',
'outline-warning' => 'btn-outline-warning',
'outline-info' => 'btn-outline-info',
'ghost' => 'btn-light',
'link' => 'btn-link',
'danger' => 'btn-danger',
'destructive' => 'btn-danger',
'success' => 'btn-success',
'warning' => 'btn-warning',
'info' => 'btn-info',
'light' => 'btn-light',
'dark' => 'btn-dark',
];
$variantClass = $variants[$variant ?? 'primary'] ?? $variants['primary']; $sizes = [
$sizeClass = $sizes[$size ?? 'default'] ?? ''; 'default' => '',
'sm' => 'btn-sm',
'lg' => 'btn-lg',
'xs' => 'btn-xs',
'icon' => 'btn-icon',
];
$classes = "btn d-flex align-items-center {$variantClass} {$sizeClass}"; $variantClass = $variants[$variant ?? 'primary'] ?? $variants['primary'];
$sizeClass = $sizes[$size ?? 'default'] ?? '';
$classes = "btn d-flex align-items-center rounded-4 border {$variantClass} {$sizeClass}";
@endphp @endphp
@if($tag === 'a') @if($tag === 'a')
<a href="{{ $href }}" {{ $attributes->merge(['class' => $classes]) }}> <a href="{{ $href }}" {{ $attributes->merge(['class' => $classes]) }}>
+475 -430
View File
@@ -1,17 +1,17 @@
@props(['id', 'columns', 'ajax', 'bulkDeleteUrl' => null]) @props(['id', 'columns', 'ajax', 'bulkDeleteUrl' => null])
@php @php
$dtColumns = collect($columns) $dtColumns = collect($columns)
->map(function ($c) { ->map(function ($c) {
return [ return [
'data' => $c['key'], 'data' => $c['key'],
'name' => $c['key'], 'name' => $c['key'],
'orderable' => $c['orderable'] ?? true, 'orderable' => $c['orderable'] ?? true,
'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 align-items-center mb-3" id="{{ $id }}-bulk-actions" <div class="d-flex justify-content-start align-items-center mb-3" id="{{ $id }}-bulk-actions"
@@ -22,8 +22,8 @@ $dtColumns = collect($columns)
<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" <x-button-c-r-m type="button" variant="danger" size="sm" icon="trash-2" id="{{ $id }}-bulk-delete-opener-btn"
id="{{ $id }}-bulk-delete-opener-btn" class="shadow-sm"> class="shadow-sm">
Delete Selected Delete Selected
</x-button-c-r-m> </x-button-c-r-m>
</div> </div>
@@ -58,14 +58,14 @@ $dtColumns = collect($columns)
</div> </div>
</div> </div>
@endif @endif
<div class="data-table-wrapper rounded-3 border-light position-relative overflow-hidden border"> <div class="data-table-wrapper position-relative overflow-hidden shadow-none">
{{-- 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-hover mb-0 table bg-white align-middle" <table id="{{ $id }}" class="table-hover mb-0 table bg-white shadow-none 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>
@@ -102,8 +102,7 @@ $dtColumns = collect($columns)
</span> </span>
<input type="text" <input type="text"
class="form-control form-control-sm border-start-0 column-search border-light bg-white ps-0 shadow-none" 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 }}" placeholder="Filter..." data-column="{{ $loop->index }}" style="font-size: 0.8125rem;">
style="font-size: 0.8125rem;">
</div> </div>
@endif @endif
</th> </th>
@@ -116,473 +115,519 @@ $dtColumns = collect($columns)
</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({
processing: true, processing: true,
serverSide: true, serverSide: true,
ajax: '{{ $ajax }}', ajax: '{{ $ajax }}',
columns: @json($dtColumns), columns: @json($dtColumns),
orderCellsTop: true, orderCellsTop: true,
fixedHeader: false, fixedHeader: false,
stateSave: true, stateSave: true,
pagingType: 'full_numbers', pagingType: 'full_numbers',
language: { language: {
loadingRecords: '<div class="d-flex flex-column align-items-center justify-content-center py-5"><div class="spinner-border text-primary mb-3" role="status"></div><h6 class="text-secondary fw-medium">Đang tải dữ liệu...</h6></div>', loadingRecords: '<div class="d-flex flex-column align-items-center justify-content-center py-5"><div class="spinner-border text-primary mb-3" role="status"></div><h6 class="text-secondary fw-medium">Đang tải dữ liệu...</h6></div>',
searchPlaceholder: "Tìm kiếm...", searchPlaceholder: "Tìm kiếm...",
search: "", search: "",
lengthMenu: "_MENU_", lengthMenu: "_MENU_",
info: "Showing <span class='fw-bold'>_START_</span> to <span class='fw-bold'>_END_</span> of <span class='fw-bold'>_TOTAL_</span> entries", info: "Showing <span class='fw-bold'>_START_</span> to <span class='fw-bold'>_END_</span> of <span class='fw-bold'>_TOTAL_</span> entries",
paginate: { paginate: {
first: '<span class="d-flex align-items-center justify-content-center"><i data-lucide="chevrons-left" width="16" height="16"></i></span>', first: '<span class="d-flex align-items-center justify-content-center"><i data-lucide="chevrons-left" width="16" height="16"></i></span>',
last: '<span class="d-flex align-items-center justify-content-center"><i data-lucide="chevrons-right" width="16" height="16"></i></span>', last: '<span class="d-flex align-items-center justify-content-center"><i data-lucide="chevrons-right" width="16" height="16"></i></span>',
next: '<span class="d-flex align-items-center justify-content-center"><i data-lucide="chevron-right" width="16" height="16"></i></span>', next: '<span class="d-flex align-items-center justify-content-center"><i data-lucide="chevron-right" width="16" height="16"></i></span>',
previous: '<span class="d-flex align-items-center justify-content-center"><i data-lucide="chevron-left" width="16" height="16"></i></span>' previous: '<span class="d-flex align-items-center justify-content-center"><i data-lucide="chevron-left" width="16" height="16"></i></span>'
}, },
zeroRecords: '<div class="d-flex flex-column align-items-center justify-content-center py-5"><div class="text-secondary mb-3"><i data-lucide="inbox" width="28" height="28" stroke-width="1.5"></i></div><h6 class="text-secondary fw-medium">No matching records found</h6></div>', zeroRecords: '<div class="d-flex flex-column align-items-center justify-content-center py-5"><div class="text-secondary mb-3"><i data-lucide="inbox" width="28" height="28" stroke-width="1.5"></i></div><h6 class="text-secondary fw-medium">No matching records found</h6></div>',
emptyTable: '<div class="d-flex flex-column align-items-center justify-content-center py-5"><div class="text-secondary mb-3"><i data-lucide="inbox" width="28" height="28" stroke-width="1.5"></i></div><h6 class="text-secondary fw-medium">No data available</h6></div>' emptyTable: '<div class="d-flex flex-column align-items-center justify-content-center py-5"><div class="text-secondary mb-3"><i data-lucide="inbox" width="28" height="28" stroke-width="1.5"></i></div><h6 class="text-secondary fw-medium">No data available</h6></div>'
}, },
dom: "<'row p-3'<'col-sm-12'tr>>" + dom: "<'row p-0'<'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-3 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,
width: '80px', width: '80px',
dropdownCssClass: 'small-select-dropdown', dropdownCssClass: 'small-select-dropdown',
selectionCssClass: 'small-select-selection' selectionCssClass: 'small-select-selection'
}); });
// 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();
} }
}, 400); // 400ms delay }, 400); // 400ms delay
}); });
}); });
}, },
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');
} }
$('.dataTables_length select').select2({ $('.dataTables_length select').select2({
minimumResultsForSearch: Infinity, minimumResultsForSearch: Infinity,
width: '80px' width: '80px'
}); });
// 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();
} }
}, 50); }, 50);
} }
}); });
// 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')) {
window.location.href = editLink.attr('href'); window.location.href = editLink.attr('href');
} }
}); });
// 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);
} else { } else {
loadingEl.fadeOut(200); loadingEl.fadeOut(200);
} }
}); });
// 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');
const selectedCount = $('#{{ $id }}-selected-count'); const selectedCount = $('#{{ $id }}-selected-count');
const masterCheckbox = $('#dt-master-checkbox'); const masterCheckbox = $('#dt-master-checkbox');
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);
} else { } else {
selectedIds = selectedIds.filter(item => item !== id); selectedIds = selectedIds.filter(item => item !== id);
} }
// Update UI // Update UI
selectedCount.text(selectedIds.length); selectedCount.text(selectedIds.length);
if (selectedIds.length > 0) { if (selectedIds.length > 0) {
bulkActions.show(); bulkActions.show();
bulkActions.removeClass('d-none').addClass('d-flex'); bulkActions.removeClass('d-none').addClass('d-flex');
bulkActions.attr('style', ''); // Clear inline style bulkActions.attr('style', ''); // Clear inline style
} else { } else {
bulkActions.hide(); bulkActions.hide();
} }
// Update Master Checkbox state // Update Master Checkbox state
const allCheckboxes = $('.dt-checkbox').length; const allCheckboxes = $('.dt-checkbox').length;
const checkedCheckboxes = $('.dt-checkbox:checked').length; const checkedCheckboxes = $('.dt-checkbox:checked').length;
if (allCheckboxes > 0 && allCheckboxes === checkedCheckboxes) { if (allCheckboxes > 0 && allCheckboxes === checkedCheckboxes) {
masterCheckbox.prop('checked', true); masterCheckbox.prop('checked', true);
masterCheckbox.prop('indeterminate', false); masterCheckbox.prop('indeterminate', false);
} else if (checkedCheckboxes > 0) { } else if (checkedCheckboxes > 0) {
masterCheckbox.prop('checked', false); masterCheckbox.prop('checked', false);
masterCheckbox.prop('indeterminate', true); masterCheckbox.prop('indeterminate', true);
} else { } else {
masterCheckbox.prop('checked', false); masterCheckbox.prop('checked', false);
masterCheckbox.prop('indeterminate', false); masterCheckbox.prop('indeterminate', false);
} }
}); });
// 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);
masterCheckbox.prop('indeterminate', false); masterCheckbox.prop('indeterminate', false);
}); });
// Handle Bulk Delete Opener // Handle Bulk Delete Opener
const modalId = '{{ $id }}-bulk-delete-modal'; const modalId = '{{ $id }}-bulk-delete-modal';
const modalEl = document.getElementById(modalId); const modalEl = document.getElementById(modalId);
const openerBtn = $('#{{ $id }}-bulk-delete-opener-btn'); const openerBtn = $('#{{ $id }}-bulk-delete-opener-btn');
const confirmBtn = $('#{{ $id }}-confirm-bulk-delete-btn'); const confirmBtn = $('#{{ $id }}-confirm-bulk-delete-btn');
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);
if (!bsModal) { if (!bsModal) {
bsModal = new bootstrap.Modal(modalEl); bsModal = new bootstrap.Modal(modalEl);
} }
bsModal.show(); bsModal.show();
}); });
// Handle Confirm Delete // Handle Confirm Delete
confirmBtn.on('click', function() { confirmBtn.on('click', function () {
$.ajax({ $.ajax({
url: '{{ $bulkDeleteUrl }}', url: '{{ $bulkDeleteUrl }}',
type: 'DELETE', type: 'DELETE',
data: { data: {
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 = [];
bulkActions.hide(); bulkActions.hide();
// Show success toast // Show success toast
if (typeof FuiToast !== 'undefined') { if (typeof FuiToast !== 'undefined') {
FuiToast.success(response.message || FuiToast.success(response.message ||
'Selected items have been deleted successfully.'); '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 || const message = xhr.responseJSON?.message ||
'Something went wrong.'; 'Something went wrong.';
if (typeof FuiToast !== 'undefined') { if (typeof FuiToast !== 'undefined') {
FuiToast.error(message); FuiToast.error(message);
} else { } else {
alert(message); alert(message);
} }
if (bsModal) bsModal.hide(); if (bsModal) bsModal.hide();
}, },
complete: function() { complete: function () {
confirmBtn.prop('disabled', false).text('Delete'); confirmBtn.prop('disabled', false).text('Delete');
} }
}); });
}); });
}); });
@endif @endif
</script> </script>
<style> <style>
/* Custom SAAS DataTable Styles */ /* Custom SAAS DataTable Styles */
.data-table-wrapper { .data-table-wrapper {
background: #fff; background: #fff;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
overflow-y: auto; overflow-y: auto;
position: relative; position: relative;
} }
.pagination button.page-link { .pagination button.page-link {
height: 100%; height: 100%;
} }
.data-table-wrapper .table thead th { .data-table-wrapper .table thead th {
border-color: #f1f5f9 !important; border-color: #f1f5f9 !important;
font-family: 'Inter', sans-serif; font-family: 'Inter', sans-serif;
vertical-align: middle; vertical-align: middle;
position: sticky; position: sticky;
top: 0; top: 0;
z-index: 3; {{-- Lowered from 10 --}} z-index: 3;
background-color: #f8f9fa;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}
/* Sticky Action Column (ERP Standard for wide tables) */ {
.table thead th:last-child, {
.table tbody td:last-child { -- Lowered from 10 --
position: sticky; }
right: 0; }
background: #fff;
z-index: 2; {{-- Lowered from 5 --}}
border-left: 1px solid #f1f5f9;
box-shadow: -2px 0 5px rgba(0, 0, 0, 0.02);
}
.table thead th:last-child { background-color: #f8f9fa;
background: #f8f9fa; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
z-index: 4; {{-- Lowered from 11 --}} }
}
/* Sticky Checkbox Column */ /* Sticky Action Column (ERP Standard for wide tables) */
.table thead th:first-child, .table thead th:last-child,
.table tbody td:first-child { .table tbody td:last-child {
position: sticky; position: sticky;
left: 0; right: 0;
background: #fff; background: #fff;
z-index: 2; {{-- Lowered from 5 --}} z-index: 2;
border-right: 1px solid #f1f5f9;
box-shadow: 2px 0 5px rgba(0, 0, 0, 0.02);
}
.table thead th:first-child { {
background: #f8f9fa; {
z-index: 4; {{-- Lowered from 11 --}} -- Lowered from 5 --
} }
}
.table tbody tr:hover td { border-left: 1px solid #f1f5f9;
background-color: #f8fafc !important; box-shadow: -2px 0 5px rgba(0, 0, 0, 0.02);
cursor: pointer; }
}
.data-table-wrapper .table td:not(:last-child) { .table thead th:last-child {
border-right: 1px solid #f1f5f9; background: #f8f9fa;
} z-index: 4;
/* Sticky for second row (filter inputs) if present */ {
.data-table-wrapper .table thead tr:nth-child(2) th { {
top: 45px; -- Lowered from 11 --
/* Adjust based on typical header height */ }
z-index: 4; }
} }
.data-table-wrapper .input-group-text { /* Sticky Checkbox Column */
color: #94a3b8; .table thead th:first-child,
/* Slate 400 */ .table tbody td:first-child {
} position: sticky;
left: 0;
background: #fff;
z-index: 2;
.data-table-wrapper .form-control::placeholder { {
color: #cbd5e1; {
/* Slate 300 */ -- Lowered from 5 --
} }
}
.dataTables_wrapper .pagination .page-item .page-link { border-right: 1px solid #f1f5f9;
border: 1px solid transparent; box-shadow: 2px 0 5px rgba(0, 0, 0, 0.02);
border-radius: 6px; }
margin: 0 2px;
color: #64748b;
padding: 0;
font-size: 0.875rem;
transition: all 0.2s ease;
display: flex;
align-items: center;
justify-content: center;
height: 38px;
min-width: 38px;
}
.dataTables_wrapper .pagination .page-item.active .page-link { .table thead th:first-child {
background-color: #0f172a; background: #f8f9fa;
/* Slate 900 or Primary Color */ z-index: 4;
color: white;
font-weight: 500;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
border-color: #0f172a;
}
.dataTables_wrapper .pagination .page-item.disabled .page-link { {
color: #cbd5e1; {
background-color: transparent; -- Lowered from 11 --
} }
}
}
.dataTables_wrapper .pagination .page-item:not(.active) .page-link:hover { .table tbody tr:hover td {
background-color: #f8fafc; background-color: #f8fafc !important;
color: #0f172a; cursor: pointer;
border-color: #e2e8f0; }
}
/* Select2 Customization for Table Length */ .data-table-wrapper .table td:not(:last-child) {
.dataTables_length { border-right: 1px solid #f1f5f9;
margin-right: 1rem; }
}
.select2-container--default .select2-selection--single { /* Sticky for second row (filter inputs) if present */
border: 1px solid #e2e8f0; .data-table-wrapper .table thead tr:nth-child(2) th {
border-radius: 6px; top: 45px;
height: 32px; /* Adjust based on typical header height */
display: flex; z-index: 4;
align-items: center; }
outline: none;
}
.select2-container--default .select2-selection--single:focus { .data-table-wrapper .input-group-text {
border-color: #94a3b8; color: #94a3b8;
} /* Slate 400 */
}
.select2-container--default .select2-selection--single .select2-selection__arrow { .data-table-wrapper .form-control::placeholder {
height: 30px; color: #cbd5e1;
} /* Slate 300 */
}
.select2-container--default .select2-selection--single .select2-selection__rendered { .dataTables_wrapper .pagination .page-item .page-link {
color: #475569; border: 1px solid transparent;
font-size: 0.8125rem; border-radius: 6px;
padding-left: 10px; margin: 0 2px;
line-height: normal; color: #64748b;
} padding: 0;
font-size: 0.875rem;
transition: all 0.2s ease;
display: flex;
align-items: center;
justify-content: center;
height: 38px;
min-width: 38px;
}
/* Loading Process Styles */ .dataTables_wrapper .pagination .page-item.active .page-link {
.loading-process { background-color: #0f172a;
position: absolute; /* Slate 900 or Primary Color */
top: 0; color: white;
left: 0; font-weight: 500;
right: 0; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
bottom: 0; border-color: #0f172a;
z-index: 5; {{-- Lowered from 1000 --}} }
pointer-events: none;
}
.loading-bar { .dataTables_wrapper .pagination .page-item.disabled .page-link {
position: absolute; color: #cbd5e1;
top: 0; background-color: transparent;
left: 0; }
height: 3px;
width: 100%;
background: #f1f5f9;
overflow: hidden;
z-index: 6; {{-- Lowered from 1001 --}}
}
.loading-bar::after { .dataTables_wrapper .pagination .page-item:not(.active) .page-link:hover {
content: ''; background-color: #f8fafc;
position: absolute; color: #0f172a;
top: 0; border-color: #e2e8f0;
left: 0; }
height: 100%;
width: 50%;
background: linear-gradient(90deg, transparent, #0f172a, transparent);
animation: loading-process-info 1.5s infinite linear;
}
.loading-overlay { /* Select2 Customization for Table Length */
position: absolute; .dataTables_length {
top: 0; margin-right: 1rem;
left: 0; }
width: 100%;
height: 100%;
background: rgba(255, 255, 255, 0.5);
backdrop-filter: blur(1px);
}
@keyframes loading-process-info { .select2-container--default .select2-selection--single {
0% { border: 1px solid #e2e8f0;
transform: translateX(-100%); border-radius: 6px;
} height: 32px;
display: flex;
align-items: center;
outline: none;
}
100% { .select2-container--default .select2-selection--single:focus {
transform: translateX(200%); border-color: #94a3b8;
} }
}
/* Custom Sort Icons Styles */ .select2-container--default .select2-selection--single .select2-selection__arrow {
.sort-icons { height: 30px;
opacity: 0.15; }
transition: opacity 0.2s;
}
th:hover .sort-icons { .select2-container--default .select2-selection--single .select2-selection__rendered {
opacity: 0.5; color: #475569;
} font-size: 0.8125rem;
padding-left: 10px;
line-height: normal;
}
th.sorting_asc .sort-icons { /* Loading Process Styles */
opacity: 1; .loading-process {
} position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 5;
th.sorting_asc .sort-icon-desc { {
display: none !important; {
} -- Lowered from 1000 --
}
}
th.sorting_desc .sort-icons { pointer-events: none;
opacity: 1; }
}
th.sorting_desc .sort-icon-asc { .loading-bar {
display: none !important; position: absolute;
} top: 0;
left: 0;
height: 3px;
width: 100%;
background: #f1f5f9;
overflow: hidden;
z-index: 6;
/* Hide default DataTables icons */ {
table.dataTable thead .sorting:before, {
table.dataTable thead .sorting:after, -- Lowered from 1001 --
table.dataTable thead .sorting_asc:before, }
table.dataTable thead .sorting_asc:after, }
table.dataTable thead .sorting_desc:before, }
table.dataTable thead .sorting_desc:after {
display: none !important;
}
/* Processing Indicator with improved look - Centered */ .loading-bar::after {
div.dataTables_processing { content: '';
display: none !important; position: absolute;
/* Hide default processing */ top: 0;
} left: 0;
</style> height: 100%;
width: 50%;
background: linear-gradient(90deg, transparent, #0f172a, transparent);
animation: loading-process-info 1.5s infinite linear;
}
.loading-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(255, 255, 255, 0.5);
backdrop-filter: blur(1px);
}
@keyframes loading-process-info {
0% {
transform: translateX(-100%);
}
100% {
transform: translateX(200%);
}
}
/* Custom Sort Icons Styles */
.sort-icons {
opacity: 0.15;
transition: opacity 0.2s;
}
th:hover .sort-icons {
opacity: 0.5;
}
th.sorting_asc .sort-icons {
opacity: 1;
}
th.sorting_asc .sort-icon-desc {
display: none !important;
}
th.sorting_desc .sort-icons {
opacity: 1;
}
th.sorting_desc .sort-icon-asc {
display: none !important;
}
/* Hide default DataTables icons */
table.dataTable thead .sorting:before,
table.dataTable thead .sorting:after,
table.dataTable thead .sorting_asc:before,
table.dataTable thead .sorting_asc:after,
table.dataTable thead .sorting_desc:before,
table.dataTable thead .sorting_desc:after {
display: none !important;
}
/* Processing Indicator with improved look - Centered */
div.dataTables_processing {
display: none !important;
/* Hide default processing */
}
</style>
@endpush @endpush