61 lines
2.2 KiB
PHP
61 lines
2.2 KiB
PHP
<!-- 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>
|
|
|
|
<!-- Toast Logic -->
|
|
<script type="text/javascript">
|
|
// 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;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Function to show alerts with fallback
|
|
function showAlerts() {
|
|
@if ($errors->any() || session()->has('success'))
|
|
@foreach ($errors->all() as $item)
|
|
if (!showToast('{{ addslashes($item) }}', 'error', 'Opp!')) {
|
|
alert('{{ addslashes($item) }}');
|
|
}
|
|
@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
|
|
setTimeout(function() {
|
|
showAlerts();
|
|
}, 100);
|
|
});
|
|
</script>
|