From 10008c81a8682e6c545964f0ab977a472328fc10 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 4 Jan 2012 08:50:10 +0000 Subject: [PATCH] assigned/unassigned user(s) to a role: double multiselect view git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1227080 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/webapp/css/archiva.css | 21 ++++++++ .../src/main/webapp/index.html | 31 ++++++++++- .../src/main/webapp/js/redback/roles.js | 54 ++++++++++++------- .../js/redback/templates/roles-tmpl.html | 15 ++++++ 4 files changed, 101 insertions(+), 20 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/css/archiva.css b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/css/archiva.css index 1c090026f..945a119ff 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/css/archiva.css +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/css/archiva.css @@ -20,4 +20,25 @@ /* medium-spinner */ #medium-spinner { z-index: 20001; +} + + + +.ar-multiselect .ar-multiselect-column { + float: left; + width: 17em; +} + +.ar-multiselect .ar-multiselect-center { + float: left; + width: 3em; +} + +.ar-multiselect-center ul { + list-style: none; + margin: 3px 0 2px 6px +} + +.ar-multiselect-right { + margin-left: 2em } \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/index.html b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/index.html index a7d4fcca1..83e3d146e 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/index.html +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/index.html @@ -1,9 +1,11 @@ + + @@ -22,7 +24,34 @@
-
+
+ +
+
+ +
+
+
    +
  • + +
  • +
  • + +
  • +
+
+
+ +
+
+
+ + +
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 daabae10a..c72a93a0e 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 @@ -18,7 +18,7 @@ */ $(function() { - role = function(name,description,assignable,childRoleNames,parentRoleNames,users,parentsRolesUsers,permissions){ + role = function(name,description,assignable,childRoleNames,parentRoleNames,users,parentsRolesUsers,permissions,otherUsers){ this.name = ko.observable(name); this.description = ko.observable(description); this.assignable = ko.observable(assignable); @@ -27,6 +27,8 @@ $(function() { this.users = ko.observableArray(users); this.parentsRolesUsers = ko.observableArray(parentsRolesUsers);//read only this.permissions = ko.observableArray(permissions);//read only + // when editing a role other users not assign to this role are populated + this.otherUsers = ko.observableArray(otherUsers); this.updateDescription=function(){ var url = "restServices/redbackServices/roleManagementService/updateRoleDescription?"; @@ -54,6 +56,7 @@ $(function() { */ RolesViewModel=function() { this.roles = ko.observableArray([]); + var self = this; this.loadRoles = function() { $.ajax("restServices/redbackServices/roleManagementService/allRoles", { @@ -96,22 +99,17 @@ $(function() { dataType: 'json', success: function(data) { var mappedRole = mapRole(data.role); - $("#main-content #roles-view-tabs-content #role-edit").attr("data-bind",'template: {name:"editRoleTab",data: role}'); + $("#main-content #roles-view-tabs-content #role-edit").attr("data-bind",'template: {name:"editRoleTab",data: currentRole}'); role.parentRoleNames=mappedRole.parentRoleNames; role.parentsRolesUsers=mappedRole.parentsRolesUsers; role.users=mappedRole.users; - var viewModel = new roleViewModel(role); + role.otherUsers=mappedRole.otherUsers; + var viewModel = new RoleViewModel(role); ko.applyBindings(viewModel,$("#main-content #roles-view-tabs-content #role-edit").get(0)); activateRoleEditTab(); } } ); - - - } - - this.saveRoleDescription=function(role){ - $.log("saveRoleDescription:"+role.description); } } @@ -130,16 +128,30 @@ $(function() { removeMediumSpinnerImg(); } - saveRoleDescription=function(){ - var roleName = $("#editRoleTable #role-edit-name").html(); - var description = $("#editRoleTable #role-edit-description").val(); - clearUserMessages(); - new role(roleName,description).updateDescription(); - - } + RoleViewModel=function(role){ + selectedOtherUsers=new ko.observableArray(); + selectedUsers=new ko.observableArray(); + currentRole=role; + var self=this; + addUser=function(){ + var removed = currentRole.otherUsers.removeAll(selectedOtherUsers()); + for (var i = 0; i < removed.length; i++) { + currentRole.users.push(removed[i]); + } + selectedOtherUsers([]); + } - roleViewModel=function(role){ - this.role=role; + removeUser=function(){ + var added = currentRole.users.removeAll(selectedUsers()); + for (var i = 0; i < added.length; i++) { + currentRole.otherUsers.push(added[i]); + } + selectedUsers([]); + } + saveRoleDescription=function(){ + $.log("saveRoleDescription:"+currentRole.description()); + currentRole.updateDescription(); + } } /** @@ -164,7 +176,11 @@ $(function() { return mapPermission(item); }): new Array(mapPermission(data.permissions)) :null; - return new role(data.name, data.description?data.description:"",data.assignable,childRoleNames,parentRoleNames,users,parentsRolesUsers,permissions); + var otherUsers = data.otherUsers ? $.isArray(data.otherUsers)? $.map(data.otherUsers, function(item) { + return mapUser(item); + }):new Array(mapUser(data.otherUsers)):null; + + return new role(data.name, data.description?data.description:"",data.assignable,childRoleNames,parentRoleNames,users,parentsRolesUsers,permissions,otherUsers); } activateRolesGridTab=function(){ diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/templates/roles-tmpl.html b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/templates/roles-tmpl.html index 8ec37303f..103443ba8 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/templates/roles-tmpl.html +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/templates/roles-tmpl.html @@ -130,6 +130,21 @@ ${$.i18n.prop('role.edit.no.user.defined')} {{/if}} +
+
+ +
+
+
    +
  • +
  • +
+
+
+ +
+
+ -- 2.39.5