Fix notification view issue

4.x.x
kamidu 8 years ago
parent 77a8fed7de
commit 4506db3647

@ -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, * WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * 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, * Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an * software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* KIND, either express or implied. See the License for the * either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
var responseCodes = { var deviceMgtAPIBaseURI = "/api/device-mgt/v1.0";
"CREATED": "Created",
"ACCEPTED": "202",
"INTERNAL_SERVER_ERROR": "Internal Server Error"
};
/** /**
* Following function would execute * Following function would execute
@ -31,6 +27,48 @@ function InitiateViewOption() {
$(location).attr('href', $(this).data("url")); $(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 () { $(document).ready(function () {
var permissionSet = {}; var permissionSet = {};
$.setPermission = function (permission) { $.setPermission = function (permission) {
@ -43,76 +81,31 @@ $(document).ready(function () {
loadNotifications(); loadNotifications();
$("#ast-container").on("click", ".new-notification", function(e){ $("#ast-container").on("click", ".new-notification", function(e) {
var notificationId = $(this).data("id"); var notificationId = $(this).data("id");
var redirectUrl = $(this).data("url"); // var redirectUrl = $(this).data("url");
var getNotificationsAPI = "/api/device-mgt/v1.0/notifications/"+notificationId+"/CHECKED"; var query = deviceMgtAPIBaseURI + "/notifications" + "/" + notificationId + "/mark-checked";
var errorMsgWrapper = "#error-msg"; var errorMsgWrapper = "#error-msg";
var errorMsg = "#error-msg span"; var errorMsg = "#error-msg span";
invokerUtil.put( invokerUtil.put(
getNotificationsAPI, query,
null, null,
function (data) { // on success
data = JSON.parse(data); function (data, textStatus, jqXHR) {
if (data.status == responseCodes["ACCEPTED"]) { if (jqXHR.status == 200) {
$("#config-save-form").addClass("hidden"); $("#config-save-form").addClass("hidden");
location.href = redirectUrl; // 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.");
} }
},
$(errorMsgWrapper).removeClass("hidden"); // on error
}, function (data) { function (jqXHR) {
data = data.status; if (jqXHR.status == 403) {
if (data == 500) {
$(errorMsg).text("Exception occurred at backend.");
} else if (data == 403) {
$(errorMsg).text("Action was not permitted."); $(errorMsg).text("Action was not permitted.");
} else { } else if (jqXHR.status == 500) {
$(errorMsg).text("An unexpected error occurred."); $(errorMsg).text("An unexpected error occurred. Please try refreshing the page in a while.");
} }
$(errorMsgWrapper).removeClass("hidden"); $(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();
};

@ -19,7 +19,7 @@
<tr data-type="selectable" data-id="{{id}}"> <tr data-type="selectable" data-id="{{id}}">
<td data-display="{{description}}" data-grid-label="Description">{{description}}</td> <td data-display="{{description}}" data-grid-label="Description">{{description}}</td>
<td style="text-align: center;"> <td style="text-align: center;">
<a href="device?type={{deviceIdentifier.type}}&id={{deviceIdentifier.id}}" data-id="{{id}}" data-url="device?type={{deviceIdentifier.type}}&id={{deviceIdentifier.id}}" class="new-notification" data-click-event="remove-form"> <a href="device?type={{deviceIdentifier.type}}&id={{deviceIdentifier.id}}" data-id="{{id}}" data-url="device/{{deviceIdentifier.type}}?id={{deviceIdentifier.id}}" class="new-notification" data-click-event="remove-form">
<span class="fw-stack"> <span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i> <i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-view fw-stack-1x"></i> <i class="fw fw-view fw-stack-1x"></i>

Loading…
Cancel
Save