diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/group-listing.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/group-listing.js
index 96820097..6906a242 100644
--- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/group-listing.js
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/group-listing.js
@@ -1,12 +1,17 @@
function onRequest(context){
- //var userModule = require("/modules/user.js").userModule;
var permissions = [];
- //if(userModule.isAuthorized("/permission/device-mgt/admin/devices/list")){
+ //var userModule = require("/modules/user.js").userModule;
+ //if(userModule.isAuthorized("/permission/device-mgt/admin/groups/list")){
// permissions.push("LIST_GROUPS");
- //}else if(userModule.isAuthorized("/permission/device-mgt/user/devices/list")){
- // permissions.push("LIST_OWN_GROUPS");
+ //}else if(userModule.isAuthorized("/permission/device-mgt/groups/remove")){
+ // permissions.push("REMOVE_GROUPS");
+ //}else if(userModule.isAuthorized("/permission/device-mgt/groups/share")){
+ // permissions.push("SHARE_GROUPS");
//}
permissions.push("LIST_GROUPS");
+ permissions.push("ADD_GROUPS");
+ permissions.push("SHARE_GROUPS");
context.permissions = stringify(permissions);
+ context.SHARE_GROUPS = true;
return context;
}
\ No newline at end of file
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/js/group-listing.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/js/group-listing.js
index d6e7ba65..70414fd8 100644
--- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/js/group-listing.js
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/js/group-listing.js
@@ -245,11 +245,11 @@ function attachGroupAdding() {
var status = jqxhr.status;
if (status == 200) {
if (data != "false") {
- $(modalPopupContent).html($('#add-group-200-content').html());
- $("a#add-group-200-link").click(function () {
- hidePopup();
- location.reload();
- });
+ $(modalPopupContent).html($('#add-group-200-content').html());
+ $("a#add-group-200-link").click(function () {
+ hidePopup();
+ location.reload();
+ });
} else {
$(modalPopupContent).html($('#group-400-content').html());
$("a#group-400-link").click(function () {
@@ -293,6 +293,83 @@ function attachGroupAdding() {
* 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.view-group-link").click(function () {
+ $("#group_data").closest('form').submit();
+ });
+
+ /**
+ * 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");
+ var shareGroupApi = "/iotserver/api/group/id/" + groupId + "/share";
+ var unShareGroupApi = "/iotserver/api/group/id/" + groupId + "/unshare";
+
+ $(modalPopupContent).html($('#share-group-modal-content').html());
+ showPopup();
+
+ $("a#share-group-share-link").click(function () {
+ var data = {"shareUser":"", "role":""};
+ invokerUtil.post(
+ shareGroupApi,
+ data,
+ function (data, txtStatus, jqxhr) {
+ var status = jqxhr.status;
+ if (status == 200) {
+
+ } else {
+ displayErrors(status);
+ }
+ },
+ function () {
+ $(modalPopupContent).html($('#group-unexpected-error-content').html());
+ $("a#group-unexpected-error-link").click(function () {
+ hidePopup();
+ });
+ }
+ );
+ });
+
+ $("a#share-group-unshare-link").click(function () {
+ var data = {"shareUser":"", "role":""};
+ invokerUtil.post(
+ unShareGroupApi,
+ data,
+ function (data, txtStatus, jqxhr) {
+ var status = jqxhr.status;
+ if (status == 200) {
+
+ } else {
+ displayErrors(status);
+ }
+ },
+ function () {
+ $(modalPopupContent).html($('#group-unexpected-error-content').html());
+ $("a#group-unexpected-error-link").click(function () {
+ hidePopup();
+ });
+ }
+ );
+ });
+
+ $("a#share-group-yes-link").click(function () {
+ hidePopup();
+ location.reload();
+ });
+
+ $("a#share-group-cancel-link").click(function () {
+ hidePopup();
+ });
+
+ });
+
/**
* Following click function would execute
* when a user clicks on "Remove" link
@@ -324,26 +401,13 @@ function attachEvents() {
hidePopup();
});
}
- } else if (status == 400) {
- $(modalPopupContent).html($('#group-400-content').html());
- $("a#remove-group-400-link").click(function () {
- hidePopup();
- });
- } else if (status == 403) {
- $(modalPopupContent).html($('#group-403-content').html());
- $("a#remove-group-403-link").click(function () {
- hidePopup();
- });
- } else if (status == 409) {
- $(modalPopupContent).html($('#group-409-content').html());
- $("a#remove-group-409-link").click(function () {
- hidePopup();
- });
+ } else {
+ displayErrors(status);
}
},
function () {
$(modalPopupContent).html($('#group-unexpected-error-content').html());
- $("a#remove-group-unexpected-error-link").click(function () {
+ $("a#group-unexpected-error-link").click(function () {
hidePopup();
});
}
@@ -387,7 +451,6 @@ function attachEvents() {
$("div[data-groupid='" + groupId + "'] .ast-name").html(newGroupName);
$("a#edit-group-200-link").click(function () {
hidePopup();
- location.reload();
});
} else {
$(modalPopupContent).html($('#group-409-content').html());
@@ -395,21 +458,8 @@ function attachEvents() {
hidePopup();
});
}
- } else 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();
- });
+ } else {
+ displayErrors(status);
}
},
function () {
@@ -426,3 +476,22 @@ function attachEvents() {
});
});
}
+
+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();
+ });
+ }
+}
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/templates/group-listing.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/templates/group-listing.hbs
index 14080028..844645b9 100644
--- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/templates/group-listing.hbs
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/templates/group-listing.hbs
@@ -1,5 +1,14 @@
{{#each groups}}
- {{groupMap this}}
+ {{groupMap this}}
+
+