]> source.dussan.org Git - archiva.git/commitdiff
start moving role edition to use knockout with adding bean mapping
authorOlivier Lamy <olamy@apache.org>
Sat, 31 Dec 2011 13:55:46 +0000 (13:55 +0000)
committerOlivier Lamy <olamy@apache.org>
Sat, 31 Dec 2011 13:55:46 +0000 (13:55 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1226092 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/index.html
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js
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/operation.js
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/permission.js [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/resource.js [new file with mode: 0644]
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
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/users.js

index d3969b9db5c6c1ee2f75f44c756bccbd29e5cca5..a6702913362bdf5f903fb58ecc4bf4ae79caaa5c 100644 (file)
@@ -64,6 +64,8 @@
        .script("redback/users.js").wait()
        .script("redback/redback.js").wait()
        .script("redback/register.js").wait()
+       .script("redback/permission.js").wait()
+       .script("redback/resource.js").wait()
        .script("redback/roles.js").wait()
        .script("archiva/main.js");
 
index 1e6a93b58216e356aa66310dd9af0f87fb3ebfe3..7264fc5164e67ca9b298b4b0e7132b46461b0f60 100644 (file)
@@ -79,7 +79,7 @@ $(function() {
               return mapOperation(item);
           });
           window.redbackModel.operatioNames = $.map(mappedOperations, function(item){
-            return item.name;
+            return item.name();
           });
 
           $("[redback-permissions]").each(function(element){
@@ -88,7 +88,6 @@ $(function() {
             var neededKarmas = $(eval(bindingValue)).toArray();
             var karmaOk = false;
             $(neededKarmas).each(function(value){
-              //alert(neededKarmas[value]);
               if ($.inArray(neededKarmas[value],window.redbackModel.operatioNames)>=0) {
                 karmaOk = true;
               }
index ff39934b8eed494d4c236fba40e462a9e0c2386e..43697d267743c4467a02afd54af7e539805d78f5 100644 (file)
@@ -176,4 +176,20 @@ 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);
+    }
+  //}
+
+  //return null;
 }
\ No newline at end of file
index f91109e961acff9baf546dca16824a4c9db0ee50..9f31787ba28069d75271fbe0eeb2967cac8c1070 100644 (file)
@@ -20,7 +20,7 @@ $(function() {
 
 
   operation=function(name) {
-    this.name=name;
+    this.name=ko.observable(name);
   }
 
   /**
diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/permission.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/permission.js
new file mode 100644 (file)
index 0000000..cc3da08
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+$(function() {
+
+
+  permission=function(name,operation,resource) {
+    this.name=ko.observable(name);
+    this.operation=ko.observable(operation);
+    this.resource=ko.observable(resource);
+  }
+
+  /**
+   * @param data Permission response from redback rest api
+   */
+  mapPermission=function(data) {
+    return new permission(data.name,
+                          data.operation?mapOperation(data.operation):null,
+                          data.resource?mapResource(data.resource):null);
+  }
+
+
+});
\ No newline at end of file
diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/resource.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/resource.js
new file mode 100644 (file)
index 0000000..9fd19c3
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+$(function() {
+
+
+  resource=function(identifier,pattern) {
+    this.identifier=ko.observable(identifier);
+    this.pattern=ko.observable(pattern);
+  }
+
+  /**
+   * @param data Resource response from redback rest api
+   */
+  mapResource=function(data) {
+    return new resource(data.identifier,data.pattern);
+  }
+
+
+});
\ No newline at end of file
index 4bdb74a59a5327428e7018e101066acb98a0e0bc..da018b3a561bad090b768b605dbeaa0d3bccbe4b 100644 (file)
  */
 $(function() {
 
-  role = function(name,description,permissions){
-    this.name = name;
-    this.description = description;
-    this.permissions=permissions;
-  }
+  role = function(name,description,assignable,childRoleNames,parentRoleNames,users,parentsRolesUsers,permissions){
+    this.name = ko.observable(name);
+    this.description = ko.observable(description);
+    this.assignable = ko.observable(assignable);
+    this.childRoleNames = ko.observableArray(childRoleNames);//read only
+    this.parentRoleNames = ko.observableArray(parentRoleNames);//read only
+    this.users = ko.observableArray(users);
+    this.parentsRolesUsers = ko.observableArray(parentsRolesUsers);//read only
+    this.permissions = ko.observableArray(permissions);//read only
+
+
+
 
-  permission = function(){
 
+
+    this.updateDescription=function(){
+      var url = "restServices/redbackServices/roleManagementService/updateRoleDescription?";
+      var roleName = this.name();
+      url += "roleName="+encodeURIComponent(roleName);
+      url += "&roleDescription="+encodeURIComponent(this.description());
+      $.ajax(url,
+        {
+          type: "GET",
+          dataType: 'json',
+          success: function(data) {
+            $.log("role description updated");
+            displaySuccessMessage($.i18n.prop("role.updated",roleName));
+          },
+          error: function(data){
+            displayErrorMessage("error updating role description");
+          }
+        }
+      );
+    }
   }
 
+
+
   displayRolesGrid = function(){
     $("#user-messages").html("");
     $("#main-content").html("");
@@ -37,11 +65,11 @@ $(function() {
        dataType: 'json',
        success: function(data) {
          var roles = $.map(data.role, function(item) {
-             return mapRole(item);
+           return mapRole(item);
          });
-
+         $.log(ko.toJSON(roles));
          $("#main-content").html($("#rolesTabs").tmpl());
-         $("#main-content #roles-view-tabs-content #roles-view").html($("#rolesGrid").tmpl(data));
+         $("#main-content #roles-view-tabs-content #roles-view").html($("#rolesGrid").tmpl(roles));
          $("#roles-view-tabs").tabs();
          activateRolesGridTab();
        }
@@ -68,22 +96,7 @@ $(function() {
     var roleName = $("#editRoleTable #role-edit-name").html();
     var description = $("#editRoleTable #role-edit-description").val();
     clearUserMessages();
-    var url = "restServices/redbackServices/roleManagementService/updateRoleDescription?";
-    url += "roleName="+encodeURIComponent(roleName);
-    url += "&roleDescription="+encodeURIComponent(description);
-    $.ajax(url,
-      {
-        type: "GET",
-        dataType: 'json',
-        success: function(data) {
-          $.log("role description updated");
-          displaySuccessMessage($.i18n.prop("role.updated",roleName));
-        },
-        error: function(data){
-          displayErrorMessage("error updating role description");
-        }
-      }
-    );
+    new role(roleName,description).updateDescription();
 
   }
 
@@ -91,7 +104,23 @@ $(function() {
    * @param data Role response from redback rest api
    */
   mapRole=function(data) {
-    return new role(data.name, data.description);
+    // name, description, assignable,childRoleNames,parentRoleNames,users,parentsRolesUsers,permissions
+    $.log("mapRole:"+data.name+":");
+    var childRoleNames = mapStringArray(data.childRoleNames);
+    var parentRoleNames = mapStringArray(data.parentRoleNames);
+    var users = data.users ? $.map(data.users, function(item) {
+      return mapUser(item);
+    }):null;
+
+    var parentsRolesUsers = data.parentsRolesUsers ? $.map(data.parentsRolesUsers, function(item) {
+      return mapUser(item);
+    }):null;
+
+    var permissions = data.permissions? $.map(data.permissions, function(item){
+      return mapPermission(item);
+    }):null;
+
+    return new role(data.name, data.description,data.assignable,childRoleNames,parentRoleNames,users,parentsRolesUsers,permissions);
   }
 
   activateRolesGridTab=function(){
index 6401cd91ffae55f94f7049de4182062f1e2a596c..8f7b357e91e8e7a38e5356149a709684c937d8df 100644 (file)
@@ -80,7 +80,7 @@
       {{/if}}
     </ul>
   {{/if}}
-
+  <!--
   <div class="page-header">
     <h3>${$.i18n.prop('role.model.child.roles')}</h3>
   </div>
   {{else}}
     ${$.i18n.prop('role.edit.no.user.defined')}
   {{/if}}
-
+  -->
 </script>
index f0466dc4574b4611e42385a548ba847ad5c16376..61950aee680efd1f42c8c0f21932731adc307d60 100644 (file)
@@ -31,10 +31,10 @@ $(function() {
           async: false,
           dataType: 'json',
           success: function(data) {
-              var mappedUsers = $.map(data.user, function(item) {
-                  return mapUser(item);
-              });
-              self.users(mappedUsers);
+            var mappedUsers = $.map(data.user, function(item) {
+              return mapUser(item);
+            });
+            self.users(mappedUsers);
           }
         }
       );