Fix the notification related issues in mdm.nav bar

merge-requests/1/head
kamidu 8 years ago
parent 04d1a3912a
commit 96503f8166

@ -104,7 +104,7 @@
{{/zone}}
{{#zone "bottomJs"}}
<script id="notifications" data-current-user="{{currentUser.username}}"
data-image-resource="{{self.publicURL}}/images/" src="{{self.publicURL}}/templates/notifications.hbs"
data-image-resource="{{@unit.publicUri}}/images/" src="{{@unit.publicUri}}/templates/notifications.hbs"
type="text/x-handlebars-template"></script>
{{js "js/nav-menu.js"}}
{{/zone}}

@ -22,6 +22,15 @@ var modalPopup = ".wr-modalpopup",
var emmAdminBasePath = "/api/device-mgt/v1.0";
//function openCollapsedNav() {
// $(".wr-hidden-nav-toggle-btn").addClass("active");
// $("#hiddenNav").slideToggle("slideDown", function () {
// if ($(this).css("display") == "none") {
// $(".wr-hidden-nav-toggle-btn").removeClass("active");
// }
// });
//}
/*
* set popup maximum height function.
*/
@ -50,74 +59,93 @@ function hidePopup() {
$(modalPopup).hide();
}
var updateNotificationCount = function (data, textStatus, jqXHR) {
/*
* QR-code generation function.
*/
function generateQRCode(qrCodeClass) {
var enrollmentURL = $("#qr-code-modal").data("enrollment-url");
$(qrCodeClass).qrcode({
text: enrollmentURL,
width: 200,
height: 200
});
}
function toggleEnrollment() {
$(".modalpopup-content").html($("#qr-code-modal").html());
generateQRCode(".modalpopup-content .qr-code");
showPopup();
}
var updateNotificationCountOnSuccess = function (data, textStatus, jqXHR) {
var notificationBubble = "#notification-bubble";
if (jqXHR.status == 200 && data) {
var responsePayload = JSON.parse(data);
var newNotificationsCount = responsePayload.count;
var newNotificationsCount = responsePayload["count"];
if (newNotificationsCount > 0) {
$("#notification-bubble").html(newNotificationsCount);
$(notificationBubble).html(newNotificationsCount);
$(notificationBubble).show();
} else {
$(notificationBubble).hide();
}
// } else {
// $("#notification-bubble").html("Error");
// }
}
};
function loadNotificationsPanel() {
if ("true" == $("#right-sidebar").attr("is-authorized")) {
var serviceURL = emmAdminBasePath + "/notifications?status=NEW";
invokerUtil.get(serviceURL, updateNotificationCount, hideNotificationCount);
loadNewNotifications();
} else {
$("#notification-bubble-wrapper").remove();
}
function updateNotificationCountOnError() {
var notificationBubble = "#notification-bubble";
$(notificationBubble).html("Error");
$(notificationBubble).show();
}
function hideNotificationCount(jqXHR) {
if (jqXHR.status == 404) {
// this means "no new notifications to show"
$("#notification-bubble").hide();
function loadNewNotificationsOnSideViewPanel() {
if ($("#right-sidebar").attr("is-authorized") == "false") {
$("#notification-bubble-wrapper").remove();
} else {
$("#notification-bubble").html("Error");
var serviceURL = emmAdminBasePath + "/notifications?status=NEW";
invokerUtil.get(serviceURL, updateNotificationCountOnSuccess, updateNotificationCountOnError);
loadNewNotifications();
}
}
function loadNewNotifications() {
var messageSideBar = ".sidebar-messages";
if ($("#right-sidebar").attr("is-authorized") == "true") {
if ($("#right-sidebar").attr("is-authorized") == "false") {
$(messageSideBar).html("<h4 class ='message-danger'>You are not authorized to view notifications.</h4>");
} else {
var notifications = $("#notifications");
var currentUser = notifications.data("currentUser");
$.template("notification-listing", notifications.attr("src"), function (template) {
var serviceURL = emmAdminBasePath + "/notifications?status=NEW";
var successCallback = function (data, textStatus, jqXHR) {
invokerUtil.get(
serviceURL,
// on success
function (data, textStatus, jqXHR) {
if (jqXHR.status == 200 && data) {
var viewModel = {};
var responsePayload = JSON.parse(data);
if (responsePayload.notifications) {
viewModel.notifications = responsePayload.notifications;
if (responsePayload["notifications"]) {
if (responsePayload.count > 0) {
viewModel["notifications"] = responsePayload["notifications"];
$(messageSideBar).html(template(viewModel));
} else {
$(messageSideBar).html("<h4 class='text-center'>No new notifications found...</h4>");
}
} else {
$(messageSideBar).html("<h4 class ='message-danger'>Unexpected error occurred while loading new notifications.</h4>");
$(messageSideBar).html("<h4 class ='message-danger'>Unexpected error " +
"occurred while loading new notifications.</h4>");
}
}
};
var errorCallback = function (jqXHR) {
},
// on error
function (jqXHR) {
if (jqXHR.status = 500) {
$(messageSideBar).html("<h4 class ='message-danger'>Unexpected error occurred while trying " +
"to retrieve any new notifications.</h4>");
}
};
invokerUtil.get(serviceURL, successCallback, errorCallback);
}
);
});
} else {
$(messageSideBar).html("<h4 class ='message-danger'>You are not authorized to view notifications</h4>");
}
}
@ -178,8 +206,7 @@ $.sidebar_toggle = function (action, target, container) {
if (buttonParent.is('li')) {
if (relationship !== '') {
$(elem + '[rel=' + relationship + ']:not([data-handle=close])').parent().removeClass("active");
$(elem + '[rel=' + relationship + ']:not([data-handle=close])').parent().
attr('aria-expanded', 'false');
$(elem + '[rel=' + relationship + ']:not([data-handle=close])').parent().attr('aria-expanded', 'false');
}
buttonParent.addClass("active");
buttonParent.attr('aria-expanded', 'true');
@ -217,8 +244,7 @@ $.sidebar_toggle = function (action, target, container) {
if ($(button).parent().is('li')) {
if (relationship !== '') {
$(elem + '[rel=' + relationship + ']:not([data-handle=close])').parent().removeClass("active");
$(elem + '[rel=' + relationship + ']:not([data-handle=close])').parent().
attr('aria-expanded', 'false');
$(elem + '[rel=' + relationship + ']:not([data-handle=close])').parent().attr('aria-expanded', 'false');
}
}
}
@ -317,24 +343,32 @@ $.fn.collapse_nav_sub = function () {
};
$(document).ready(function () {
loadNotificationsPanel();
$.sidebar_toggle();
if (typeof $.fn.collapse == 'function') {
$('.navbar-collapse.tiles').on('shown.bs.collapse', function () {
$(this).collapse_nav_sub();
});
}
loadNewNotificationsOnSideViewPanel();
$("#right-sidebar").on("click", ".new-notification", function () {
var notificationId = $(this).data("id");
var redirectUrl = $(this).data("url");
var markAsReadNotificationsAPI = "/mdm-admin/notifications/" + notificationId + "/CHECKED";
var markAsReadNotificationsEpr = emmAdminBasePath + "/notifications/" + notificationId + "/mark-checked";
var messageSideBar = ".sidebar-messages";
invokerUtil.put(
markAsReadNotificationsAPI,
markAsReadNotificationsEpr,
null,
// on success
function (data) {
data = JSON.parse(data);
if (data.statusCode == responseCodes["ACCEPTED"]) {
location.href = redirectUrl;
}
}, function () {
},
// on error
function () {
var content = "<li class='message message-danger'><h4><i class='icon fw fw-error'></i>Warning</h4>" +
"<p>Unexpected error occurred while loading notification. Please refresh the page and" +
" try again</p></li>";
@ -342,10 +376,4 @@ $(document).ready(function () {
}
);
});
if (typeof $.fn.collapse == 'function') {
$('.navbar-collapse.tiles').on('shown.bs.collapse', function () {
$(this).collapse_nav_sub();
});
}
});

Loading…
Cancel
Save