'
+ + ''
+ + ''
+ + 'Delete';
+ }
}
return html;
}
@@ -380,13 +376,14 @@ function loadDevices(searchType, searchParam) {
var fnCreatedRow = function (row, data, dataIndex) {
$(row).attr('data-type', 'selectable');
$(row).attr('data-deviceid', data.deviceIdentifier);
- $(row).attr('data-devicetype', data.type);
+ $(row).attr('data-devicetype', data.deviceType);
+ $(row).attr('data-url', context + '/device/' + data.deviceType + '?id=' + data.deviceIdentifier);
var model = getPropertyValue(data.properties, 'DEVICE_MODEL');
var vendor = getPropertyValue(data.properties, 'VENDOR');
var owner = data.user;
var status = data.status;
var ownership = data.ownership;
- var deviceType = data.type;
+ var deviceType = data.deviceType;
var category = getDeviceTypeCategory(deviceType);
$.each($('td', row), function (colIndex) {
switch (colIndex) {
@@ -560,17 +557,13 @@ function markAlreadyAssignedGroups(deviceId, deviceType) {
data = JSON.parse(data);
if (xhr.status == 200) {
if (data.length > 0) {
+ var selectedValues = [];
for (var i = 0; i < data.length; i++) {
- $('.groupCheckBoxes').each(
- function () {
- if (data[i].id == $(this).data('groupid')) {
- $(this).attr('checked', true);
- }
- }
- );
+ if (data[i].owner != "wso2.system.user") {
+ selectedValues.push(data[i].id);
+ }
}
- } else {
- return;
+ $("#groups").val(selectedValues).trigger("change");
}
} else {
displayErrors(xhr);
@@ -600,7 +593,7 @@ function attachDeviceEvents() {
$(modalPopupContent).html($('#group-device-modal-content').html());
$('#user-groups').html(
'');
- $("a#group-device-yes-link").hide();
+ $("a#group-device-update-link").hide();
showPopup();
var serviceURL;
@@ -612,39 +605,39 @@ function attachDeviceEvents() {
}
invokerUtil.get(serviceURL, function (data) {
+ $("a#group-device-add-link").hide();
var groups = JSON.parse(data);
var html = '';
var hasGroups = false;
for (var i = 0; i < groups.deviceGroups.length; i++) {
if (groups.deviceGroups[i].owner != "wso2.system.user") {
- html += '';
+ html += '';
hasGroups = true;
}
}
if (hasGroups) {
- html = '
Please select device group(s)
' + html;
+ html = '
Please select device group(s)
' +
+ '' +
+ '
';
markAlreadyAssignedGroups(deviceId, deviceType);
- $("a#group-device-yes-link").show();
+ $("a#group-device-update-link").show();
$("a#group-add-link").hide();
} else {
- $("a#group-device-yes-link").hide();
+ $("a#group-device-update-link").hide();
$("a#group-add-link").show();
html += '
You don\'t have any existing device groups. Please add new device group first.
'
}
$('#user-groups').html(html);
- $("a#group-device-yes-link").click(function () {
+ $("select.select2[multiple=multiple]").select2({
+ tags: false
+ });
+ $("a#group-device-update-link").click(function () {
var deviceIdentifier = {"id": deviceId, "type": deviceType};
- var deviceGroupIds = [];
- $('.modal .groupCheckBoxes').each(
- function () {
- if ($(this).is(':checked')) {
- deviceGroupIds.push($(this).data('groupid'));
- }
- }
- );
+ var deviceGroupIds = $("#groups").val();
+ if (!deviceGroupIds) {
+ deviceGroupIds = [];
+ }
var deviceToGroupsAssignment = {
deviceIdentifier: deviceIdentifier,
deviceGroupIds: deviceGroupIds
@@ -684,36 +677,42 @@ function attachDeviceEvents() {
* on Device Management page in WSO2 MDM Console.
*/
$("a.remove-device-link").click(function () {
+ var deviceIdentifiers = [];
var deviceId = $(this).data("deviceid");
var deviceType = $(this).data("devicetype");
- var serviceURL = "/api/device-mgt/v1.0/devices/type/" + deviceType + "/id/" + deviceId;
+
+ if (deviceId && deviceType) {
+ deviceIdentifiers = [{"id": deviceId, "type": deviceType}];
+ } else {
+ deviceIdentifiers = getSelectedDevices();
+ }
+
+ if (deviceIdentifiers.length == 0) {
+ $(modalPopupContent).html($('#no-device-selected').html());
+ $("a#no-device-selected-link").click(function () {
+ hidePopup();
+ });
+ showPopup();
+ return;
+ }
$(modalPopupContent).html($('#remove-device-modal-content').html());
showPopup();
$("a#remove-device-yes-link").click(function () {
if (groupId) {
- var deviceIdentifiers = [{"id": deviceId, "type": deviceType}];
- serviceURL = "/api/device-mgt/v1.0/groups/id/" + groupId + "/devices/remove";
+ var serviceURL = "/api/device-mgt/v1.0/groups/id/" + groupId + "/devices/remove";
invokerUtil.post(serviceURL, deviceIdentifiers, function (message) {
- $(modalPopupContent).html($('#remove-device-from-group-200-content').html());
- setTimeout(function () {
- hidePopup();
- location.reload(false);
- }, 2000);
- }, function (message) {
- displayDeviceErrors(message);
- });
- } else {
- invokerUtil.delete(serviceURL, function (message) {
$(modalPopupContent).html($('#remove-device-200-content').html());
setTimeout(function () {
hidePopup();
location.reload(false);
}, 2000);
- }, function (message) {
+ }, function (jqXHR) {
displayDeviceErrors(jqXHR);
});
+ } else {
+ removeDevices(deviceIdentifiers);
}
});
@@ -745,7 +744,7 @@ function attachDeviceEvents() {
hidePopup();
location.reload(false);
}, 2000);
- }, function (message) {
+ }, function (jqXHR) {
displayDeviceErrors(jqXHR);
});
});
@@ -754,6 +753,106 @@ function attachDeviceEvents() {
hidePopup();
});
});
+
+ /**
+ * Following click function would execute
+ * when a user clicks on "Add to Group" link
+ * on Device Management page in WSO2 devicemgt Console.
+ */
+ $("a.add-devices-to-group-link").click(function () {
+ $("a#group-device-update-link").hide();
+ var deviceIdentifiers = getSelectedDevices();
+ if (deviceIdentifiers.length == 0) {
+ $(modalPopupContent).html($('#no-device-selected').html());
+ $("a#no-device-selected-link").click(function () {
+ hidePopup();
+ });
+ showPopup();
+ return;
+ }
+
+ $(modalPopupContent).html($('#group-device-modal-content').html());
+ $('#user-groups').html(
+ '');
+ $("a#group-device-add-link").hide();
+ showPopup();
+
+ var serviceURL;
+ if ($.hasPermission("LIST_ALL_GROUPS")) {
+ serviceURL = "/api/device-mgt/v1.0/admin/groups?limit=100";
+ } else if ($.hasPermission("LIST_GROUPS")) {
+ //Get authenticated users groups
+ serviceURL = "/api/device-mgt/v1.0/groups?limit=100";
+ }
+
+ invokerUtil.get(serviceURL, function (data) {
+ var groups = JSON.parse(data);
+ var html = '';
+ var hasGroups = false;
+ for (var i = 0; i < groups.deviceGroups.length; i++) {
+ if (groups.deviceGroups[i].owner != "wso2.system.user") {
+ html += '';
+ hasGroups = true;
+ }
+ }
+ if (hasGroups) {
+ html = '
';
+ $("a#group-add-link").hide();
+ $("a#group-device-add-link").show();
+ } else {
+ html += '
You don\'t have any existing device groups. Please add new device group first.
';
+ $("a#group-add-link").show();
+ $("a#group-device-add-link").hide();
+ }
+ $('#user-groups').html(html);
+ $("a#group-device-add-link").click(function () {
+ var selectedGroup = $('#assign-group-selector').val();
+ serviceURL = "/api/device-mgt/v1.0/groups/id/" + selectedGroup + "/devices/add";
+ invokerUtil.post(serviceURL, deviceIdentifiers, function (data) {
+ $(modalPopupContent).html($('#group-associate-device-200-content').html());
+ setTimeout(function () {
+ hidePopup();
+ location.reload(false);
+ }, 2000);
+ }, function (jqXHR) {
+ displayDeviceErrors(jqXHR);
+ });
+ });
+ }, function (jqXHR) {
+ if (jqXHR.status == 404) {
+ $(modalPopupContent).html($('#group-404-content').html());
+ $("a#cancel-link").click(function () {
+ hidePopup();
+ });
+ } else {
+ displayDeviceErrors(jqXHR);
+ }
+ });
+
+ $("a#group-device-cancel-link").click(function () {
+ hidePopup();
+ });
+ });
+}
+
+function removeDevices(deviceIdentifiers) {
+ var serviceURL = "/api/device-mgt/v1.0/devices/type/" + deviceIdentifiers[0].type + "/id/" + deviceIdentifiers[0].id;
+ invokerUtil.delete(serviceURL, function (message) {
+ if (deviceIdentifiers.length > 1) {
+ deviceIdentifiers.slice(1, deviceIdentifiers.length);
+ removeDevices(deviceIdentifiers);
+ } else {
+ $(modalPopupContent).html($('#remove-device-200-content').html());
+ setTimeout(function () {
+ hidePopup();
+ location.reload(false);
+ }, 2000);
+ }
+ }, function (jqXHR) {
+ displayDeviceErrors(jqXHR);
+ });
}
function displayDeviceErrors(jqXHR) {
@@ -788,3 +887,23 @@ function getParameterByName(name) {
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
+
+/*
+ * Function to get selected devices.
+ */
+function getSelectedDevices() {
+ var deviceList = [];
+ var thisTable = $(".DTTT_selected").closest('.dataTables_wrapper').find('.dataTable').dataTable();
+ thisTable.api().rows().every(function () {
+ if ($(this.node()).hasClass('DTTT_selected')) {
+ deviceList.push(
+ {
+ "id": $(thisTable.api().row(this).node()).data('deviceid'),
+ "type": $(thisTable.api().row(this).node()).data('devicetype')
+ }
+ );
+ }
+ });
+
+ return deviceList;
+}
\ No newline at end of file
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js
index 6661e775b4..a229215b57 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js
@@ -23,6 +23,7 @@
*/
function InitiateViewOption(url) {
if ($(".select-enable-btn").text() == "Select") {
+ url = $(this).parent().data("url");
$(location).attr('href', url);
}
}
@@ -147,35 +148,30 @@ function loadGroups() {
return JSON.stringify(json);
};
- var columns = [{
- targets: 0,
- data: 'id',
- class: 'remove-padding icon-only content-fill',
- render: function (data, type, row, meta) {
- if ($.hasPermission("VIEW_GROUP_DEVICES")) {
- return '