From 216591f7d55ad758f0d076b94ad4e76686858025 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sun, 1 Jan 2012 00:45:53 +0000 Subject: [PATCH] role edit detail with knockout git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1226203 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/webapp/index.html | 1 + .../src/main/webapp/js/archiva/utils.js | 18 ++--- .../src/main/webapp/js/redback/roles.js | 74 +++++++------------ .../js/redback/templates/roles-tmpl.html | 63 ++++++---------- 4 files changed, 58 insertions(+), 98 deletions(-) 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 a67029133..e55b96373 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 @@ -60,6 +60,7 @@ .script("bootstrap-alerts.js").wait() .script("bootstrap-dropdown.js").wait() .script("knockout.simpleGrid.js").wait() + .script("knockout.mapping-latest.debug.js").wait() .script("redback/user.js").wait() .script("redback/users.js").wait() .script("redback/redback.js").wait() diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js index 6dd46900b..223968d1b 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js @@ -191,14 +191,14 @@ openDialogConfirmui=function(okFn, okMessage, cancelMessage, title){ } mapStringArray=function(data){ - if ($.isArray(data)){ - //$.log("isArray"); - return $.map(data,function(item){ - return item; - }); - } else { - //$.log("not Array"); - return [data]; + if (data) { + if ($.isArray(data)){ + return $.map(data,function(item){ + return item; + }); + } else { + return new Array(data); + } } - + return null; } \ No newline at end of file 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 bc61a5a40..c68276880 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 @@ -28,11 +28,6 @@ $(function() { this.parentsRolesUsers = ko.observableArray(parentsRolesUsers);//read only this.permissions = ko.observableArray(permissions);//read only - - - - - this.updateDescription=function(){ var url = "restServices/redbackServices/roleManagementService/updateRoleDescription?"; var roleName = this.name(); @@ -93,10 +88,30 @@ $(function() { }); this.editRole=function(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").html(mediumSpinnerImg()); + // load missing attributes + $.ajax("restServices/redbackServices/roleManagementService/getRole/"+role.name(), + { + type: "GET", + 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}'); + role.parentRoleNames=mappedRole.parentRoleNames; + role.parentsRolesUsers=mappedRole.parentsRolesUsers; + role.users=mappedRole.users; + var viewModel = new roleViewModel(role); + ko.applyBindings(viewModel,$("#main-content #roles-view-tabs-content #role-edit").get(0)); + activateRoleEditTab(); + } + } + ); + + + } - var viewModel = new roleViewModel(role); - ko.applyBindings(viewModel,$("#main-content #roles-view-tabs-content #role-edit").get(0)); + this.saveRoleDescription=function(role){ + $.log("saveRoleDescription:"+role.description); } } @@ -113,43 +128,6 @@ $(function() { $("#roles-view-tabs").tabs(); activateRolesGridTab(); removeMediumSpinnerImg(); - /* - $.ajax("restServices/redbackServices/roleManagementService/detailledAllRoles", - { - type: "GET", - dataType: 'json', - success: function(data) { - var roles = $.map(data.role, function(item) { - return mapRole(item); - }); - //$.log(ko.toJSON(roles)); - $("#main-content").html($("#rolesTabs").tmpl()); - var data = {roles: roles}; - $("#main-content #roles-view-tabs-content #roles-view").html($("#rolesGrid").tmpl(data)); - $("#roles-view-tabs").tabs(); - activateRolesGridTab(); - }, - complete: function(){ - removeMediumSpinnerImg(); - } - } - ); - */ - } - - editRole = function(roleName){ - $.log("edit role:"+roleName); - $.ajax("restServices/redbackServices/roleManagementService/getRole/"+roleName, - { - type: "GET", - dataType: 'json', - success: function(data) { - var role = mapRole(data.role); - $("#main-content #roles-view-tabs-content #role-edit").html($("#editRoleTab").tmpl(data.role)); - activateRoleEditTab(); - } - } - ); } saveRoleDescription=function(){ @@ -174,15 +152,15 @@ $(function() { var parentRoleNames = mapStringArray(data.parentRoleNames); var users = data.users ? $.isArray(data.users) ? $.map(data.users, function(item) { return mapUser(item); - }):[mapUser(data.users)]:null; + }):new Array(mapUser(data.users)):null; var parentsRolesUsers = data.parentsRolesUsers ? $.isArray(data.parentsRolesUsers)? $.map(data.parentsRolesUsers, function(item) { return mapUser(item); - }):[mapUser(data.parentsRolesUsers)]:null; + }):new Array(mapUser(data.parentsRolesUsers)):null; var permissions = data.permissions? $.isArray(data.permissions) ? $.map(data.permissions, function(item){ return mapPermission(item); - }): [mapPermission(data.permissions)] :null; + }): new Array(mapPermission(data.permissions)) :null; return new role(data.name, data.description,data.assignable,childRoleNames,parentRoleNames,users,parentsRolesUsers,permissions); } 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 90e25d91b..b5d2ce7b7 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 @@ -31,16 +31,16 @@ ${$.i18n.prop('name')}: - ${name} + ${$data.name} ${$.i18n.prop('description')}: - +
- +
@@ -50,37 +50,30 @@ - {{if parentRoleNames}} + {{if $data.parentRoleNames}} {{/if}} - {{if childRoleNames}} + {{if $data.childRoleNames}} {{/if}} - {{if permissions}} + {{if $data.permissions}} @@ -90,21 +83,21 @@ - {{if $.isArray(permissions)}} {{each permissions}} - - + {{if $value.operation }} + + {{else}} + + {{/if}} + {{if $value.resource }} + + {{else}} + + {{/if}} {{/each}} - {{else}} - - - - - - {{/if}}
${$value.name}${$value.operation.name}${$value.resource.identifier}${$value.operation.name}${$value.resource.identifier}
${permissions.name}${permissions.operation.name}${permissions.resource.identifier}
{{/if}} @@ -112,39 +105,27 @@ - {{if parentsRolesUsers}} + {{if $data.parentsRolesUsers}} - {{if $.isArray(parentsRolesUsers)}} - {{else}} - - {{/if}} {{/if}} - {{if users}} - {{if $.isArray(users)}} + {{if $data.users}} - {{else}} - - {{/if}} {{else}} ${$.i18n.prop('role.edit.no.user.defined')} {{/if}} -- 2.39.5