From 96503f81666b0eee10a17876148aa96ce322c0e6 Mon Sep 17 00:00:00 2001 From: kamidu Date: Fri, 12 Aug 2016 14:09:08 +0530 Subject: [PATCH] Fix the notification related issues in mdm.nav bar --- .../mdm.unit.ui.navbar.nav-menu/nav-menu.hbs | 2 +- .../public/js/nav-menu.js | 142 +++++++++++------- 2 files changed, 86 insertions(+), 58 deletions(-) diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.navbar.nav-menu/nav-menu.hbs b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.navbar.nav-menu/nav-menu.hbs index a89cb0031..b4c15eea3 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.navbar.nav-menu/nav-menu.hbs +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.navbar.nav-menu/nav-menu.hbs @@ -104,7 +104,7 @@ {{/zone}} {{#zone "bottomJs"}} {{js "js/nav-menu.js"}} {{/zone}} diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.navbar.nav-menu/public/js/nav-menu.js b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.navbar.nav-menu/public/js/nav-menu.js index c15f80b26..5015563a9 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.navbar.nav-menu/public/js/nav-menu.js +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.ui.navbar.nav-menu/public/js/nav-menu.js @@ -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("

You are not authorized to view notifications.

"); + } 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) { - if (jqXHR.status == 200 && data) { - var viewModel = {}; - var responsePayload = JSON.parse(data); - - if (responsePayload.notifications) { - viewModel.notifications = responsePayload.notifications; - if (responsePayload.count > 0) { - $(messageSideBar).html(template(viewModel)); + invokerUtil.get( + serviceURL, + // on success + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200 && data) { + var viewModel = {}; + var responsePayload = JSON.parse(data); + if (responsePayload["notifications"]) { + if (responsePayload.count > 0) { + viewModel["notifications"] = responsePayload["notifications"]; + $(messageSideBar).html(template(viewModel)); + } else { + $(messageSideBar).html("

No new notifications found...

"); + } } else { - $(messageSideBar).html("

No new notifications found...

"); + $(messageSideBar).html("

Unexpected error " + + "occurred while loading new notifications.

"); } - } else { - $(messageSideBar).html("

Unexpected error occurred while loading new notifications.

"); + } + }, + // on error + function (jqXHR) { + if (jqXHR.status = 500) { + $(messageSideBar).html("

Unexpected error occurred while trying " + + "to retrieve any new notifications.

"); } } - }; - var errorCallback = function (jqXHR) { - if (jqXHR.status = 500) { - $(messageSideBar).html("

Unexpected error occurred while trying " + - "to retrieve any new notifications.

"); - } - }; - invokerUtil.get(serviceURL, successCallback, errorCallback); + ); }); - } else { - $(messageSideBar).html("

You are not authorized to view notifications

"); } } @@ -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 = "
  • Warning

    " + "

    Unexpected error occurred while loading notification. Please refresh the page and" + " try again

  • "; @@ -342,10 +376,4 @@ $(document).ready(function () { } ); }); - - if (typeof $.fn.collapse == 'function') { - $('.navbar-collapse.tiles').on('shown.bs.collapse', function () { - $(this).collapse_nav_sub(); - }); - } });