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();
});
this.editRole=function(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").html(mediumSpinnerImg());
+ // load missing attributes
+ $.ajax("restServices/redbackServices/roleManagementService/getRole/"+role.name(),
+ {
+ type: "GET",
+ 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}');
+ role.parentRoleNames=mappedRole.parentRoleNames;
+ role.parentsRolesUsers=mappedRole.parentsRolesUsers;
+ role.users=mappedRole.users;
+ var viewModel = new roleViewModel(role);
+ ko.applyBindings(viewModel,$("#main-content #roles-view-tabs-content #role-edit").get(0));
+ activateRoleEditTab();
+ }
+ }
+ );
+
+
+ }
- var viewModel = new roleViewModel(role);
- ko.applyBindings(viewModel,$("#main-content #roles-view-tabs-content #role-edit").get(0));
+ this.saveRoleDescription=function(role){
+ $.log("saveRoleDescription:"+role.description);
}
}
$("#roles-view-tabs").tabs();
activateRolesGridTab();
removeMediumSpinnerImg();
- /*
- $.ajax("restServices/redbackServices/roleManagementService/detailledAllRoles",
- {
- type: "GET",
- dataType: 'json',
- success: function(data) {
- var roles = $.map(data.role, function(item) {
- return mapRole(item);
- });
- //$.log(ko.toJSON(roles));
- $("#main-content").html($("#rolesTabs").tmpl());
- var data = {roles: roles};
- $("#main-content #roles-view-tabs-content #roles-view").html($("#rolesGrid").tmpl(data));
- $("#roles-view-tabs").tabs();
- activateRolesGridTab();
- },
- complete: function(){
- removeMediumSpinnerImg();
- }
- }
- );
- */
- }
-
- editRole = function(roleName){
- $.log("edit role:"+roleName);
- $.ajax("restServices/redbackServices/roleManagementService/getRole/"+roleName,
- {
- type: "GET",
- dataType: 'json',
- success: function(data) {
- var role = mapRole(data.role);
- $("#main-content #roles-view-tabs-content #role-edit").html($("#editRoleTab").tmpl(data.role));
- activateRoleEditTab();
- }
- }
- );
}
saveRoleDescription=function(){
var parentRoleNames = mapStringArray(data.parentRoleNames);
var users = data.users ? $.isArray(data.users) ? $.map(data.users, function(item) {
return mapUser(item);
- }):[mapUser(data.users)]:null;
+ }):new Array(mapUser(data.users)):null;
var parentsRolesUsers = data.parentsRolesUsers ? $.isArray(data.parentsRolesUsers)? $.map(data.parentsRolesUsers, function(item) {
return mapUser(item);
- }):[mapUser(data.parentsRolesUsers)]:null;
+ }):new Array(mapUser(data.parentsRolesUsers)):null;
var permissions = data.permissions? $.isArray(data.permissions) ? $.map(data.permissions, function(item){
return mapPermission(item);
- }): [mapPermission(data.permissions)] :null;
+ }): new Array(mapPermission(data.permissions)) :null;
return new role(data.name, data.description,data.assignable,childRoleNames,parentRoleNames,users,parentsRolesUsers,permissions);
}
<tbody>
<tr>
<td>${$.i18n.prop('name')}:</td>
- <td id="role-edit-name">${name}</td>
+ <td id="role-edit-name">${$data.name}</td>
</tr>
<tr>
<td>${$.i18n.prop('description')}:</td>
- <td><input type="text" id="role-edit-description" value="${description}"></td>
+ <td><input type="text" id="role-edit-description" data-bind="value: description"></td>
</tr>
<tr>
<td colspan="2">
<div class="pull-left">
- <button class="btn" onclick="saveRoleDescription();">${$.i18n.prop('save')}</button>
+ <button class="btn" data-bind="click: saveRoleDescription">${$.i18n.prop('save')}</button>
</div>
</td>
</tr>
<div class="page-header">
<h3>${$.i18n.prop('role.model.parent.roles')}</h3>
</div>
- {{if parentRoleNames}}
+ {{if $data.parentRoleNames}}
<ul>
- {{if $.isArray(parentRoleNames)}}
- {{each parentRoleNames}}
+ {{each $data.parentRoleNames}}
<li>${$value}</li>
{{/each}}
- {{else}}
- <li>${parentRoleNames}</li>
- {{/if}}
+
</ul>
{{/if}}
<div class="page-header">
<h3>${$.i18n.prop('role.model.child.roles')}</h3>
</div>
- {{if childRoleNames}}
+ {{if $data.childRoleNames}}
<ul>
- {{if $.isArray(childRoleNames)}}
- {{each childRoleNames}}
+ {{each $data.childRoleNames}}
<li>${$value}</li>
{{/each}}
- {{else}}
- <li>${childRoleNames}</li>
- {{/if}}
</ul>
{{/if}}
<div class="page-header">
<h3>${$.i18n.prop('permissions')}</h3>
</div>
- {{if permissions}}
+ {{if $data.permissions}}
<table class="bordered-table zebra-striped" id="rolePermissionsTable">
<thead>
<tr>
</tr>
</thead>
<tbody>
- {{if $.isArray(permissions)}}
{{each permissions}}
<tr>
<td>${$value.name}</td>
- <td>${$value.operation.name}</td>
- <td>${$value.resource.identifier}</td>
+ {{if $value.operation }}
+ <td>${$value.operation.name}</td>
+ {{else}}
+ <td></td>
+ {{/if}}
+ {{if $value.resource }}
+ <td>${$value.resource.identifier}</td>
+ {{else}}
+ <td></td>
+ {{/if}}
</tr>
{{/each}}
- {{else}}
- <tr>
- <td>${permissions.name}</td>
- <td>${permissions.operation.name}</td>
- <td>${permissions.resource.identifier}</td>
- </tr>
- {{/if}}
</tbody>
</table>
{{/if}}
<div class="page-header">
<h2>${$.i18n.prop('role.edit.section.users')}</h2>
</div>
- {{if parentsRolesUsers}}
+ {{if $data.parentsRolesUsers}}
<div class="page-header">
<h3>${$.i18n.prop('role.edit.users.defined.in.parent.roles')}</h3>
</div>
- {{if $.isArray(parentsRolesUsers)}}
<ul>
- {{each parentsRolesUsers}}
+ {{each $data.parentsRolesUsers}}
<li>${$value.fullName} - ( ${$value.username} - ${$value.email} ) </li>
{{/each}}
</ul>
- {{else}}
- <ul>
- <li>${parentsRolesUsers.fullName} - ( ${parentsRolesUsers.username} - ${parentsRolesUsers.email} ) </li>
- </ul>
- {{/if}}
{{/if}}
<div class="page-header">
<h3>${$.i18n.prop('role.edit.users.defined.in.current.role')}</h3>
</div>
- {{if users}}
- {{if $.isArray(users)}}
+ {{if $data.users}}
<ul>
{{each users}}
<li>${$value.fullName} - ( ${$value.username} - ${$value.email} ) </li>
{{/each}}
</ul>
- {{else}}
- <ul>
- <li>${users.fullName} - ( ${users.username} - ${users.email} ) </li>
- </ul>
- {{/if}}
{{else}}
${$.i18n.prop('role.edit.no.user.defined')}
{{/if}}