From d665a96341e4ae0a0b652c5b4f1cfd995735e1ca Mon Sep 17 00:00:00 2001 From: sandeepsajan0 <sandeepsajan0@gmail.com> Date: Fri, 24 Jun 2022 11:32:31 +0530 Subject: [PATCH] Fix tests and js lint issues --- hypha/apply/activity/context_processors.py | 5 ++-- .../src/javascript/apply/notifications.js | 26 ++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/hypha/apply/activity/context_processors.py b/hypha/apply/activity/context_processors.py index 6f94d6b93..0a9a62168 100644 --- a/hypha/apply/activity/context_processors.py +++ b/hypha/apply/activity/context_processors.py @@ -3,6 +3,7 @@ from .models import Activity def notification_context(request): context_data = dict() - if request.user.is_authenticated and request.user.is_apply_staff: - context_data['latest_notifications'] = Activity.objects.all().order_by('-timestamp')[:5] + if hasattr(request, 'user'): + if request.user.is_authenticated and request.user.is_apply_staff: + context_data['latest_notifications'] = Activity.objects.all().order_by('-timestamp')[:5] return context_data diff --git a/hypha/static_src/src/javascript/apply/notifications.js b/hypha/static_src/src/javascript/apply/notifications.js index 43e3de514..f3e619abd 100644 --- a/hypha/static_src/src/javascript/apply/notifications.js +++ b/hypha/static_src/src/javascript/apply/notifications.js @@ -1,17 +1,19 @@ function notificationToggle() { - document.getElementById("notificationDropdown").classList.toggle("show"); + 'use strict'; + document.getElementById('notificationDropdown').classList.toggle('show'); } // Close the dropdown menu if the user clicks outside of it -window.onclick = function(event) { - if (!event.target.matches('.dropbtn, .dropbtn *')) { - var dropdowns = document.getElementsByClassName("dropdown-content"); - var i; - for (i = 0; i < dropdowns.length; i++) { - var openDropdown = dropdowns[i]; - if (openDropdown.classList.contains('show')) { - openDropdown.classList.remove('show'); - } +window.onclick = function (event) { + 'use strict'; + if (!event.target.matches('.dropbtn, .dropbtn *')) { + var dropdowns = document.getElementsByClassName('dropdown-content'); + var i; + for (i = 0; i < dropdowns.length; i++) { + var openDropdown = dropdowns[i]; + if (openDropdown.classList.contains('show')) { + notificationToggle(); + } + } } - } -} +}; -- GitLab