|
|
|
@ -51,7 +51,7 @@ function InitiateViewOption(url) {
|
|
|
|
|
var deviceCheckbox = "#ast-container .ctrl-wr-asset .itm-select input[type='checkbox']";
|
|
|
|
|
var assetContainer = "#ast-container";
|
|
|
|
|
|
|
|
|
|
var deviceListing, currentUser, groupName, groupId;
|
|
|
|
|
var deviceListing, currentUser, groupId;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* DOM ready functions.
|
|
|
|
@ -69,8 +69,7 @@ $(document).ready(function () {
|
|
|
|
|
|
|
|
|
|
deviceListing = $("#device-listing");
|
|
|
|
|
currentUser = deviceListing.data("current-user");
|
|
|
|
|
|
|
|
|
|
groupName = getParameterByName("groupName");
|
|
|
|
|
|
|
|
|
|
groupId = getParameterByName("groupId");
|
|
|
|
|
|
|
|
|
|
/* Adding selected class for selected devices */
|
|
|
|
@ -161,7 +160,7 @@ function toTitleCase(str) {
|
|
|
|
|
|
|
|
|
|
function loadDevices(searchType, searchParam) {
|
|
|
|
|
var serviceURL;
|
|
|
|
|
if (groupName && groupId && $.hasPermission("LIST_OWN_DEVICES")) {
|
|
|
|
|
if (groupId && $.hasPermission("LIST_OWN_DEVICES")) {
|
|
|
|
|
serviceURL = "/api/device-mgt/v1.0/groups/id/" + groupId + "/devices";
|
|
|
|
|
} else if ($.hasPermission("LIST_DEVICES")) {
|
|
|
|
|
serviceURL = "/api/device-mgt/v1.0/devices";
|
|
|
|
@ -261,7 +260,7 @@ function loadDevices(searchType, searchParam) {
|
|
|
|
|
return '<a href="' + context + '/device/' + row.deviceType + '?id=' + row.deviceIdentifier
|
|
|
|
|
+ '"><div class="thumbnail icon"><img class="square-element text fw " src="'
|
|
|
|
|
+ getDeviceTypeThumb(
|
|
|
|
|
row.deviceType) + '"/></div></a>';
|
|
|
|
|
row.deviceType) + '"/></div></a>';
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
@ -345,33 +344,33 @@ function loadDevices(searchType, searchParam) {
|
|
|
|
|
'<span class="hidden-xs hidden-on-grid-view">Analytics</span>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((!groupName || !groupId) && groupingEnabled(row.deviceType)) {
|
|
|
|
|
if (!groupId && groupingEnabled(row.deviceType)) {
|
|
|
|
|
html +=
|
|
|
|
|
'<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view group-device-link" '
|
|
|
|
|
+
|
|
|
|
|
'data-deviceid="' + deviceIdentifier + '" data-devicetype="' + deviceType
|
|
|
|
|
+ '" data-devicename="' +
|
|
|
|
|
row.name + '"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i>' +
|
|
|
|
|
'<i class="fw fw-grouping fw-stack-1x"></i></span>' +
|
|
|
|
|
'<span class="hidden-xs hidden-on-grid-view">Group</span></a>';
|
|
|
|
|
'<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view group-device-link" '
|
|
|
|
|
+
|
|
|
|
|
'data-deviceid="' + deviceIdentifier + '" data-devicetype="' + deviceType
|
|
|
|
|
+ '" data-devicename="' +
|
|
|
|
|
row.name + '"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i>' +
|
|
|
|
|
'<i class="fw fw-grouping fw-stack-1x"></i></span>' +
|
|
|
|
|
'<span class="hidden-xs hidden-on-grid-view">Group</span></a>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
html +=
|
|
|
|
|
'<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view edit-device-link" '
|
|
|
|
|
+
|
|
|
|
|
'data-deviceid="' + deviceIdentifier + '" data-devicetype="' + deviceType
|
|
|
|
|
+ '" data-devicename="' + row.name + '">' +
|
|
|
|
|
'<span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i>' +
|
|
|
|
|
'<i class="fw fw-edit fw-stack-1x"></i></span>' +
|
|
|
|
|
'<span class="hidden-xs hidden-on-grid-view">Edit</span></a>';
|
|
|
|
|
'<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view edit-device-link" '
|
|
|
|
|
+
|
|
|
|
|
'data-deviceid="' + deviceIdentifier + '" data-devicetype="' + deviceType
|
|
|
|
|
+ '" data-devicename="' + row.name + '">' +
|
|
|
|
|
'<span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i>' +
|
|
|
|
|
'<i class="fw fw-edit fw-stack-1x"></i></span>' +
|
|
|
|
|
'<span class="hidden-xs hidden-on-grid-view">Edit</span></a>';
|
|
|
|
|
html +=
|
|
|
|
|
'<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view remove-device-link" '
|
|
|
|
|
+
|
|
|
|
|
'data-deviceid="' + deviceIdentifier + '" data-devicetype="' + deviceType
|
|
|
|
|
+ '" data-devicename="' + row.name + '">' +
|
|
|
|
|
'<span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i>' +
|
|
|
|
|
'<i class="fw fw-delete fw-stack-1x"></i></span>' +
|
|
|
|
|
'<span class="hidden-xs hidden-on-grid-view">Delete</span>';
|
|
|
|
|
'<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view remove-device-link" '
|
|
|
|
|
+
|
|
|
|
|
'data-deviceid="' + deviceIdentifier + '" data-devicetype="' + deviceType
|
|
|
|
|
+ '" data-devicename="' + row.name + '">' +
|
|
|
|
|
'<span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i>' +
|
|
|
|
|
'<i class="fw fw-delete fw-stack-1x"></i></span>' +
|
|
|
|
|
'<span class="hidden-xs hidden-on-grid-view">Delete</span>';
|
|
|
|
|
}
|
|
|
|
|
return html;
|
|
|
|
|
}
|
|
|
|
@ -427,16 +426,16 @@ function loadDevices(searchType, searchParam) {
|
|
|
|
|
|
|
|
|
|
$(data.devices).each(function (index) {
|
|
|
|
|
objects.push(
|
|
|
|
|
{
|
|
|
|
|
model: getPropertyValue(data.devices[index].properties, "DEVICE_MODEL"),
|
|
|
|
|
vendor: getPropertyValue(data.devices[index].properties, "VENDOR"),
|
|
|
|
|
user: data.devices[index].enrolmentInfo.owner,
|
|
|
|
|
status: data.devices[index].enrolmentInfo.status,
|
|
|
|
|
ownership: data.devices[index].enrolmentInfo.ownership,
|
|
|
|
|
deviceType: data.devices[index].type,
|
|
|
|
|
deviceIdentifier: data.devices[index].deviceIdentifier,
|
|
|
|
|
name: data.devices[index].name
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
model: getPropertyValue(data.devices[index].properties, "DEVICE_MODEL"),
|
|
|
|
|
vendor: getPropertyValue(data.devices[index].properties, "VENDOR"),
|
|
|
|
|
user: data.devices[index].enrolmentInfo.owner,
|
|
|
|
|
status: data.devices[index].enrolmentInfo.status,
|
|
|
|
|
ownership: data.devices[index].enrolmentInfo.ownership,
|
|
|
|
|
deviceType: data.devices[index].type,
|
|
|
|
|
deviceIdentifier: data.devices[index].deviceIdentifier,
|
|
|
|
|
name: data.devices[index].name
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -449,20 +448,20 @@ function loadDevices(searchType, searchParam) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$('#device-grid').datatables_extended_serverside_paging(
|
|
|
|
|
null,
|
|
|
|
|
serviceURL,
|
|
|
|
|
dataFilter,
|
|
|
|
|
columns,
|
|
|
|
|
fnCreatedRow,
|
|
|
|
|
function () {
|
|
|
|
|
$(".icon .text").res_text(0.2);
|
|
|
|
|
$('#device-grid').removeClass('hidden');
|
|
|
|
|
$("#loading-content").remove();
|
|
|
|
|
attachDeviceEvents();
|
|
|
|
|
}, {
|
|
|
|
|
"placeholder": "Search By Device Name",
|
|
|
|
|
"searchKey": "name"
|
|
|
|
|
}
|
|
|
|
|
null,
|
|
|
|
|
serviceURL,
|
|
|
|
|
dataFilter,
|
|
|
|
|
columns,
|
|
|
|
|
fnCreatedRow,
|
|
|
|
|
function () {
|
|
|
|
|
$(".icon .text").res_text(0.2);
|
|
|
|
|
$('#device-grid').removeClass('hidden');
|
|
|
|
|
$("#loading-content").remove();
|
|
|
|
|
attachDeviceEvents();
|
|
|
|
|
}, {
|
|
|
|
|
"placeholder": "Search By Device Name",
|
|
|
|
|
"searchKey": "name"
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$(deviceCheckbox).click(function () {
|
|
|
|
@ -556,6 +555,34 @@ function hidePopup() {
|
|
|
|
|
$('.modal-backdrop').remove();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function markAlreadyAssignedGroups(deviceId, deviceType) {
|
|
|
|
|
var successCallback = function (data, textStatus, xhr) {
|
|
|
|
|
data = JSON.parse(data);
|
|
|
|
|
if (xhr.status == 200) {
|
|
|
|
|
if (data.length > 0) {
|
|
|
|
|
for (var i = 0; i < data.length; i++) {
|
|
|
|
|
$('.groupCheckBoxes').each(
|
|
|
|
|
function () {
|
|
|
|
|
if (data[i].id == $(this).data('groupid')) {
|
|
|
|
|
$(this).attr('checked', true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
displayErrors(xhr);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
invokerUtil.get("/api/device-mgt/v1.0/groups/device?deviceId=" + deviceId + "&deviceType=" + deviceType,
|
|
|
|
|
successCallback, function (message) {
|
|
|
|
|
displayErrors(message);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Following functions should be triggered after AJAX request is made.
|
|
|
|
|
*/
|
|
|
|
@ -572,33 +599,58 @@ function attachDeviceEvents() {
|
|
|
|
|
var deviceType = $(this).data("devicetype");
|
|
|
|
|
$(modalPopupContent).html($('#group-device-modal-content').html());
|
|
|
|
|
$('#user-groups').html(
|
|
|
|
|
'<div style="height:100px" data-state="loading" data-loading-text="Loading..." data-loading-style="icon-only" data-loading-inverse="true"></div>');
|
|
|
|
|
'<div style="height:100px" data-state="loading" data-loading-text="Loading..." data-loading-style="icon-only" data-loading-inverse="true"></div>');
|
|
|
|
|
$("a#group-device-yes-link").hide();
|
|
|
|
|
showPopup();
|
|
|
|
|
|
|
|
|
|
var serviceURL;
|
|
|
|
|
if ($.hasPermission("LIST_ALL_GROUPS")) {
|
|
|
|
|
serviceURL = "/api/device-mgt/v1.0/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/user/" + currentUser + "/all";
|
|
|
|
|
serviceURL = "/api/device-mgt/v1.0/groups?limit=100";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
invokerUtil.get(serviceURL, function (data) {
|
|
|
|
|
var groups = JSON.parse(data);
|
|
|
|
|
var str = '<br /><select id="assign-group-selector" style="color:#3f3f3f;padding:5px;width:250px;">';
|
|
|
|
|
var html = '';
|
|
|
|
|
var hasGroups = false;
|
|
|
|
|
for (var i = 0; i < groups.deviceGroups.length; i++) {
|
|
|
|
|
str += '<option value="' + groups.deviceGroups[i].id + '">' +
|
|
|
|
|
groups.deviceGroups[i].name + '</option>';
|
|
|
|
|
if (groups.deviceGroups[i].owner != "wso2.system.user") {
|
|
|
|
|
html += '<div class="wr-input-control"><label class="wr-input-control checkbox">' +
|
|
|
|
|
'<input class="groupCheckBoxes" type="checkbox" data-groupid="' + groups.deviceGroups[i].id + '" />' +
|
|
|
|
|
'<span class="helper" title="' + groups.deviceGroups[i].name + '">' + groups.deviceGroups[i].name +
|
|
|
|
|
'</span></label></div>';
|
|
|
|
|
hasGroups = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (hasGroups) {
|
|
|
|
|
html = '<br/><h4>Please select device group(s)</h4><br/>' + html;
|
|
|
|
|
markAlreadyAssignedGroups(deviceId, deviceType);
|
|
|
|
|
$("a#group-device-yes-link").show();
|
|
|
|
|
$("a#group-add-link").hide();
|
|
|
|
|
} else {
|
|
|
|
|
$("a#group-device-yes-link").hide();
|
|
|
|
|
$("a#group-add-link").show();
|
|
|
|
|
html += '<br/><h4>You don\'t have any existing device groups. Please add new device group first.</h4>'
|
|
|
|
|
}
|
|
|
|
|
str += '</select>';
|
|
|
|
|
$('#user-groups').html(str);
|
|
|
|
|
$("a#group-device-yes-link").show();
|
|
|
|
|
$('#user-groups').html(html);
|
|
|
|
|
$("a#group-device-yes-link").click(function () {
|
|
|
|
|
var selectedGroup = $('#assign-group-selector').val();
|
|
|
|
|
serviceURL = "/api/device-mgt/v1.0/groups/id/" + selectedGroup + "/devices/add";
|
|
|
|
|
var deviceIdentifiers = [{"id": deviceId, "type": deviceType}];
|
|
|
|
|
invokerUtil.post(serviceURL, deviceIdentifiers, function (data) {
|
|
|
|
|
var deviceIdentifier = {"id": deviceId, "type": deviceType};
|
|
|
|
|
var deviceGroupIds = [];
|
|
|
|
|
$('.modal .groupCheckBoxes').each(
|
|
|
|
|
function () {
|
|
|
|
|
if ($(this).is(':checked')) {
|
|
|
|
|
deviceGroupIds.push($(this).data('groupid'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
var deviceToGroupsAssignment = {
|
|
|
|
|
deviceIdentifier: deviceIdentifier,
|
|
|
|
|
deviceGroupIds: deviceGroupIds
|
|
|
|
|
};
|
|
|
|
|
serviceURL = "/api/device-mgt/v1.0/groups/device/assign";
|
|
|
|
|
invokerUtil.post(serviceURL, deviceToGroupsAssignment, function (data) {
|
|
|
|
|
$(modalPopupContent).html($('#group-associate-device-200-content').html());
|
|
|
|
|
setTimeout(function () {
|
|
|
|
|
hidePopup();
|
|
|
|
@ -640,8 +692,8 @@ function attachDeviceEvents() {
|
|
|
|
|
showPopup();
|
|
|
|
|
|
|
|
|
|
$("a#remove-device-yes-link").click(function () {
|
|
|
|
|
if(groupId && groupName) {
|
|
|
|
|
var deviceIdentifiers = [{"id": deviceId,"type": deviceType}];
|
|
|
|
|
if (groupId) {
|
|
|
|
|
var deviceIdentifiers = [{"id": deviceId, "type": deviceType}];
|
|
|
|
|
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());
|
|
|
|
@ -733,6 +785,6 @@ function displayDeviceErrors(jqXHR) {
|
|
|
|
|
function getParameterByName(name) {
|
|
|
|
|
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
|
|
|
|
|
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
|
|
|
|
|
results = regex.exec(location.search);
|
|
|
|
|
results = regex.exec(location.search);
|
|
|
|
|
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
|
|
|
|
|
}
|
|
|
|
|