<!DOCTYPE html>
<html>
<head>
+ <link rel="stylesheet" href="css/jquery-ui-1.8.16.custom.css"/>
<link rel="stylesheet" href="css/bootstrap.min.1.4.0.css">
<link rel="stylesheet" href="css/archiva.css">
+
<script type="text/javascript" src="js/jquery-1.7.js"></script>
<script type="text/javascript" src="js/lab.js"></script>
<div class="content">
<div id="user-messages"></div>
- <div id="main-content"></div>
+ <div id="main-content">
+
+<div id="role-edit-users" class="clearfix ar-multiselect" style="float: left">
+<div class="ar-multiselect-column ar-multiselect-left">
+<select id="role-edit-available-users" class="" multiple="true">
+<option value="">admin</option>
+</select>
+</div>
+<div class="ar-multiselect-column ar-multiselect-center">
+<ul>
+<li>
+<button class="btn">></button>
+</li>
+<li>
+<button class="btn"><</button>
+</li>
+</ul>
+</div>
+<div class="ar-multiselect-column ar-multiselect-right">
+<select id="role-edit-affected-users" class="" multiple="true">
+<option value="">admin</option>
+</select>
+</div>
+</div>
+</div>
+
+
+ </div>
</div>
</div>
*/
$(function() {
- role = function(name,description,assignable,childRoleNames,parentRoleNames,users,parentsRolesUsers,permissions){
+ role = function(name,description,assignable,childRoleNames,parentRoleNames,users,parentsRolesUsers,permissions,otherUsers){
this.name = ko.observable(name);
this.description = ko.observable(description);
this.assignable = ko.observable(assignable);
this.users = ko.observableArray(users);
this.parentsRolesUsers = ko.observableArray(parentsRolesUsers);//read only
this.permissions = ko.observableArray(permissions);//read only
+ // when editing a role other users not assign to this role are populated
+ this.otherUsers = ko.observableArray(otherUsers);
this.updateDescription=function(){
var url = "restServices/redbackServices/roleManagementService/updateRoleDescription?";
*/
RolesViewModel=function() {
this.roles = ko.observableArray([]);
+
var self = this;
this.loadRoles = function() {
$.ajax("restServices/redbackServices/roleManagementService/allRoles", {
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}');
+ $("#main-content #roles-view-tabs-content #role-edit").attr("data-bind",'template: {name:"editRoleTab",data: currentRole}');
role.parentRoleNames=mappedRole.parentRoleNames;
role.parentsRolesUsers=mappedRole.parentsRolesUsers;
role.users=mappedRole.users;
- var viewModel = new roleViewModel(role);
+ role.otherUsers=mappedRole.otherUsers;
+ var viewModel = new RoleViewModel(role);
ko.applyBindings(viewModel,$("#main-content #roles-view-tabs-content #role-edit").get(0));
activateRoleEditTab();
}
}
);
-
-
- }
-
- this.saveRoleDescription=function(role){
- $.log("saveRoleDescription:"+role.description);
}
}
removeMediumSpinnerImg();
}
- saveRoleDescription=function(){
- var roleName = $("#editRoleTable #role-edit-name").html();
- var description = $("#editRoleTable #role-edit-description").val();
- clearUserMessages();
- new role(roleName,description).updateDescription();
-
- }
+ RoleViewModel=function(role){
+ selectedOtherUsers=new ko.observableArray();
+ selectedUsers=new ko.observableArray();
+ currentRole=role;
+ var self=this;
+ addUser=function(){
+ var removed = currentRole.otherUsers.removeAll(selectedOtherUsers());
+ for (var i = 0; i < removed.length; i++) {
+ currentRole.users.push(removed[i]);
+ }
+ selectedOtherUsers([]);
+ }
- roleViewModel=function(role){
- this.role=role;
+ removeUser=function(){
+ var added = currentRole.users.removeAll(selectedUsers());
+ for (var i = 0; i < added.length; i++) {
+ currentRole.otherUsers.push(added[i]);
+ }
+ selectedUsers([]);
+ }
+ saveRoleDescription=function(){
+ $.log("saveRoleDescription:"+currentRole.description());
+ currentRole.updateDescription();
+ }
}
/**
return mapPermission(item);
}): new Array(mapPermission(data.permissions)) :null;
- return new role(data.name, data.description?data.description:"",data.assignable,childRoleNames,parentRoleNames,users,parentsRolesUsers,permissions);
+ var otherUsers = data.otherUsers ? $.isArray(data.otherUsers)? $.map(data.otherUsers, function(item) {
+ return mapUser(item);
+ }):new Array(mapUser(data.otherUsers)):null;
+
+ return new role(data.name, data.description?data.description:"",data.assignable,childRoleNames,parentRoleNames,users,parentsRolesUsers,permissions,otherUsers);
}
activateRolesGridTab=function(){