From: Olivier Lamy Date: Sat, 31 Dec 2011 13:55:46 +0000 (+0000) Subject: start moving role edition to use knockout with adding bean mapping X-Git-Tag: archiva-1.4-M3~1666 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=90e5ff9ed0a08df275af4c2882e9ef99227c8bdf;p=archiva.git start moving role edition to use knockout with adding bean mapping git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1226092 13f79535-47bb-0310-9956-ffa450edef68 --- 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 d3969b9db..a67029133 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 @@ -64,6 +64,8 @@ .script("redback/users.js").wait() .script("redback/redback.js").wait() .script("redback/register.js").wait() + .script("redback/permission.js").wait() + .script("redback/resource.js").wait() .script("redback/roles.js").wait() .script("archiva/main.js"); diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js index 1e6a93b58..7264fc516 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js @@ -79,7 +79,7 @@ $(function() { return mapOperation(item); }); window.redbackModel.operatioNames = $.map(mappedOperations, function(item){ - return item.name; + return item.name(); }); $("[redback-permissions]").each(function(element){ @@ -88,7 +88,6 @@ $(function() { var neededKarmas = $(eval(bindingValue)).toArray(); var karmaOk = false; $(neededKarmas).each(function(value){ - //alert(neededKarmas[value]); if ($.inArray(neededKarmas[value],window.redbackModel.operatioNames)>=0) { karmaOk = true; } 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 ff39934b8..43697d267 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 @@ -176,4 +176,20 @@ openDialogConfirmui=function(okFn, okMessage, cancelMessage, title){ } }] }); +} + +mapStringArray=function(data){ + //if (data){ + if ($.isArray(data)){ + $.log("isArray"); + return $.map(data,function(item){ + return item; + }); + } else { + $.log("not Array"); + 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/operation.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/operation.js index f91109e96..9f31787ba 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/operation.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/operation.js @@ -20,7 +20,7 @@ $(function() { operation=function(name) { - this.name=name; + this.name=ko.observable(name); } /** diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/permission.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/permission.js new file mode 100644 index 000000000..cc3da0844 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/permission.js @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +$(function() { + + + permission=function(name,operation,resource) { + this.name=ko.observable(name); + this.operation=ko.observable(operation); + this.resource=ko.observable(resource); + } + + /** + * @param data Permission response from redback rest api + */ + mapPermission=function(data) { + return new permission(data.name, + data.operation?mapOperation(data.operation):null, + data.resource?mapResource(data.resource):null); + } + + +}); \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/resource.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/resource.js new file mode 100644 index 000000000..9fd19c3e2 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/resource.js @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +$(function() { + + + resource=function(identifier,pattern) { + this.identifier=ko.observable(identifier); + this.pattern=ko.observable(pattern); + } + + /** + * @param data Resource response from redback rest api + */ + mapResource=function(data) { + return new resource(data.identifier,data.pattern); + } + + +}); \ 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 4bdb74a59..da018b3a5 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,16 +18,44 @@ */ $(function() { - role = function(name,description,permissions){ - this.name = name; - this.description = description; - this.permissions=permissions; - } + role = function(name,description,assignable,childRoleNames,parentRoleNames,users,parentsRolesUsers,permissions){ + this.name = ko.observable(name); + this.description = ko.observable(description); + this.assignable = ko.observable(assignable); + this.childRoleNames = ko.observableArray(childRoleNames);//read only + this.parentRoleNames = ko.observableArray(parentRoleNames);//read only + this.users = ko.observableArray(users); + this.parentsRolesUsers = ko.observableArray(parentsRolesUsers);//read only + this.permissions = ko.observableArray(permissions);//read only + + + - permission = function(){ + + this.updateDescription=function(){ + var url = "restServices/redbackServices/roleManagementService/updateRoleDescription?"; + var roleName = this.name(); + url += "roleName="+encodeURIComponent(roleName); + url += "&roleDescription="+encodeURIComponent(this.description()); + $.ajax(url, + { + type: "GET", + dataType: 'json', + success: function(data) { + $.log("role description updated"); + displaySuccessMessage($.i18n.prop("role.updated",roleName)); + }, + error: function(data){ + displayErrorMessage("error updating role description"); + } + } + ); + } } + + displayRolesGrid = function(){ $("#user-messages").html(""); $("#main-content").html(""); @@ -37,11 +65,11 @@ $(function() { dataType: 'json', success: function(data) { var roles = $.map(data.role, function(item) { - return mapRole(item); + return mapRole(item); }); - + $.log(ko.toJSON(roles)); $("#main-content").html($("#rolesTabs").tmpl()); - $("#main-content #roles-view-tabs-content #roles-view").html($("#rolesGrid").tmpl(data)); + $("#main-content #roles-view-tabs-content #roles-view").html($("#rolesGrid").tmpl(roles)); $("#roles-view-tabs").tabs(); activateRolesGridTab(); } @@ -68,22 +96,7 @@ $(function() { var roleName = $("#editRoleTable #role-edit-name").html(); var description = $("#editRoleTable #role-edit-description").val(); clearUserMessages(); - var url = "restServices/redbackServices/roleManagementService/updateRoleDescription?"; - url += "roleName="+encodeURIComponent(roleName); - url += "&roleDescription="+encodeURIComponent(description); - $.ajax(url, - { - type: "GET", - dataType: 'json', - success: function(data) { - $.log("role description updated"); - displaySuccessMessage($.i18n.prop("role.updated",roleName)); - }, - error: function(data){ - displayErrorMessage("error updating role description"); - } - } - ); + new role(roleName,description).updateDescription(); } @@ -91,7 +104,23 @@ $(function() { * @param data Role response from redback rest api */ mapRole=function(data) { - return new role(data.name, data.description); + // name, description, assignable,childRoleNames,parentRoleNames,users,parentsRolesUsers,permissions + $.log("mapRole:"+data.name+":"); + var childRoleNames = mapStringArray(data.childRoleNames); + var parentRoleNames = mapStringArray(data.parentRoleNames); + var users = data.users ? $.map(data.users, function(item) { + return mapUser(item); + }):null; + + var parentsRolesUsers = data.parentsRolesUsers ? $.map(data.parentsRolesUsers, function(item) { + return mapUser(item); + }):null; + + var permissions = data.permissions? $.map(data.permissions, function(item){ + return mapPermission(item); + }):null; + + return new role(data.name, data.description,data.assignable,childRoleNames,parentRoleNames,users,parentsRolesUsers,permissions); } 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 6401cd91f..8f7b357e9 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 @@ -80,7 +80,7 @@ {{/if}} {{/if}} - + 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 f0466dc45..61950aee6 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 @@ -31,10 +31,10 @@ $(function() { async: false, dataType: 'json', success: function(data) { - var mappedUsers = $.map(data.user, function(item) { - return mapUser(item); - }); - self.users(mappedUsers); + var mappedUsers = $.map(data.user, function(item) { + return mapUser(item); + }); + self.users(mappedUsers); } } );