|
|
@ -16,7 +16,7 @@
|
|
|
|
* under the License.
|
|
|
|
* under the License.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
var groupId, user;
|
|
|
|
var groupId, username;
|
|
|
|
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
(function () {
|
|
|
|
var cache = {};
|
|
|
|
var cache = {};
|
|
|
@ -39,7 +39,7 @@ var groupId, user;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
Handlebars.registerHelper("if_owner", function (owner, opts) {
|
|
|
|
Handlebars.registerHelper("if_owner", function (owner, opts) {
|
|
|
|
if (owner == user) {
|
|
|
|
if (owner == username) {
|
|
|
|
return opts.fn(this);
|
|
|
|
return opts.fn(this);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
opts.inverse(this);
|
|
|
|
opts.inverse(this);
|
|
|
@ -72,7 +72,7 @@ $(document).ready(function () {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var i;
|
|
|
|
var i;
|
|
|
|
user = $("#permission").data("user");
|
|
|
|
username = $("#permission").data("user");
|
|
|
|
var permissionList = $("#permission").data("permission");
|
|
|
|
var permissionList = $("#permission").data("permission");
|
|
|
|
for (i = 0; i < permissionList.length; i++) {
|
|
|
|
for (i = 0; i < permissionList.length; i++) {
|
|
|
|
$.setPermission(permissionList[i]);
|
|
|
|
$.setPermission(permissionList[i]);
|
|
|
@ -88,6 +88,7 @@ $(document).ready(function () {
|
|
|
|
|
|
|
|
|
|
|
|
groupId = $("#request-group-id").data("groupid");
|
|
|
|
groupId = $("#request-group-id").data("groupid");
|
|
|
|
loadDevices();
|
|
|
|
loadDevices();
|
|
|
|
|
|
|
|
attachGroupAdding();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
@ -125,9 +126,9 @@ function changeDeviceView(view, selection) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$(selection).addClass("selected");
|
|
|
|
$(selection).addClass("selected");
|
|
|
|
if (view == "list") {
|
|
|
|
if (view == "list") {
|
|
|
|
$(assetContainerParent).addClass("list-view");
|
|
|
|
$(".ast-container .devices-set").addClass("list-view");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$(assetContainerParent).removeClass("list-view");
|
|
|
|
$(".ast-container .devices-set").removeClass("list-view");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -463,3 +464,294 @@ function attachEvents() {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var errorHandler = function () {
|
|
|
|
|
|
|
|
$(modalPopupContent).html($('#add-group-unexpected-error-content').html());
|
|
|
|
|
|
|
|
$("a#group-unexpected-error-link").click(function () {
|
|
|
|
|
|
|
|
hidePopup();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function attachGroupAdding() {
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Following click function would execute
|
|
|
|
|
|
|
|
* when a user clicks on "Remove" link
|
|
|
|
|
|
|
|
* on Group Management page in WSO2 IoT Server Console.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
$("a.add-group-link").click(function () {
|
|
|
|
|
|
|
|
var addGroupApi = "/iotserver/api/group/add";
|
|
|
|
|
|
|
|
$(modalPopupContent).html($('#add-group-modal-content').html());
|
|
|
|
|
|
|
|
showPopup();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$("a#add-group-yes-link").click(function () {
|
|
|
|
|
|
|
|
var newGroupName = $('#add-group-name').val();
|
|
|
|
|
|
|
|
var newGroupDescription = $('#add-group-description').val();
|
|
|
|
|
|
|
|
var group = {"name": newGroupName, "description": newGroupDescription};
|
|
|
|
|
|
|
|
invokerUtil.post(
|
|
|
|
|
|
|
|
addGroupApi,
|
|
|
|
|
|
|
|
group,
|
|
|
|
|
|
|
|
function (data, txtStatus, jqxhr) {
|
|
|
|
|
|
|
|
var status = jqxhr.status;
|
|
|
|
|
|
|
|
if (status == 200) {
|
|
|
|
|
|
|
|
if (data != "false") {
|
|
|
|
|
|
|
|
$(modalPopupContent).html($('#add-group-200-content').html());
|
|
|
|
|
|
|
|
loadDevices();
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
|
|
|
|
hidePopup();
|
|
|
|
|
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$(modalPopupContent).html($('#group-400-content').html());
|
|
|
|
|
|
|
|
$("a#group-400-link").click(function () {
|
|
|
|
|
|
|
|
hidePopup();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (status == 400) {
|
|
|
|
|
|
|
|
$(modalPopupContent).html($('#group-400-content').html());
|
|
|
|
|
|
|
|
$("a#group-400-link").click(function () {
|
|
|
|
|
|
|
|
hidePopup();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else if (status == 403) {
|
|
|
|
|
|
|
|
$(modalPopupContent).html($('#agroup-403-content').html());
|
|
|
|
|
|
|
|
$("a#group-403-link").click(function () {
|
|
|
|
|
|
|
|
hidePopup();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else if (status == 409) {
|
|
|
|
|
|
|
|
$(modalPopupContent).html($('#group-409-content').html());
|
|
|
|
|
|
|
|
$("a#group-409-link").click(function () {
|
|
|
|
|
|
|
|
hidePopup();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, errorHandler
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$("a#add-group-cancel-link").click(function () {
|
|
|
|
|
|
|
|
hidePopup();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Following functions should be triggered after AJAX request is made.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
function attachEvents() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Following click function would execute
|
|
|
|
|
|
|
|
* when a user clicks on "Share" link
|
|
|
|
|
|
|
|
* on Group Management page in WSO2 IoT Server Console.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
$("a.share-group-link").click(function () {
|
|
|
|
|
|
|
|
var groupId = $(this).data("groupid");
|
|
|
|
|
|
|
|
$(modalPopupContent).html($('#share-group-w1-modal-content').html());
|
|
|
|
|
|
|
|
$('#user-names').html('Loading...');
|
|
|
|
|
|
|
|
showPopup();
|
|
|
|
|
|
|
|
$("a#share-group-next-link").hide();
|
|
|
|
|
|
|
|
invokerUtil.get("/iotserver/api/users",
|
|
|
|
|
|
|
|
function (data, txtStatus, jqxhr) {
|
|
|
|
|
|
|
|
var users = JSON.parse(data);
|
|
|
|
|
|
|
|
var status = jqxhr.status;
|
|
|
|
|
|
|
|
if (status == 200) {
|
|
|
|
|
|
|
|
var str = '<br /><select id="share-user-selector" style="color:#3f3f3f;padding:5px;width:250px;">';
|
|
|
|
|
|
|
|
var hasUsers = false;
|
|
|
|
|
|
|
|
for (var user in users) {
|
|
|
|
|
|
|
|
if (users[user].username != username) {
|
|
|
|
|
|
|
|
str += '<option value="' + users[user].username + '">' + users[user].username + '</option>';
|
|
|
|
|
|
|
|
hasUsers = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
str += '</select>';
|
|
|
|
|
|
|
|
if (!hasUsers) {
|
|
|
|
|
|
|
|
str = "There is no any other users registered";
|
|
|
|
|
|
|
|
$('#user-names').html(str);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#user-names').html(str);
|
|
|
|
|
|
|
|
$("a#share-group-next-link").show();
|
|
|
|
|
|
|
|
$("a#share-group-next-link").click(function () {
|
|
|
|
|
|
|
|
var selectedUser = $('#share-user-selector').val();
|
|
|
|
|
|
|
|
$(modalPopupContent).html($('#share-group-w2-modal-content').html());
|
|
|
|
|
|
|
|
$('#user-roles').html('Loading...');
|
|
|
|
|
|
|
|
$("a#share-group-yes-link").hide();
|
|
|
|
|
|
|
|
invokerUtil.get("/iotserver/api/group/id/" + groupId + "/" + selectedUser + "/rolemapping",
|
|
|
|
|
|
|
|
function (data, txtStatus, jqxhr) {
|
|
|
|
|
|
|
|
var roleMap = JSON.parse(data);
|
|
|
|
|
|
|
|
var status = jqxhr.status;
|
|
|
|
|
|
|
|
if (status == 200) {
|
|
|
|
|
|
|
|
var str = '';
|
|
|
|
|
|
|
|
var isChecked = '';
|
|
|
|
|
|
|
|
var hasRoles = false;
|
|
|
|
|
|
|
|
for (var role in roleMap) {
|
|
|
|
|
|
|
|
if (roleMap[role].assigned == true) {
|
|
|
|
|
|
|
|
isChecked = 'checked';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
str += '<label class="checkbox-text"><input type="checkbox" id="user-role-' + roleMap[role].role + '" value="' + roleMap[role].role
|
|
|
|
|
|
|
|
+ '" ' + isChecked + '/>' + roleMap[role].role + '</label> ';
|
|
|
|
|
|
|
|
hasRoles = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hasRoles) {
|
|
|
|
|
|
|
|
str = "There is no any roles for this group";
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#user-roles').html(str);
|
|
|
|
|
|
|
|
$("a#share-group-yes-link").show();
|
|
|
|
|
|
|
|
$("a#share-group-yes-link").click(function () {
|
|
|
|
|
|
|
|
var updatedRoleMap = [];
|
|
|
|
|
|
|
|
for (var role in roleMap) {
|
|
|
|
|
|
|
|
if ($('#user-role-' + roleMap[role].role).is(':checked') != roleMap[role].assigned) {
|
|
|
|
|
|
|
|
roleMap[role].assigned = $('#user-role-' + roleMap[role].role).is(':checked');
|
|
|
|
|
|
|
|
updatedRoleMap.push(roleMap[role]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
invokerUtil.post("/iotserver/api/group/id/" + groupId + "/" + selectedUser + "/roleupdate",
|
|
|
|
|
|
|
|
updatedRoleMap,
|
|
|
|
|
|
|
|
function (data, txtStatus, jqxhr) {
|
|
|
|
|
|
|
|
var status = jqxhr.status;
|
|
|
|
|
|
|
|
if (status == 200) {
|
|
|
|
|
|
|
|
$(modalPopupContent).html($('#share-group-200-content').html());
|
|
|
|
|
|
|
|
loadDevices();
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
|
|
|
|
hidePopup();
|
|
|
|
|
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
displayErrors(status);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, errorHandler);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
displayErrors(status);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, errorHandler);
|
|
|
|
|
|
|
|
$("a#share-group-w2-cancel-link").click(function () {
|
|
|
|
|
|
|
|
hidePopup();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
displayErrors(status);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, errorHandler);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$("a#share-group-w1-cancel-link").click(function () {
|
|
|
|
|
|
|
|
hidePopup();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Following click function would execute
|
|
|
|
|
|
|
|
* when a user clicks on "Remove" link
|
|
|
|
|
|
|
|
* on Group Management page in WSO2 IoT Server Console.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
$("a.remove-group-link").click(function () {
|
|
|
|
|
|
|
|
var groupId = $(this).data("groupid");
|
|
|
|
|
|
|
|
var removeGroupApi = "/iotserver/api/group/id/" + groupId + "/remove";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$(modalPopupContent).html($('#remove-group-modal-content').html());
|
|
|
|
|
|
|
|
showPopup();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$("a#remove-group-yes-link").click(function () {
|
|
|
|
|
|
|
|
invokerUtil.delete(
|
|
|
|
|
|
|
|
removeGroupApi,
|
|
|
|
|
|
|
|
function (data, txtStatus, jqxhr) {
|
|
|
|
|
|
|
|
var status = jqxhr.status;
|
|
|
|
|
|
|
|
if (status == 200) {
|
|
|
|
|
|
|
|
$(modalPopupContent).html($('#remove-group-200-content').html());
|
|
|
|
|
|
|
|
loadDevices();
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
|
|
|
|
hidePopup();
|
|
|
|
|
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
displayErrors(status);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
function () {
|
|
|
|
|
|
|
|
$(modalPopupContent).html($('#group-unexpected-error-content').html());
|
|
|
|
|
|
|
|
$("a#group-unexpected-error-link").click(function () {
|
|
|
|
|
|
|
|
hidePopup();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$("a#remove-group-cancel-link").click(function () {
|
|
|
|
|
|
|
|
hidePopup();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Following click function would execute
|
|
|
|
|
|
|
|
* when a user clicks on "Edit" link
|
|
|
|
|
|
|
|
* on Device Management page in WSO2 MDM Console.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
$("a.edit-group-link").click(function () {
|
|
|
|
|
|
|
|
var groupId = $(this).data("groupid");
|
|
|
|
|
|
|
|
var groupName = $(this).data("groupname");
|
|
|
|
|
|
|
|
var groupDescription = $(this).data("groupdescription");
|
|
|
|
|
|
|
|
var editGroupApi = "/iotserver/api/group/id/" + groupId + "/update";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$(modalPopupContent).html($('#edit-group-modal-content').html());
|
|
|
|
|
|
|
|
$('#edit-group-name').val(groupName);
|
|
|
|
|
|
|
|
$('#edit-group-description').val(groupDescription);
|
|
|
|
|
|
|
|
showPopup();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$("a#edit-group-yes-link").click(function () {
|
|
|
|
|
|
|
|
var newGroupName = $('#edit-group-name').val();
|
|
|
|
|
|
|
|
var newGroupDescription = $('#edit-group-description').val();
|
|
|
|
|
|
|
|
var group = {"name": newGroupName, "description": newGroupDescription};
|
|
|
|
|
|
|
|
invokerUtil.post(
|
|
|
|
|
|
|
|
editGroupApi,
|
|
|
|
|
|
|
|
group,
|
|
|
|
|
|
|
|
function (data, txtStatus, jqxhr) {
|
|
|
|
|
|
|
|
var status = jqxhr.status;
|
|
|
|
|
|
|
|
if (status == 200) {
|
|
|
|
|
|
|
|
if (data != "false") {
|
|
|
|
|
|
|
|
$(modalPopupContent).html($('#edit-group-200-content').html());
|
|
|
|
|
|
|
|
loadDevices();
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
|
|
|
|
hidePopup();
|
|
|
|
|
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$(modalPopupContent).html($('#group-409-content').html());
|
|
|
|
|
|
|
|
$("a#group-409-link").click(function () {
|
|
|
|
|
|
|
|
hidePopup();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
displayErrors(status);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
function () {
|
|
|
|
|
|
|
|
$(modalPopupContent).html($('#group-unexpected-error-content').html());
|
|
|
|
|
|
|
|
$("a#group-unexpected-error-link").click(function () {
|
|
|
|
|
|
|
|
hidePopup();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$("a#edit-group-cancel-link").click(function () {
|
|
|
|
|
|
|
|
hidePopup();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function displayErrors(status) {
|
|
|
|
|
|
|
|
if (status == 400) {
|
|
|
|
|
|
|
|
$(modalPopupContent).html($('#group-400-content').html());
|
|
|
|
|
|
|
|
$("a#group-400-link").click(function () {
|
|
|
|
|
|
|
|
hidePopup();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else if (status == 403) {
|
|
|
|
|
|
|
|
$(modalPopupContent).html($('#group-403-content').html());
|
|
|
|
|
|
|
|
$("a#group-403-link").click(function () {
|
|
|
|
|
|
|
|
hidePopup();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else if (status == 409) {
|
|
|
|
|
|
|
|
$(modalPopupContent).html($('#group-409-content').html());
|
|
|
|
|
|
|
|
$("a#group-409-link").click(function () {
|
|
|
|
|
|
|
|
hidePopup();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|