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