diff options
Diffstat (limited to 'view')
-rw-r--r-- | view/js/main.js | 54 | ||||
-rw-r--r-- | view/theme/redbasic/php/theme_init.php | 3 | ||||
-rw-r--r-- | view/tpl/notifications_widget.tpl | 20 |
3 files changed, 40 insertions, 37 deletions
diff --git a/view/js/main.js b/view/js/main.js index 00c536243..8eb02156b 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -68,14 +68,11 @@ $(document).ready(function() { $('a.notification-link').click(function(e){ var notifyType = $(this).data('type'); - if (!$(this).data('clicked') && (sessionStorage.getItem(notifyType + '_notifications_cache') !== null)) { - var cached_data = JSON.parse(sessionStorage.getItem(notifyType + '_notifications_cache')); - loadNotificationItems(notifyType, cached_data); - $(this).data('clicked', true); - } - else { + if(! $('#nav-' + notifyType + '-sub').hasClass('show')) { loadNotificationItems(notifyType); } + + $(this).data('clicked', true); }); // Allow folks to stop the ajax page updates with the pause/break key @@ -391,6 +388,14 @@ function notificationsUpdate(cached_data) { }); } + var notifyType = null; + if($('.notification-content.show').length) { + notifyType = $('.notification-content.show').data('type'); + } + if(notifyType !== null) { + loadNotificationItems(notifyType); + } + if(timer) clearTimeout(timer); timer = setTimeout(updateInit,updateInterval); } @@ -431,7 +436,6 @@ function handleNotifications(data) { } function handleNotificationsItems(notifyType, data) { - var notifications_tpl= unescape($("#nav-notifications-template[rel=template]").html()); var notify_menu = $("#nav-" + notifyType + "-menu"); @@ -924,33 +928,33 @@ function justifyPhotosAjax(id) { $('#' + id).justifiedGallery('norewind').on('jg.complete', function(e){ justifiedGalleryActive = false; }); } -function loadNotificationItems(notifyType, cached_data) { - +function loadNotificationItems(notifyType) { var pingExCmd = 'ping/' + notifyType + ((localUser != 0) ? '?f=&uid=' + localUser : ''); - if(cached_data !== undefined) { + var clicked = $('[data-type=\'' + notifyType + '\']').data('clicked'); + if((clicked === undefined) && (sessionStorage.getItem(notifyType + '_notifications_cache') !== null)) { + var cached_data = JSON.parse(sessionStorage.getItem(notifyType + '_notifications_cache')); handleNotificationsItems(notifyType, cached_data); + console.log('updating ' + notifyType + ' notifications from cache...'); } else { - $.get(pingExCmd, function(data) { - if(data.invalid == 1) { - window.location.href=window.location.href; - } - - $("." + notifyType + "-update").html(data.notify.length); + var cached_data = []; + } - sessionStorage.setItem(notifyType + '_notifications_cache', JSON.stringify(data.notify)); + console.log('updating ' + notifyType + ' notifications...'); + $.get(pingExCmd, function(data) { + if(data.invalid == 1) { + window.location.href=window.location.href; + } + if(JSON.stringify(cached_data[0]) === JSON.stringify(data.notify[0])) { + console.log(notifyType + ' notifications cache up to date - update deferred'); + } + else { handleNotificationsItems(notifyType, data.notify); - }); - } - - setTimeout(function() { - if($('#nav-' + notifyType + '-sub').hasClass('show')) { - console.log('updating ' + notifyType + ' notifications...'); - setTimeout(loadNotificationItems, updateInterval, notifyType); + sessionStorage.setItem(notifyType + '_notifications_cache', JSON.stringify(data.notify)); } - }, 1000); + }); } // Since our ajax calls are asynchronous, we will give a few diff --git a/view/theme/redbasic/php/theme_init.php b/view/theme/redbasic/php/theme_init.php index b12d80ea5..73ae8f6d2 100644 --- a/view/theme/redbasic/php/theme_init.php +++ b/view/theme/redbasic/php/theme_init.php @@ -8,8 +8,7 @@ head_add_css('/library/datetimepicker/jquery.datetimepicker.css'); head_add_css('/library/bootstrap-colorpicker/dist/css/bootstrap-colorpicker.min.css'); require_once('view/php/theme_init.php'); -head_add_js('/library/popper/popper.min.js'); -head_add_js('/library/bootstrap/js/bootstrap.min.js'); +head_add_js('/library/bootstrap/js/bootstrap.bundle.min.js'); head_add_js('/library/bootbox/bootbox.min.js'); head_add_js('/library/bootstrap-tagsinput/bootstrap-tagsinput.js'); head_add_js('/library/datetimepicker/jquery.datetimepicker.js'); diff --git a/view/tpl/notifications_widget.tpl b/view/tpl/notifications_widget.tpl index fd5c0dbc0..69e5e15bc 100644 --- a/view/tpl/notifications_widget.tpl +++ b/view/tpl/notifications_widget.tpl @@ -115,21 +115,21 @@ <div id="no_notifications" class="d-xl-none"> {{$no_notifications}}<span class="jumping-dots"><span class="dot-1">.</span><span class="dot-2">.</span><span class="dot-3">.</span></span> </div> - <div id="notifications" class="navbar-nav" data-children=".nav-item"> - <div id="nav-notifications-template" rel="template"> - <a class="list-group-item clearfix notification {5}" href="{0}" title="{2} {3}" data-b64mid="{6}" data-notify_id="{7}" data-thread_top="{8}" data-contact_name="{2}"> - <img class="menu-img-3" data-src="{1}"> - <span class="contactname">{2}</span> - <span class="dropdown-sub-text">{3}<br>{4}</span> - </a> - </div> + <div id="nav-notifications-template" rel="template"> + <a class="list-group-item clearfix notification {5}" href="{0}" title="{2} {3}" data-b64mid="{6}" data-notify_id="{7}" data-thread_top="{8}" data-contact_name="{2}"> + <img class="menu-img-3" data-src="{1}"> + <span class="contactname">{2}</span> + <span class="dropdown-sub-text">{3}<br>{4}</span> + </a> + </div> + <div id="notifications" class="navbar-nav"> {{foreach $notifications as $notification}} <div class="collapse {{$notification.type}}-button"> - <a class="list-group-item notification-link" href="#nav-{{$notification.type}}-sub" title="{{$notification.title}}" data-toggle="collapse" data-parent="#notifications" data-type="{{$notification.type}}"> + <a class="list-group-item notification-link" href="#" title="{{$notification.title}}" data-target="#nav-{{$notification.type}}-sub" data-toggle="collapse" data-type="{{$notification.type}}"> <i class="fa fa-fw fa-{{$notification.icon}}"></i> {{$notification.label}} <span class="float-right badge badge-{{$notification.severity}} {{$notification.type}}-update"></span> </a> - <div id="nav-{{$notification.type}}-sub" class="collapse notification-content"> + <div id="nav-{{$notification.type}}-sub" class="collapse notification-content" data-parent="#notifications" data-type="{{$notification.type}}"> {{if $notification.viewall}} <a class="list-group-item text-dark" id="nav-{{$notification.type}}-see-all" href="{{$notification.viewall.url}}"> <i class="fa fa-fw fa-external-link"></i> {{$notification.viewall.label}} |