From b83441fec2cd728e2787c5fa0d84d7ac2ecd6370 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sat, 31 Dec 2011 14:44:19 +0000 Subject: [PATCH] fix js bean role mapping when users are array or not git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1226095 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/webapp/js/archiva/utils.js | 21 ++++++++----------- .../src/main/webapp/js/redback/roles.js | 16 +++++++------- .../js/redback/templates/roles-tmpl.html | 8 +++---- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js index 43697d267..813e27b40 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js @@ -179,17 +179,14 @@ openDialogConfirmui=function(okFn, okMessage, cancelMessage, title){ } mapStringArray=function(data){ - //if (data){ - if ($.isArray(data)){ - $.log("isArray"); - return $.map(data,function(item){ - return item; - }); - } else { - $.log("not Array"); - return new Array(data); - } - //} + if ($.isArray(data)){ + //$.log("isArray"); + return $.map(data,function(item){ + return item; + }); + } else { + //$.log("not Array"); + return [data]; + } - //return null; } \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/roles.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/roles.js index 58db85e30..4cd1cc1ed 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/roles.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/roles.js @@ -81,7 +81,7 @@ $(function() { displayRolesGrid = function(){ $("#user-messages").html(""); $("#main-content").html(""); - $.ajax("restServices/redbackServices/roleManagementService/allRoles", + $.ajax("restServices/redbackServices/roleManagementService/detailledAllRoles", { type: "GET", dataType: 'json', @@ -89,7 +89,7 @@ $(function() { var roles = $.map(data.role, function(item) { return mapRole(item); }); - $.log(ko.toJSON(roles)); + //$.log(ko.toJSON(roles)); $("#main-content").html($("#rolesTabs").tmpl()); var data = {roles: roles}; $("#main-content #roles-view-tabs-content #roles-view").html($("#rolesGrid").tmpl(data)); @@ -128,20 +128,20 @@ $(function() { */ mapRole=function(data) { // name, description, assignable,childRoleNames,parentRoleNames,users,parentsRolesUsers,permissions - $.log("mapRole:"+data.name+":"); + //$.log("mapRole:"+data.name+":"); var childRoleNames = mapStringArray(data.childRoleNames); var parentRoleNames = mapStringArray(data.parentRoleNames); - var users = data.users ? $.map(data.users, function(item) { + var users = data.users ? $.isArray(data.users) ? $.map(data.users, function(item) { return mapUser(item); - }):null; + }):[mapUser(data.users)]:null; - var parentsRolesUsers = data.parentsRolesUsers ? $.map(data.parentsRolesUsers, function(item) { + var parentsRolesUsers = data.parentsRolesUsers ? $.isArray(data.parentsRolesUsers)? $.map(data.parentsRolesUsers, function(item) { return mapUser(item); - }):null; + }):[mapUser(data.parentsRolesUsers)]:null; var permissions = data.permissions? $.isArray(data.permissions) ? $.map(data.permissions, function(item){ return mapPermission(item); - }): new Array(mapPermission(data.permissions)) :null; + }): [mapPermission(data.permissions)] :null; return new role(data.name, data.description,data.assignable,childRoleNames,parentRoleNames,users,parentsRolesUsers,permissions); } diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/templates/roles-tmpl.html b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/templates/roles-tmpl.html index 8d8c05db1..5d0e1748b 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/templates/roles-tmpl.html +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/templates/roles-tmpl.html @@ -69,14 +69,14 @@ - {{if parentRoleNames()}} + {{if parentRoleNames}} {{/if}} -- 2.39.5