From cfd88272a0deab3456433f1f6ce79dd1afbf5245 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 6 Jan 2012 15:00:56 +0000 Subject: [PATCH] move display users roles to a knockout bind to prepare update mode git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1228215 13f79535-47bb-0310-9956-ffa450edef68 --- .../js/redback/templates/user-edit.html | 3 ++- .../js/redback/templates/user-grids.html | 4 ++- .../src/main/webapp/js/redback/users.js | 26 ++++++++++++------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/templates/user-edit.html b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/templates/user-edit.html index 0c7c74d84..4406ac41e 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/templates/user-edit.html +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/templates/user-edit.html @@ -61,10 +61,11 @@ - diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/templates/user-grids.html b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/templates/user-grids.html index 448789e3a..34b824832 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/templates/user-grids.html +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/templates/user-grids.html @@ -99,6 +99,8 @@ diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/users.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/users.js index 10db0e571..4ef9bfbbc 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/users.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/users.js @@ -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"); -- 2.39.5