$(function() {
Role = function(name,description,assignable,childRoleNames,parentRoleNames,users,parentsRolesUsers,permissions,otherUsers){
+
+ var self=this;
+
this.name = ko.observable(name);
this.name.subscribe(function(newValue){self.modified(true)});
this.modified=ko.observable(false);
+ this.usersModified=ko.observable(false);
+
this.updateDescription=function(){
var url = "restServices/redbackServices/roleManagementService/updateRoleDescription?";
var roleName = this.name();
}
);
}
- var self=this;
+
this.updateUsers=function(){
var url = "restServices/redbackServices/roleManagementService/updateRoleUsers";
$.ajax(url,
dataType: 'json',
success: function(data) {
var mappedRole = mapRole(data.role);
- role.parentRoleNames=mappedRole.parentRoleNames;
- role.parentsRolesUsers=mappedRole.parentsRolesUsers;
- role.users=mappedRole.users;
- role.otherUsers=mappedRole.otherUsers;
+ role.parentRoleNames(mappedRole.parentRoleNames());
+ role.parentsRolesUsers(mappedRole.parentsRolesUsers());
+ role.users(mappedRole.users());
+ role.otherUsers(mappedRole.otherUsers());
+ role.modified(false);
var viewModel = new RoleViewModel(role);
ko.applyBindings(viewModel,mainContent.find("#roles-view-tabs-content #role-edit").get(0));
activateRoleEditTab();
- mainContent.find("#role-view-users ").tabs("show");
+ mainContent.find("#role-view-users").tabs("show");
mainContent.find("#role-edit-users-tabs-content #role-view-users").addClass("active");
}
}
);
}
+ this.bulkSave=function(){
+ $.log("bulkSave");
+ return getModifiedRoles().length>0;
+ }
+
+ getModifiedRoles=function(){
+ var prx = $.grep(self.roles(),
+ function (role,i) {
+ return role.modified()||role.usersModified();
+ });
+ return prx;
+ }
+
+ updateModifiedRoles=function(){
+ var modifiedRoles = getModifiedRoles();
+ $.log("modifiedRoles:"+modifiedRoles);
+ for(i=0;i<modifiedRoles.length;i++){
+ var modifiedRole=modifiedRoles[i];
+ if (modifiedRole.modified()){
+ modifiedRole.updateDescription();
+ modifiedRole.modified(false);
+ }
+ if (modifiedRole.usersModified()){
+ modifiedRole.updateUsers();
+ modifiedRole.usersModified(false);
+ }
+ }
+ }
+
}
displayRolesGrid = function(){
var rolesViewModel = new RolesViewModel();
rolesViewModel.roles(mappedRoles);
mainContent.html($("#rolesTabs").tmpl());
- ko.applyBindings(rolesViewModel,mainContent.find("#rolesTable").get(0));
+ ko.applyBindings(rolesViewModel,mainContent.find("#roles-view").get(0));
mainContent.find("#roles-view-tabs #roles-view-tabs-a-roles-grid").tab("show");
activateRolesGridTab();
removeMediumSpinnerImg();
for (var i = 0; i < removed.length; i++) {
$.log("add user:"+removed[i].username());
currentRole.users.push(removed[i]);
- role.modified(true);
+ //role.modified(true);
+ role.usersModified(true);
}
selectedOtherUsers([]);
activateRoleUsersEditTab();
for (var i = 0; i < added.length; i++) {
currentRole.otherUsers.push(added[i]);
currentRole.removedUsers.push(added[i]);
- role.modified(true);
+ //role.modified(true);
+ role.usersModified(true);
}
selectedUsers([]);
activateRoleUsersEditTab()
</ul>
<div id="roles-view-tabs-content" class="tab-content">
<div id="roles-view" class="tab-pane">
+ <div data-bind="style: { display: bulkSave() ? '' : 'none' }">
+ <button data-bind="click: updateModifiedRoles" class="btn">${$.i18n.prop('save.all')}</button>
+ </div>
<table class="table table-striped table-bordered" id="rolesTable"
data-bind="simpleGrid: gridViewModel,simpleGridTemplate:'ko_rolesGrid',pageLinksId:'rolesPagination'">
</table>
<h3>${$.i18n.prop('role.edit.users.defined.in.current.role')}</h3>
</div>
<div id="role-list-users">
- {{if $data.users}}
+ {{if users().length>0}}
<ul>
- {{each users}}
- <li>${$value.fullName} - ( ${$value.username} - ${$value.email} ) </li>
+ {{each(j, user) users()}}
+ <li>${user.fullName()} - ( ${user.username()} - ${user.email()} ) </li>
{{/each}}
</ul>
{{else}}
</thead>
<tbody>
{{each(i, row) itemsOnCurrentPage()}}
- <tr data-bind="css:{ 'modified': row.modified()}">
+ <tr data-bind="css:{ 'modified': row.modified()||row.usersModified()}">
{{each(j, columnDefinition) columns}}
{{var val = (typeof columnDefinition.rowText == 'function' ? columnDefinition.rowText(row) : row[columnDefinition.rowText])}}
<td id="role-${columnDefinition.rowText}-${row.name()}">