index.blade.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. @extends('layouts.app')
  2. @section('content')
  3. @include('partials.table', [
  4. 'id' => $id,
  5. 'header' => $header,
  6. 'strings' => $notifications,
  7. ])
  8. @include('partials.pagination', ['items' => $notifications])
  9. @endsection
  10. @push('scripts')
  11. <script type="module">
  12. function updateNotificationBadge(count) {
  13. const badge = document.getElementById('notification-badge');
  14. if (!badge) return;
  15. const safeCount = Math.max(0, parseInt(count || 0, 10));
  16. badge.dataset.count = String(safeCount);
  17. badge.classList.toggle('d-none', safeCount === 0);
  18. }
  19. async function markNotificationRead(id, $row) {
  20. const response = await fetch(`/notifications/${id}/read`, {
  21. method: 'POST',
  22. headers: {
  23. 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute('content'),
  24. 'Accept': 'application/json',
  25. },
  26. });
  27. if (response.ok) {
  28. const data = await response.json();
  29. if (typeof data.unread !== 'undefined') {
  30. updateNotificationBadge(data.unread);
  31. }
  32. if ($row) {
  33. $row.removeClass('notification-unread');
  34. const typeClass = $row.data('read-class');
  35. if (typeClass) $row.addClass(typeClass);
  36. $row.data('notification-read', '1');
  37. if (data.read_at) {
  38. $row.find('.column_read_at').text(data.read_at);
  39. }
  40. }
  41. }
  42. }
  43. $(document).on('dblclick', '#tbl tbody tr[data-notification-id]', function (e) {
  44. const $row = $(this);
  45. const id = $row.data('notification-id');
  46. const isRead = $row.data('notification-read') === '1' || $row.data('notification-read') === 1;
  47. if (!isRead && id) {
  48. e.preventDefault();
  49. markNotificationRead(id, $row);
  50. }
  51. });
  52. </script>
  53. @endpush