]> source.dussan.org Git - archiva.git/commitdiff
fix js bean role mapping when users are array or not
authorOlivier Lamy <olamy@apache.org>
Sat, 31 Dec 2011 14:44:19 +0000 (14:44 +0000)
committerOlivier Lamy <olamy@apache.org>
Sat, 31 Dec 2011 14:44:19 +0000 (14:44 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1226095 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/roles.js
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/templates/roles-tmpl.html

index 43697d267743c4467a02afd54af7e539805d78f5..813e27b4014a444c8bd322822610e55d0fcadb3d 100644 (file)
@@ -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
index 58db85e30b108ec0ba935a475cffbdc79cdfadd6..4cd1cc1ede6e703dede51731907de3a4c00c98e0 100644 (file)
@@ -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);
   }
index 8d8c05db14c1f50753701cc0af5c91fba7f6907f..5d0e1748b88176dfd0f3439bdce3eb5a49b7fe4f 100644 (file)
   <div class="page-header">
     <h3>${$.i18n.prop('role.model.parent.roles')}</h3>
   </div>
-  {{if parentRoleNames()}}
+  {{if parentRoleNames}}
     <ul>
-      {{if $.isArray(parentRoleNames())}}
-        {{each parentRoleNames()}}
+      {{if $.isArray(parentRoleNames)}}
+        {{each parentRoleNames}}
           <li>${$value}</li>
         {{/each}}
       {{else}}
-        <li>${parentRoleNames()}</li>
+        <li>${parentRoleNames}</li>
       {{/if}}
     </ul>
   {{/if}}