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>
@yield('content')
<div id="fui-toast"></div>
</div>
@include('administrator.layout.partials.footer')
</div>
@@ -1,60 +1,74 @@
<!-- Toast Dependencies -->
<link rel="stylesheet" type="text/css" href="{{ asset('lib/fui-toast/fuiToast.min.css') }}">
<script type="text/javascript" src="{{ asset('lib/fui-toast/fuiToast.min.js') }}"></script>
<!-- Notyf Dependencies -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/notyf@3/notyf.min.css">
<script src="https://cdn.jsdelivr.net/npm/notyf@3/notyf.min.js"></script>
<!-- Toast Logic -->
<script type="text/javascript">
var notyf;
// Initialize Notyf
document.addEventListener('DOMContentLoaded', function () {
notyf = new Notyf({
duration: 5000,
position: {
x: 'right',
y: 'top',
},
types: [
{
type: 'success',
background: '#10b981',
dismissible: true
},
{
type: 'error',
background: '#ef4444',
dismissible: true
}
]
});
// Show alerts from session
setTimeout(function () {
showAlerts();
}, 100);
});
// Function to safely show toast notifications
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;
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;
}
return false;
}
// Function to show alerts with fallback
// Function to show alerts from Laravel session
function showAlerts() {
@if ($errors->any() || session()->has('success'))
@foreach ($errors->all() as $item)
if (!showToast('{{ addslashes($item) }}', 'error', 'Opp!')) {
alert('{{ addslashes($item) }}');
}
showToast('{{ addslashes($item) }}', 'error');
@endforeach
@if (session()->has('success'))
if (!showToast('{{ addslashes(session()->get('success')) }}', 'success', 'Success!')) {
alert('{{ addslashes(session()->get('success')) }}');
}
showToast('{{ addslashes(session()->get('success')) }}', '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
setTimeout(function() {
showAlerts();
}, 100);
});
</script>
// Compatibility layer with old FuiToast calls
window.FuiToast = {
success: function (message) { return showToast(message, 'success'); },
error: function (message) { return showToast(message, 'error'); }
};
</script>