mirror of https://github.com/apache/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
This commit is contained in:
parent
507a6593d3
commit
90e5ff9ed0
|
@ -64,6 +64,8 @@
|
||||||
.script("redback/users.js").wait()
|
.script("redback/users.js").wait()
|
||||||
.script("redback/redback.js").wait()
|
.script("redback/redback.js").wait()
|
||||||
.script("redback/register.js").wait()
|
.script("redback/register.js").wait()
|
||||||
|
.script("redback/permission.js").wait()
|
||||||
|
.script("redback/resource.js").wait()
|
||||||
.script("redback/roles.js").wait()
|
.script("redback/roles.js").wait()
|
||||||
.script("archiva/main.js");
|
.script("archiva/main.js");
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ $(function() {
|
||||||
return mapOperation(item);
|
return mapOperation(item);
|
||||||
});
|
});
|
||||||
window.redbackModel.operatioNames = $.map(mappedOperations, function(item){
|
window.redbackModel.operatioNames = $.map(mappedOperations, function(item){
|
||||||
return item.name;
|
return item.name();
|
||||||
});
|
});
|
||||||
|
|
||||||
$("[redback-permissions]").each(function(element){
|
$("[redback-permissions]").each(function(element){
|
||||||
|
@ -88,7 +88,6 @@ $(function() {
|
||||||
var neededKarmas = $(eval(bindingValue)).toArray();
|
var neededKarmas = $(eval(bindingValue)).toArray();
|
||||||
var karmaOk = false;
|
var karmaOk = false;
|
||||||
$(neededKarmas).each(function(value){
|
$(neededKarmas).each(function(value){
|
||||||
//alert(neededKarmas[value]);
|
|
||||||
if ($.inArray(neededKarmas[value],window.redbackModel.operatioNames)>=0) {
|
if ($.inArray(neededKarmas[value],window.redbackModel.operatioNames)>=0) {
|
||||||
karmaOk = true;
|
karmaOk = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -20,7 +20,7 @@ $(function() {
|
||||||
|
|
||||||
|
|
||||||
operation=function(name) {
|
operation=function(name) {
|
||||||
this.name=name;
|
this.name=ko.observable(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
});
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
});
|
|
@ -18,15 +18,43 @@
|
||||||
*/
|
*/
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
||||||
role = function(name,description,permissions){
|
role = function(name,description,assignable,childRoleNames,parentRoleNames,users,parentsRolesUsers,permissions){
|
||||||
this.name = name;
|
this.name = ko.observable(name);
|
||||||
this.description = description;
|
this.description = ko.observable(description);
|
||||||
this.permissions=permissions;
|
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(){
|
displayRolesGrid = function(){
|
||||||
$("#user-messages").html("");
|
$("#user-messages").html("");
|
||||||
|
@ -37,11 +65,11 @@ $(function() {
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
var roles = $.map(data.role, function(item) {
|
var roles = $.map(data.role, function(item) {
|
||||||
return mapRole(item);
|
return mapRole(item);
|
||||||
});
|
});
|
||||||
|
$.log(ko.toJSON(roles));
|
||||||
$("#main-content").html($("#rolesTabs").tmpl());
|
$("#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();
|
$("#roles-view-tabs").tabs();
|
||||||
activateRolesGridTab();
|
activateRolesGridTab();
|
||||||
}
|
}
|
||||||
|
@ -68,22 +96,7 @@ $(function() {
|
||||||
var roleName = $("#editRoleTable #role-edit-name").html();
|
var roleName = $("#editRoleTable #role-edit-name").html();
|
||||||
var description = $("#editRoleTable #role-edit-description").val();
|
var description = $("#editRoleTable #role-edit-description").val();
|
||||||
clearUserMessages();
|
clearUserMessages();
|
||||||
var url = "restServices/redbackServices/roleManagementService/updateRoleDescription?";
|
new role(roleName,description).updateDescription();
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +104,23 @@ $(function() {
|
||||||
* @param data Role response from redback rest api
|
* @param data Role response from redback rest api
|
||||||
*/
|
*/
|
||||||
mapRole=function(data) {
|
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(){
|
activateRolesGridTab=function(){
|
||||||
|
|
|
@ -80,7 +80,7 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</ul>
|
</ul>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
<!--
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h3>${$.i18n.prop('role.model.child.roles')}</h3>
|
<h3>${$.i18n.prop('role.model.child.roles')}</h3>
|
||||||
</div>
|
</div>
|
||||||
|
@ -167,5 +167,5 @@
|
||||||
{{else}}
|
{{else}}
|
||||||
${$.i18n.prop('role.edit.no.user.defined')}
|
${$.i18n.prop('role.edit.no.user.defined')}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
-->
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -31,10 +31,10 @@ $(function() {
|
||||||
async: false,
|
async: false,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
var mappedUsers = $.map(data.user, function(item) {
|
var mappedUsers = $.map(data.user, function(item) {
|
||||||
return mapUser(item);
|
return mapUser(item);
|
||||||
});
|
});
|
||||||
self.users(mappedUsers);
|
self.users(mappedUsers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue