diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js
index 8976f9f1854..6e504b0ea42 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js
@@ -46,6 +46,9 @@ function onRequest(context) {
if (uiPermissions.UPDATE_ENROLLMENT) {
viewModel.permissions.updateEnrollment = true;
}
+ if (uiPermissions.PERMANENT_DELETE) {
+ viewModel.permissions.permanentDelete = true;
+ }
viewModel.currentUser = currentUser;
var deviceCount = 0;
if (groupId) {
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js
index 10c15426956..09a515ac7d6 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js
@@ -70,7 +70,7 @@ function InitiateViewOption(url) {
var deviceCheckbox = "#ast-container .ctrl-wr-asset .itm-select input[type='checkbox']";
var assetContainer = "#ast-container";
-var deviceListing, currentUser, groupId;
+var deviceListing, currentUser, groupId, hasDeletePermission;
/*
* DOM ready functions.
@@ -87,8 +87,8 @@ $(document).ready(function () {
};
deviceListing = $("#device-listing");
+ hasDeletePermission = $("#permission").data("permission")['PERMANENT_DELETE'];
currentUser = deviceListing.data("current-user");
-
groupId = getParameterByName("groupId");
/* Adding selected class for selected devices */
@@ -320,7 +320,7 @@ function loadDevices(searchType, searchParam) {
html = '
Blocked';
break;
case 'REMOVED' :
- html = '
Removed';
+ html = '
Removed';
break;
case 'UNREACHABLE' :
html = '
Unreachable';
@@ -361,12 +361,12 @@ function loadDevices(searchType, searchParam) {
var portalUrl = $("#device-listing").data("portal-url");
var serverUrl = $("#device-listing").data("server-url");
var userDomain = $("#device-listing").data("userDomain");
+ var statusCode = row.status;
var statURL;
- if (status != 'REMOVED') {
+ if (statusCode != 'REMOVED') {
html = '';
if (analyticsEnabled(row.deviceType)) {
-
// redirecting to respective analytics view depending on device configs
switch (getAnalyticsView(deviceType)) {
case "DAS" : { statURL =portalUrl + "/portal/t/"+ userDomain+ "/dashboards/android-iot/battery?owner=" +currentUser+"&deviceId=";break;}
@@ -405,17 +405,115 @@ function loadDevices(searchType, searchParam) {
+ 'data-deviceid="' + deviceIdentifier + '" data-devicetype="' + deviceType
+ '" data-devicename="' + row.name + '" data-placement="top" data-toggle="tooltip" data-original-title="Remove from group">'
+ '
'
- + ''
+ + '
'
+ '
Remove from group';
} else {
html +=
'
'
+ + ''
+ + ''
+ + 'Dis-enroll';
+ }
+ } else if (statusCode == 'REMOVED' && hasDeletePermission) {
+ html = '';
+
+ if (analyticsEnabled(row.deviceType)) {
+ // redirecting to respective analytics view depending on device configs
+ switch (getAnalyticsView(deviceType)) {
+ case "DAS" : {
+ statURL = portalUrl + "/portal/t/" + userDomain + "/dashboards/android-iot/battery?owner=" + currentUser + "&deviceId=";
+ break;
+ }
+ default : {
+ statURL = context + "/device/" + row.deviceType + "/analytics?deviceId="
+ }
+ }
+
+ html += '' +
+ '' +
+ 'Analytics';
+ }
+
+ if (!groupId && groupingEnabled(row.deviceType)) {
+ html +=
+ '' +
+ '' +
+ 'Group';
+ }
+
+ html +=
+ '
'
+ + ''
+ + ''
+ + 'Edit';
+ var groupOwner = $('#group_owner').text();
+ if (groupId && groupOwner != "wso2.system.user") {
+ html +=
+ '
'
+ + ''
+ + ''
+ + 'Remove from group';
+ } else {
+ html +=
+ ''
+ ''
+ ''
+ 'Delete';
}
+ } else {
+ html = '';
+
+ if (analyticsEnabled(row.deviceType)) {
+ // redirecting to respective analytics view depending on device configs
+ switch (getAnalyticsView(deviceType)) {
+ case "DAS" : {
+ statURL = portalUrl + "/portal/t/" + userDomain + "/dashboards/android-iot/battery?owner=" + currentUser + "&deviceId=";
+ break;
+ }
+ default : {
+ statURL = context + "/device/" + row.deviceType + "/analytics?deviceId="
+ }
+ }
+
+ html += '' +
+ '' +
+ 'Analytics';
+ }
+
+ if (!groupId && groupingEnabled(row.deviceType)) {
+ html +=
+ '' +
+ '' +
+ 'Group';
+ }
+
+ html +=
+ '
'
+ + ''
+ + ''
+ + 'Edit';
}
return html;
}
@@ -423,6 +521,11 @@ function loadDevices(searchType, searchParam) {
];
var fnCreatedRow = function (row, data, dataIndex) {
+ if (data.status != "REMOVED") {
+ $(row).attr('data-type', 'selectable');
+ } else {
+ $(row).attr('data-type', 'non-selectable');
+ }
var model = htmlspecialchars(getPropertyValue(data.properties, 'DEVICE_MODEL'));
var vendor = htmlspecialchars(getPropertyValue(data.properties, 'VENDOR'));
var owner = htmlspecialchars(data.userPattern);
@@ -787,6 +890,57 @@ function attachDeviceEvents() {
});
});
+ /**
+ * Following click function would execute
+ * when a user clicks on "Delete" link
+ * on Device Management page in Entgra MDM Console.
+ */
+ $("a.delete-device-link").click(function () {
+ var deviceIdentifiers = [];
+ var deviceId = $(this).data("deviceid");
+ if (deviceId) {
+ deviceIdentifiers = [deviceId];
+ } else {
+ var selectedDevices = getSelectedDevices();
+ if (selectedDevices.length == 0) {
+ $(modalPopupContent).html($('#no-device-selected').html());
+ $("a#no-device-selected-link").click(function () {
+ hidePopup();
+ });
+ showPopup();
+ return;
+ } else {
+ var hasEnrolledDevice;
+ for (var i = 0; i < selectedDevices.length; i++) {
+ if (selectedDevices[i].selectability == 'selectable') {
+ hasEnrolledDevice = true;
+ break;
+ } else {
+ deviceIdentifiers.push(selectedDevices[i].id);
+ }
+ }
+ if (hasEnrolledDevice) {
+ $(modalPopupContent).html($('#enrolled-device-delete-content').html());
+ $("a#enrolled-device-delete-link").click(function () {
+ hidePopup();
+ });
+ showPopup();
+ } else {
+ $(modalPopupContent).html($('#delete-device-modal-content').html());
+ showPopup();
+ }
+ }
+ }
+
+ $("a#delete-device-yes-link").click(function () {
+ deleteDevices(deviceIdentifiers);
+ });
+
+ $("a#delete-device-cancel-link").click(function () {
+ hidePopup();
+ });
+ });
+
/**
* Following click function would execute
* when a user clicks on "Edit" link
@@ -1100,6 +1254,19 @@ function removeDevices(deviceIdentifiers) {
});
}
+function deleteDevices(deviceIdentifiers) {
+ var serviceURL = "/api/device-mgt/v1.0/admin/devices/permanent-delete";
+ invokerUtil.put(serviceURL, deviceIdentifiers, function (message) {
+ $(modalPopupContent).html($('#delete-device-200-content').html());
+ setTimeout(function () {
+ hidePopup();
+ location.reload(false);
+ }, 2000);
+ }, function (jqXHR) {
+ displayDeviceErrors(jqXHR);
+ });
+}
+
function displayDeviceErrors(jqXHR) {
showPopup();
if (jqXHR.status == 400) {
@@ -1144,7 +1311,8 @@ function getSelectedDevices() {
deviceList.push(
{
"id": $(thisTable.api().row(this).node()).data('deviceid'),
- "type": $(thisTable.api().row(this).node()).data('devicetype')
+ "type": $(thisTable.api().row(this).node()).data('devicetype'),
+ "selectability": $(thisTable.api().row(this).node()).data('type')
}
);
}