diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/js/notification-listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/js/notification-listing.js index f7f7db822f..6acbcdc68c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/js/notification-listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/js/notification-listing.js @@ -1,26 +1,22 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except * in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ -var responseCodes = { - "CREATED": "Created", - "ACCEPTED": "202", - "INTERNAL_SERVER_ERROR": "Internal Server Error" -}; +var deviceMgtAPIBaseURI = "/api/device-mgt/v1.0"; /** * Following function would execute @@ -31,6 +27,48 @@ function InitiateViewOption() { $(location).attr('href', $(this).data("url")); } +function loadNotifications() { + var deviceListing = $("#notification-listing"); + var deviceListingSrc = deviceListing.attr("src"); + var currentUser = deviceListing.data("currentUser"); + $.template( + "notification-listing", + deviceListingSrc, + function (template) { + invokerUtil.get( + deviceMgtAPIBaseURI + "/notifications", + // on success + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200 && data) { + data = JSON.parse(data); + if (data["notifications"] && data["notifications"].length > 0) { + var viewModel = {}; + viewModel["notifications"] = data["notifications"]; + var content = template(viewModel); + $("#ast-container").html(content); + $("#unread-notifications").datatables_extended(); + $("#all-notifications").datatables_extended(); + } + } + }, + // on error + function (jqXHR) { + console.log(jqXHR.status); + } + ); + } + ); +} + +// Start of HTML embedded invoke methods +function showAdvanceOperation(operation, button) { + $(button).addClass('selected'); + $(button).siblings().removeClass('selected'); + var hiddenOperation = ".wr-hidden-operations-content > div"; + $(hiddenOperation + '[data-operation="' + operation + '"]').show(); + $(hiddenOperation + '[data-operation="' + operation + '"]').siblings().hide(); +} + $(document).ready(function () { var permissionSet = {}; $.setPermission = function (permission) { @@ -43,76 +81,31 @@ $(document).ready(function () { loadNotifications(); - $("#ast-container").on("click", ".new-notification", function(e){ + $("#ast-container").on("click", ".new-notification", function(e) { var notificationId = $(this).data("id"); - var redirectUrl = $(this).data("url"); - var getNotificationsAPI = "/api/device-mgt/v1.0/notifications/"+notificationId+"/CHECKED"; + // var redirectUrl = $(this).data("url"); + var query = deviceMgtAPIBaseURI + "/notifications" + "/" + notificationId + "/mark-checked"; var errorMsgWrapper = "#error-msg"; var errorMsg = "#error-msg span"; invokerUtil.put( - getNotificationsAPI, + query, null, - function (data) { - data = JSON.parse(data); - if (data.status == responseCodes["ACCEPTED"]) { + // on success + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200) { $("#config-save-form").addClass("hidden"); - location.href = redirectUrl; - } else if (data == 500) { - $(errorMsg).text("Exception occurred at backend."); - } else if (data == 403) { - $(errorMsg).text("Action was not permitted."); - } else { - $(errorMsg).text("An unexpected error occurred."); + // location.href = redirectUrl; } - - $(errorMsgWrapper).removeClass("hidden"); - }, function (data) { - data = data.status; - if (data == 500) { - $(errorMsg).text("Exception occurred at backend."); - } else if (data == 403) { + }, + // on error + function (jqXHR) { + if (jqXHR.status == 403) { $(errorMsg).text("Action was not permitted."); - } else { - $(errorMsg).text("An unexpected error occurred."); + } else if (jqXHR.status == 500) { + $(errorMsg).text("An unexpected error occurred. Please try refreshing the page in a while."); } $(errorMsgWrapper).removeClass("hidden"); } ); }); - }); - -function loadNotifications(){ - var deviceListing = $("#notification-listing"); - var deviceListingSrc = deviceListing.attr("src"); - var currentUser = deviceListing.data("currentUser"); - $.template("notification-listing", deviceListingSrc, function (template) { - var serviceURL = "/api/device-mgt/v1.0/notifications"; - var successCallback = function (data) { - var viewModel = {}; - data = JSON.parse(data); - viewModel.notifications = data.notifications; - if(data.count > 0){ - var content = template(viewModel); - $("#ast-container").html(content); - $('#unread-notifications').datatables_extended(); - $('#all-notifications').datatables_extended(); - } - - }; - invokerUtil.get(serviceURL, - successCallback, function(message){ - console.log(message.content); - }); - }); -} - - -// Start of HTML embedded invoke methods -var showAdvanceOperation = function (operation, button) { - $(button).addClass('selected'); - $(button).siblings().removeClass('selected'); - var hiddenOperation = ".wr-hidden-operations-content > div"; - $(hiddenOperation + '[data-operation="' + operation + '"]').show(); - $(hiddenOperation + '[data-operation="' + operation + '"]').siblings().hide(); -}; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/templates/notification-listing.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/templates/notification-listing.hbs index 418bef892b..39d96b17e8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/templates/notification-listing.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/templates/notification-listing.hbs @@ -19,7 +19,7 @@ {{description}} - +