| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- {{-- Navbar notification --}}
- <li class="{{ $makeListItemClass() }}" id="{{ $id }}">
- {{-- Link --}}
- <a @if($enableDropdownMode) href="" @endif {{ $attributes->merge($makeAnchorDefaultAttrs()) }}>
- {{-- Icon --}}
- <i class="{{ $makeIconClass() }}"></i>
- {{-- Badge --}}
- <span class="{{ $makeBadgeClass() }}">{{ $badgeLabel }}</span>
- </a>
- {{-- Dropdown Menu --}}
- @if($enableDropdownMode)
- <div class="dropdown-menu dropdown-menu-lg dropdown-menu-right">
- {{-- Custom dropdown content provided by external source --}}
- <div class="adminlte-dropdown-content"></div>
- {{-- Dropdown divider --}}
- <div class="dropdown-divider"></div>
- {{-- Dropdown footer with link --}}
- <a href="{{ $attributes->get('href') }}" class="dropdown-item dropdown-footer">
- @isset($dropdownFooterLabel)
- {{ $dropdownFooterLabel }}
- @else
- <i class="fas fa-lg fa-search-plus"></i>
- @endisset
- </a>
- </div>
- @endif
- </li>
- {{-- If required, update the notification periodically --}}
- @if (! is_null($makeUpdateUrl()) && $makeUpdatePeriod() > 0)
- @push('js')
- <script>
- $(() => {
- // Method to get new notification data from the configured url.
- let updateNotification = (nLink) =>
- {
- // Make an ajax call to the configured url. The response should be
- // an object with the new data. The supported properties are:
- // 'label', 'label_color', 'icon_color' and 'dropdown'.
- $.ajax({
- url: "{{ $makeUpdateUrl() }}"
- })
- .done((data) => {
- nLink.update(data);
- })
- .fail(function(jqXHR, textStatus, errorThrown) {
- console.log(jqXHR, textStatus, errorThrown);
- });
- };
- // First load of the notification data.
- let nLink = new _AdminLTE_NavbarNotification("{{ $id }}");
- updateNotification(nLink);
- // Periodically update the notification.
- setInterval(updateNotification, {{ $makeUpdatePeriod() }}, nLink);
- })
- </script>
- @endpush
- @endif
- {{-- Register Javascript utility class for this component --}}
- @once
- @push('js')
- <script>
- class _AdminLTE_NavbarNotification {
- /**
- * Constructor.
- *
- * target: The id of the target notification link.
- */
- constructor(target)
- {
- this.target = target;
- }
- /**
- * Update the notification link.
- *
- * data: An object with the new data.
- */
- update(data)
- {
- // Check if target and data exists.
- let t = $(`li#${this.target}`);
- if (t.length <= 0 || ! data) {
- return;
- }
- let badge = t.find(".navbar-badge");
- let icon = t.find(".nav-link > i");
- let dropdown = t.find(".adminlte-dropdown-content");
- // Update the badge label.
- if (data.label && data.label > 0) {
- badge.html(data.label);
- } else {
- badge.empty();
- }
- // Update the badge color.
- if (data.label_color) {
- badge.removeClass((idx, classes) => {
- return (classes.match(/(^|\s)badge-\S+/g) || []).join(' ');
- }).addClass(`badge-${data.label_color} badge-pill`);
- }
- // Update the icon color.
- if (data.icon_color) {
- icon.removeClass((idx, classes) => {
- return (classes.match(/(^|\s)text-\S+/g) || []).join(' ');
- }).addClass(`text-${data.icon_color}`);
- }
- // Update the dropdown content.
- if (data.dropdown && dropdown.length > 0) {
- dropdown.html(data.dropdown);
- }
- }
- }
- </script>
- @endpush
- @endonce
|