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
This commit is contained in:
Olivier Lamy 2011-12-31 13:55:46 +00:00
parent 507a6593d3
commit 90e5ff9ed0
9 changed files with 154 additions and 35 deletions

View File

@ -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");

View File

@ -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;
}

View File

@ -177,3 +177,19 @@ 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;
}

View File

@ -20,7 +20,7 @@ $(function() {
operation=function(name) {
this.name=name;
this.name=ko.observable(name);
}
/**

View File

@ -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);
}
});

View File

@ -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);
}
});

View File

@ -18,15 +18,43 @@
*/
$(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
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");
}
}
);
}
}
permission = function(){
}
displayRolesGrid = function(){
$("#user-messages").html("");
@ -39,9 +67,9 @@ $(function() {
var roles = $.map(data.role, function(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(){

View File

@ -80,7 +80,7 @@
{{/if}}
</ul>
{{/if}}
<!--
<div class="page-header">
<h3>${$.i18n.prop('role.model.child.roles')}</h3>
</div>
@ -167,5 +167,5 @@
{{else}}
${$.i18n.prop('role.edit.no.user.defined')}
{{/if}}
-->
</script>