From 82e113d72f03931f20d3d30640ab86cca516b498 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Thu, 12 Jan 2012 14:12:18 +0000 Subject: [PATCH] knockout binding between available roles and user assigned roles git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1230554 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/webapp/js/redback/roles.js | 22 +++++++-------- .../js/redback/templates/user-edit.html | 26 ++++++++++++++++-- .../src/main/webapp/js/redback/users.js | 27 +++++++++++-------- 3 files changed, 51 insertions(+), 24 deletions(-) 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 830206a78..c44ec75ce 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 @@ -259,15 +259,15 @@ $(function() { ApplicationRoles = function(name,description,globalRoles,roleTemplates,resources){ //private String name; - this.name = name; + this.name = ko.observable(name); //private String description; - this.description = description; + this.description = description? ko.observable(description):""; //private Collection globalRoles; - this.globalRoles = globalRoles; + this.globalRoles = ko.observableArray(globalRoles); //private Collection roleTemplates; - this.roleTemplates = roleTemplates; + this.roleTemplates = ko.observableArray(roleTemplates); //private Collection resources; - this.resources = resources; + this.resources = ko.observableArray(resources); } mapApplicationRoles=function(data){ @@ -280,17 +280,17 @@ $(function() { RoleTemplate = function(id,namePrefix,delimiter,description,resource,roles){ //private String id; - this.id = id; + this.id = ko.observable(id); //private String namePrefix; - this.namePrefix = namePrefix; + this.namePrefix = ko.observable(namePrefix); //private String delimiter = " - "; - this.delimiter = delimiter; + this.delimiter = ko.observable(delimiter); //private String description; - this.description = description; + this.description = description? ko.observable(description):""; //private String resource; - this.resource = resource; + this.resource = ko.observable(resource); //private List roles; - this.roles = roles; + this.roles = ko.observableArray(roles); } mapRoleTemplate = function(data){ 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 7e2c7dbbe..94f39d624 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 @@ -84,16 +84,38 @@ - + + 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 e5f69aa2c..3b681b23b 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 @@ -118,9 +118,7 @@ $(function() { window.redbackModel.createUser=false; clearUserMessages(); activateUsersEditTab(); - // if already created before - //$("#main-content #createUserForm").accordion("destroy"); - $("#main-content #createUserForm").html(""); + $("#main-content #createUserForm").html(smallSpinnerImg()); $("#main-content #createUserForm").attr("data-bind",'template: {name:"redback/user-edit-tmpl",data: user}'); var viewModel = new UserViewModel(user); @@ -160,13 +158,11 @@ $(function() { dataType: 'json', success: function(data) { var mappedRoles = $.map(data.role, function(item) { - var r = mapRole(item); - viewModel.user.assignedRoles.push(r); - return r; + return item.name; }); - viewModel.roles=mappedRoles; + user.assignedRoles = ko.observableArray(mappedRoles); - $("#main-content #user-edit-roles-view").attr("data-bind",'template: {name:"user_edit_roles_tmpl"}'); + $("#main-content #user-edit-roles-view").attr("data-bind",'template: {name:"user_view_roles_list_tmpl"}'); ko.applyBindings(viewModel,$("#user-edit-roles-view").get(0)); $("#main-content #edit_user_details_pills_headers").pills(); @@ -186,17 +182,20 @@ $(function() { } editUserRoles=function(user){ - $.log("editUserRoles:"+user.username()); + var viewModel = new UserViewModel(user); $("#user-edit-roles-edit").html(smallSpinnerImg()); $.ajax("restServices/redbackServices/roleManagementService/getApplicationRoles/"+encodeURIComponent(user.username()), { type: "GET", dataType: 'json', success: function(data) { - $("#user-edit-roles-edit").html("loaded"); var mappedApplicationRoles = $.map(data.applicationRole, function(item) { return mapApplicationRoles(item); }); + viewModel.applicationRoles=ko.observableArray(mappedApplicationRoles); $.log("applicationRoles length:"+mappedApplicationRoles.length); + $("#main-content #user-edit-roles-edit").attr("data-bind",'template: {name:"user_edit_roles_tmpl"}'); + ko.applyBindings(viewModel,$("#main-content #user-edit-roles-edit").get(0)); + $.log("assignedRoles:"+user.assignedRoles().length); } } ); @@ -204,7 +203,13 @@ $(function() { UserViewModel=function(user) { this.user=user; - this.roles = ko.observableArray(new Array()); + this.applicationRoles = ko.observableArray(new Array()); + + updateUserRoles=function(){ + $.log("updateUserRoles assigned:"+this.user.assignedRoles().length); + + } + } /** -- 2.39.5