--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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
*/
$(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("");
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();
}
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();
}
* @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(){