]> source.dussan.org Git - archiva.git/commitdiff
move display users roles to a knockout bind to prepare update mode
authorOlivier Lamy <olamy@apache.org>
Fri, 6 Jan 2012 15:00:56 +0000 (15:00 +0000)
committerOlivier Lamy <olamy@apache.org>
Fri, 6 Jan 2012 15:00:56 +0000 (15:00 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1228215 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/templates/user-edit.html
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/templates/user-grids.html
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/users.js

index 0c7c74d84174118d52f9eca9bfab578ae8377769..4406ac41ecb69686069e13d32773cd94cca83465 100644 (file)
       <button class="btn" id="user-create-form-cancel-button">${i18n('cancel')}</button>
     </form>
     </div>
-    <div class="span6 columns" id="user-edit-roles-view" style="display:none">
+    <div class="span6 columns" id="user-edit-roles" style="display:none">
       <div class="page-header">
         <h3>${$.i18n.prop('effective.roles')}</h3>
       </div>
+      <div id="user-edit-roles-view"></div>
     </div>
   </div>
 
index 448789e3af4c4cd255c7c94f8c95a036fd80fc1e..34b824832f6dd605dba44d23ec48f5bf9871312e 100644 (file)
@@ -99,6 +99,8 @@
 
 <script id="user_edit_roles_tmpl" type="text/x-jquery-tmpl">
   <ul>
-    ${name}
+    {{each $data.roles}}
+      <li>${$value.name}</li>
+    {{/each}}
   </ul>
 </script>
index 10db0e571ef831605914a1b29dbf828d1d95df67..4ef9bfbbc6c23532d84de047afa1a9b4aa16710b 100644 (file)
@@ -61,7 +61,7 @@ $(function() {
       window.redbackModel.createUser=true;
       $("#main-content #user-edit").remove();
       $('#main-content #user-create').show();
-      ko.renderTemplate("redback/user-edit-tmpl", new user(), null, $("#createUserForm").get(0),"replaceChildren");
+      ko.renderTemplate("redback/user-edit-tmpl", new User(), null, $("#createUserForm").get(0),"replaceChildren");
       $("#main-content #createUserForm #user-create").delegate("#user-create-form-cancel-button", "click keydown", function(e) {
         e.preventDefault();
         activateUsersGridTab();
@@ -146,13 +146,22 @@ $(function() {
         user.update();
       });
 
-      $.ajax("restServices/redbackServices/roleManagementService/getEffectivelyAssignedRoles/"+user.username(), {
+      $("#user-edit-roles").show();
+      $( "#user-edit-roles-view" ).append(smallSpinnerImg());
+      $.ajax("restServices/redbackServices/roleManagementService/getEffectivelyAssignedRoles/"+encodeURIComponent(user.username()), {
           type: "GET",
           async: false,
           dataType: 'json',
           success: function(data) {
-            $( "#user-edit-roles-view" ).append( jQuery("#user_edit_roles_tmpl" ).tmpl( data.role ) );
             $("#user-edit-roles-view").show();
+            var mappedRoles = $.map(data.role, function(item) {
+              return mapRole(item);
+            });
+            //$( "#user-edit-roles-view" ).append( jQuery("#user_edit_roles_tmpl" ).tmpl( data.role ) );
+            viewModel.roles=mappedRoles;
+            $( "#user-edit-roles-view").attr("data-bind",'template: {name:"user_edit_roles_tmpl"}');
+            ko.applyBindings(viewModel,$("#user-edit-roles-view").get(0));
+            removeSmallSpinnerImg();
           }
         }
       );
@@ -160,6 +169,11 @@ $(function() {
     }
   }
 
+  userViewModel=function(user) {
+    this.user=user;
+    this.roles = ko.observableArray(new Array());
+  }
+
   /**
    * called from the menu to display tabs with users grid
     */
@@ -185,12 +199,6 @@ $(function() {
     $("#users-view-tabs-content #users-view").addClass("active");
   }
 
-
-
-  userViewModel=function(user) {
-      this.user=user;
-  }
-
   activateUsersGridTab=function(){
     $("#main-content #users-view-tabs li").removeClass("active");
     $("#main-content #users-view-tabs-content div").removeClass("active");