navbar-notification.blade.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. {{-- Navbar notification --}}
  2. <li class="{{ $makeListItemClass() }}" id="{{ $id }}">
  3. {{-- Link --}}
  4. <a @if($enableDropdownMode) href="" @endif {{ $attributes->merge($makeAnchorDefaultAttrs()) }}>
  5. {{-- Icon --}}
  6. <i class="{{ $makeIconClass() }}"></i>
  7. {{-- Badge --}}
  8. <span class="{{ $makeBadgeClass() }}">{{ $badgeLabel }}</span>
  9. </a>
  10. {{-- Dropdown Menu --}}
  11. @if($enableDropdownMode)
  12. <div class="dropdown-menu dropdown-menu-lg dropdown-menu-right">
  13. {{-- Custom dropdown content provided by external source --}}
  14. <div class="adminlte-dropdown-content"></div>
  15. {{-- Dropdown divider --}}
  16. <div class="dropdown-divider"></div>
  17. {{-- Dropdown footer with link --}}
  18. <a href="{{ $attributes->get('href') }}" class="dropdown-item dropdown-footer">
  19. @isset($dropdownFooterLabel)
  20. {{ $dropdownFooterLabel }}
  21. @else
  22. <i class="fas fa-lg fa-search-plus"></i>
  23. @endisset
  24. </a>
  25. </div>
  26. @endif
  27. </li>
  28. {{-- If required, update the notification periodically --}}
  29. @if (! is_null($makeUpdateUrl()) && $makeUpdatePeriod() > 0)
  30. @push('js')
  31. <script>
  32. $(() => {
  33. // Method to get new notification data from the configured url.
  34. let updateNotification = (nLink) =>
  35. {
  36. // Make an ajax call to the configured url. The response should be
  37. // an object with the new data. The supported properties are:
  38. // 'label', 'label_color', 'icon_color' and 'dropdown'.
  39. $.ajax({
  40. url: "{{ $makeUpdateUrl() }}"
  41. })
  42. .done((data) => {
  43. nLink.update(data);
  44. })
  45. .fail(function(jqXHR, textStatus, errorThrown) {
  46. console.log(jqXHR, textStatus, errorThrown);
  47. });
  48. };
  49. // First load of the notification data.
  50. let nLink = new _AdminLTE_NavbarNotification("{{ $id }}");
  51. updateNotification(nLink);
  52. // Periodically update the notification.
  53. setInterval(updateNotification, {{ $makeUpdatePeriod() }}, nLink);
  54. })
  55. </script>
  56. @endpush
  57. @endif
  58. {{-- Register Javascript utility class for this component --}}
  59. @once
  60. @push('js')
  61. <script>
  62. class _AdminLTE_NavbarNotification {
  63. /**
  64. * Constructor.
  65. *
  66. * target: The id of the target notification link.
  67. */
  68. constructor(target)
  69. {
  70. this.target = target;
  71. }
  72. /**
  73. * Update the notification link.
  74. *
  75. * data: An object with the new data.
  76. */
  77. update(data)
  78. {
  79. // Check if target and data exists.
  80. let t = $(`li#${this.target}`);
  81. if (t.length <= 0 || ! data) {
  82. return;
  83. }
  84. let badge = t.find(".navbar-badge");
  85. let icon = t.find(".nav-link > i");
  86. let dropdown = t.find(".adminlte-dropdown-content");
  87. // Update the badge label.
  88. if (data.label && data.label > 0) {
  89. badge.html(data.label);
  90. } else {
  91. badge.empty();
  92. }
  93. // Update the badge color.
  94. if (data.label_color) {
  95. badge.removeClass((idx, classes) => {
  96. return (classes.match(/(^|\s)badge-\S+/g) || []).join(' ');
  97. }).addClass(`badge-${data.label_color} badge-pill`);
  98. }
  99. // Update the icon color.
  100. if (data.icon_color) {
  101. icon.removeClass((idx, classes) => {
  102. return (classes.match(/(^|\s)text-\S+/g) || []).join(' ');
  103. }).addClass(`text-${data.icon_color}`);
  104. }
  105. // Update the dropdown content.
  106. if (data.dropdown && dropdown.length > 0) {
  107. dropdown.html(data.dropdown);
  108. }
  109. }
  110. }
  111. </script>
  112. @endpush
  113. @endonce