@ -155,33 +155,49 @@ function loadGroups() {
render : function ( id , type , row , meta ) {
render : function ( id , type , row , meta ) {
var html ;
var html ;
if ( $ . hasPermission ( "VIEW_GROUP_DEVICES" ) ) {
if ( $ . hasPermission ( "VIEW_GROUP_DEVICES" ) ) {
html = '<a href="devices?groupId=' + row . groupId + '&groupName=' + row . name + '" data-click-event="remove-form" class="btn padding-reduce-on-grid-view">' +
html = '<a href="devices?groupId=' + row . groupId + '&groupName=' + row . name
'<span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-view fw-stack-1x"></i></span>' +
+ '" data-click-event="remove-form" class="btn padding-reduce-on-grid-view">' +
'<span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-view fw-stack-1x"></i></span>'
+
'<span class="hidden-xs hidden-on-grid-view">View Devices</span></a>' ;
'<span class="hidden-xs hidden-on-grid-view">View Devices</span></a>' ;
html += '<a href="group/' + row . name + '/' + row . groupId + '/analytics" data-click-event="remove-form" class="btn padding-reduce-on-grid-view">' +
html += '<a href="group/' + row . name + '/' + row . groupId
'<span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-statistics fw-stack-1x"></i></span>' +
+ '/analytics" data-click-event="remove-form" class="btn padding-reduce-on-grid-view">' +
'<span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-statistics fw-stack-1x"></i></span>'
+
'<span class="hidden-xs hidden-on-grid-view">Analytics</span></a>' ;
'<span class="hidden-xs hidden-on-grid-view">Analytics</span></a>' ;
} else {
} else {
html = '' ;
html = '' ;
}
}
if ( $ . hasPermission ( "SHARE_GROUP" ) ) {
if ( $ . hasPermission ( "SHARE_GROUP" ) ) {
html += '<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view share-group-link" data-group-id="' + row . groupId + '" ' +
html +=
'data-group-owner="' + row . owner + '"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-share fw-stack-1x"></i></span>' +
'<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view share-group-link" data-group-id="'
+ row . groupId + '" ' +
'data-group-owner="' + row . owner
+ '"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-share fw-stack-1x"></i></span>'
+
'<span class="hidden-xs hidden-on-grid-view">Share</span></a>' ;
'<span class="hidden-xs hidden-on-grid-view">Share</span></a>' ;
} else {
} else {
html += '' ;
html += '' ;
}
}
if ( $ . hasPermission ( "UPDATE_GROUP" ) ) {
if ( $ . hasPermission ( "UPDATE_GROUP" ) ) {
html += '<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view edit-group-link" data-group-name="' + row . name + '" ' +
html +=
'data-group-owner="' + row . owner + '" data-group-description="' + row . description + '" data-group-id="' + row . groupId + '"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i>' +
'<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view edit-group-link" data-group-name="'
+ row . name + '" ' +
'data-group-owner="' + row . owner + '" data-group-description="' + row . description
+ '" data-group-id="' + row . groupId
+ '"><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>' ;
'<i class="fw fw-edit fw-stack-1x"></i></span><span class="hidden-xs hidden-on-grid-view">Edit</span></a>' ;
} else {
} else {
html += '' ;
html += '' ;
}
}
if ( $ . hasPermission ( "REMOVE_GROUP" ) ) {
if ( $ . hasPermission ( "REMOVE_GROUP" ) ) {
html += '<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view remove-group-link" data-group-id="' + row . groupId + '" ' +
html +=
'data-group-owner="' + row . owner + '"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-delete fw-stack-1x"></i>' +
'<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view remove-group-link" data-group-id="'
+ row . groupId + '" ' +
'data-group-owner="' + row . owner
+ '"><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>' ;
'</span><span class="hidden-xs hidden-on-grid-view">Delete</span></a>' ;
} else {
} else {
html += '' ;
html += '' ;
@ -352,33 +368,37 @@ function attachEvents() {
$ ( "a.share-group-link" ) . click ( function ( ) {
$ ( "a.share-group-link" ) . click ( function ( ) {
var groupId = $ ( this ) . data ( "group-id" ) ;
var groupId = $ ( this ) . data ( "group-id" ) ;
var groupOwner = $ ( this ) . data ( "group-owner" ) ;
var groupOwner = $ ( this ) . data ( "group-owner" ) ;
$ ( modalPopupContent ) . html ( $ ( '#share-group-w1-modal-content' ) . html ( ) ) ;
$ ( modalPopupContent ) . html ( $ ( '#share-group-w1-modal-content' ) . html ( ) ) ;
$ ( "a#share-group-next-link" ) . show ( ) ;
showPopup ( ) ;
showPopup ( ) ;
$ ( "a#share-group-next-link" ) . click ( function ( ) {
var successCallback = function ( data ) {
markAlreadySavedUsersRoles ( groupId ) ;
if ( data === 'true' ) {
var shareGroupNextLink = $ ( "a#share-group-next-link" ) ;
getAllRoles ( groupId , selectedUser ) ;
shareGroupNextLink . click ( function ( ) {
} else {
var roles = [ ] ;
var errorMsgWrapper = "#notification-error-msg" ;
$ ( '.modal .roleCheckBoxes' ) . each (
var errorMsg = "#notification-error-msg span" ;
function ( ) {
$ ( errorMsg ) . text ( "User does not exist." ) ;
if ( $ ( this ) . is ( ':checked' ) ) {
$ ( errorMsgWrapper ) . removeClass ( "hidden" ) ;
roles . push ( $ ( this ) . data ( 'role-name' ) ) ;
}
}
}
}
var selectedUser = $ ( '#share-user-selector' ) . val ( ) ;
) ;
if ( selectedUser == $ ( "#group-listing" ) . data ( "current-user" ) ) {
updateGroupShare ( groupId , roles ) ;
$ ( "#user-names" ) . html ( "Please specify a user other than current user." ) ;
$ ( "a#share-group-next-link" ) . hide ( ) ;
} else {
invokerUtil . get ( "/api/device-mgt/v1.0/users/checkUser?username=" + selectedUser ,
successCallback , function ( message ) {
displayErrors ( message ) ;
} ) ;
} ) ;
var shareGroupNewRoleFromSelectionLink = $ ( "a#share-group-new-role-from-selection" ) ;
shareGroupNewRoleFromSelectionLink . click ( function ( ) {
var roles = [ ] ;
$ ( '.modal .roleCheckBoxes' ) . each (
function ( ) {
if ( $ ( this ) . is ( ':checked' ) ) {
roles . push ( $ ( this ) . data ( 'role-name' ) ) ;
}
}
} ) ;
}
$ ( "a#share-group-w1-cancel-link" ) . click ( function ( ) {
) ;
hidePopup ( ) ;
addNewRole ( roles ) ;
// $(modalPopupContent).html($('#share-group-w3-modal-content').html());
// createNewRole(roles);
} ) ;
} ) ;
} ) ;
} ) ;
@ -464,115 +484,40 @@ function attachEvents() {
} ) ;
} ) ;
}
}
function getAllRoles ( groupId , selectedUser ) {
function markAlreadySavedUsersRoles ( groupId ) {
$ ( modalPopupContent ) . html ( $ ( '#share-group-w2-modal-content' ) . html ( ) ) ;
$ ( "a#share-group-yes-link" ) . hide ( ) ;
var successCallback = function ( data , textStatus , xhr ) {
var successCallback = function ( data , textStatus , xhr ) {
data = JSON . parse ( data ) ;
data = JSON . parse ( data ) ;
if ( xhr . status == 200 ) {
if ( xhr . status == 200 ) {
if ( data . roles . length > 0 ) {
if ( data . roles . length > 0 ) {
generateRoleMap ( groupId , selectedUser , data . roles ) ;
for ( var i = 0 ; i < data . roles . length ; i ++ ) {
} else {
$ ( '.roleCheckBoxes' ) . each (
$ ( '#user-roles' ) . html ( "There is no any roles for this group." ) ;
function ( ) {
}
if ( data . roles [ i ] == $ ( this ) . data ( 'role-name' ) ) {
} else {
$ ( this ) . attr ( 'checked' , true ) ;
displayErrors ( xhr ) ;
}
} ;
invokerUtil . get ( "/api/device-mgt/v1.0/groups/id/" + groupId + "/roles" ,
successCallback , function ( message ) {
displayErrors ( message ) ;
} ) ;
$ ( "a#share-group-w2-cancel-link" ) . click ( function ( ) {
hidePopup ( ) ;
} ) ;
}
function generateRoleMap ( groupId , selectedUser , allRoles ) {
var successCallback = function ( data , textStatus , xhr ) {
data = JSON . parse ( data ) ;
if ( xhr . status == 200 ) {
var userRoles = [ ] ;
if ( data != "EMPTY" ) {
userRoles = data . roles ;
}
var str = $ ( '#user-roles' ) . html ( ) ;
for ( var i = 0 ; i < allRoles . length ; i ++ ) {
var isChecked = '' ;
for ( var j = 0 ; j < userRoles . length ; j ++ ) {
if ( allRoles [ i ] == userRoles [ j ] ) {
isChecked = 'checked' ;
break ;
}
}
}
}
str += '<label class="wr-input-control checkbox"><input type="checkbox" class="form-control modal-input operationDataKeys" id="user-role-' + allRoles [ i ] + '" value="' + allRoles [ i ]
) ;
+ '" ' + isChecked + '/>' + '<span class="helper" title="Check to share this group role with user."> ' + allRoles [ i ] + '</span></label><br><br>' ;
}
$ ( '#user-roles' ) . html ( str ) ;
$ ( "a#share-group-yes-link" ) . show ( ) ;
$ ( "a#share-group-yes-link" ) . show ( ) ;
$ ( "a#share-group-yes-link" ) . click ( function ( ) {
var roles = [ ] ;
for ( var i = 0 ; i < allRoles . length ; i ++ ) {
if ( $ ( '#user-role-' + allRoles [ i ] ) . is ( ':checked' ) ) {
roles . push ( allRoles [ i ] ) ;
}
}
} else {
return ;
}
}
updateGroupShare ( groupId , selectedUser , roles ) ;
} ) ;
$ ( "a#share-group-w2-add-new-role-link" ) . click ( function ( ) {
addNewRole ( groupId , selectedUser , allRoles ) ;
} ) ;
} else {
} else {
displayErrors ( xhr ) ;
displayErrors ( xhr ) ;
}
}
} ;
} ;
invokerUtil . get ( "/api/device-mgt/v1.0/groups/id/" + groupId + "/roles ?userName= " + selectedUser ,
invokerUtil . get ( "/api/device-mgt/v1.0/groups/id/" + groupId + "/roles" ,
successCallback , function ( message ) {
successCallback , function ( message ) {
displayErrors ( message ) ;
displayErrors ( message ) ;
} ) ;
} ) ;
$ ( "a#share-group-w2-cancel-link" ) . click ( function ( ) {
hidePopup ( ) ;
} ) ;
}
}
function addNewRole ( g roupId, selectedUser , allR oles) {
function addNewRole ( roles ) {
$ ( modalPopupContent ) . html ( $ ( '#share-group-w3-modal-content' ) . html ( ) ) ;
$ ( modalPopupContent ) . html ( $ ( '#share-group-w3-modal-content' ) . html ( ) ) ;
function getPermissions ( ) {
var PERMISSION _PREFIX = '/permission/admin/' ;
var permissions = [ ] ;
$ ( '#permission-table-container' ) . find ( 'tr' ) . each ( function ( ) {
var row = $ ( this ) . closest ( 'tr' ) ;
var permission = $ ( row ) . find ( 'td:nth-child(1)' ) . text ( ) ;
var check = $ ( row ) . find ( 'td:nth-child(2) a' ) . data ( 'value' ) ;
if ( check === 'checked' ) {
permission = PERMISSION _PREFIX + permission ;
permissions . push ( permission ) ;
}
} ) ;
return permissions ;
} ;
$ ( "a#share-group-w3-yes-link" ) . click ( function ( ) {
$ ( "a#share-group-w3-yes-link" ) . click ( function ( ) {
var successCallback = function ( data , status , jqXHR ) {
if ( status == "success" ) {
getAllRoles ( groupId , selectedUser ) ;
}
}
var roleName = $ ( '#group-sharing-role-name' ) . val ( ) ;
var roleName = $ ( '#group-sharing-role-name' ) . val ( ) ;
var users = [ ] ;
if ( roleName ) {
if ( roleName ) {
var groupRoleInfo = { "roleName" : roleName , "permissions" : getPermissions ( ) , "users" : users } ;
createNewCombinedRole ( roleName , roles ) ;
var currentUser = $ ( "#group-listing" ) . data ( "current-user" ) ;
invokerUtil . post ( "/api/device-mgt/v1.0/groups/id/" + groupId + "/roles/create?userName=" + currentUser ,
groupRoleInfo , successCallback , function ( message ) {
displayErrors ( message ) ;
} ) ;
} else {
} else {
var errorMsgWrapper = "#notification-error-msg" ;
var errorMsgWrapper = "#notification-error-msg" ;
var errorMsg = "#notification-error-msg span" ;
var errorMsg = "#notification-error-msg span" ;
@ -599,7 +544,7 @@ function togglePermissionAction(element) {
}
}
}
}
function updateGroupShare ( groupId , selectedUser, roles) {
function updateGroupShare ( groupId , roles) {
var successCallback = function ( data ) {
var successCallback = function ( data ) {
$ ( modalPopupContent ) . html ( $ ( '#share-group-200-content' ) . html ( ) ) ;
$ ( modalPopupContent ) . html ( $ ( '#share-group-200-content' ) . html ( ) ) ;
setTimeout ( function ( ) {
setTimeout ( function ( ) {
@ -608,9 +553,19 @@ function updateGroupShare(groupId, selectedUser, roles) {
} , 2000 ) ;
} , 2000 ) ;
} ;
} ;
var deviceGroupShare = { "username" : selectedUser , "groupRoles" : roles } ;
invokerUtil . post ( "/api/device-mgt/v1.0/groups/id/" + groupId + "/share" ,
invokerUtil . post ( "/api/device-mgt/v1.0/groups/id/" + groupId + "/share" ,
deviceGroupShare , successCallback , function ( message ) {
roles , successCallback , function ( message ) {
displayErrors ( message ) ;
} ) ;
}
function createNewCombinedRole ( roleName , roleList ) {
var successCallback = function ( data , status , jqXHR , isLast ) {
$ ( modalPopupContent ) . html ( $ ( '#create-combined-role-200-content' ) . html ( ) ) ;
showPopup ( ) ;
} ;
invokerUtil . post ( "/api/device-mgt/v1.0/roles/create-combined-role/" + roleName , roleList ,
successCallback , function ( message ) {
displayErrors ( message ) ;
displayErrors ( message ) ;
} ) ;
} ) ;
}
}