toolbar : null,
callback : function(e){
// Prompt for new name
+ var modal = new org.argeo.ria.components.Modal();
+ modal.makePromptForm("Please enter a role name", function(roleName){
+ var service = org.argeo.security.ria.SecurityAPI.getCreateRoleService(roleName);
+ service.addListener("completed", function(response){
+ this.loadRolesList();
+ }, this);
+ service.send();
+ }, this);
+ modal.attachAndShow();
},
command : null
},
toolbar : null,
callback : function(e){
// Call service to delete
- var crtUsers = this.getViewSelection().getNodes();
- for(var i=0;i<crtUsers.length;i++){
- alert("Delete " + crtUsers[i]);
- }
+ var roles = this.getViewSelection().getNodes();
+ var modal = new org.argeo.ria.components.Modal("Delete");
+ modal.addConfirm("Are you sure you want to delete the selected roles?");
+ modal.addListener("ok", function(e){
+ for(var i=0;i<roles.length;i++){
+ var service = org.argeo.security.ria.SecurityAPI.getDeleteRoleService(roles[i]);
+ service.addListener("completed", function(response){
+ this.loadRolesList();
+ }, this);
+ service.send();
+ }
+ }, this);
+ modal.attachAndShow();
},
selectionChange : function(viewName, data){
if(viewName != "roles") return;
guiMode : {
apply : "_applyGuiMode"
},
+ rolesList : {
+ check : "Array",
+ event : "changeRolesList"
+ },
chooserOriginalSelection : {},
chooserSelectionModified : {
init:false,
this.table.addListener("cellDblclick", function(cellEvent){
this.setGuiMode("edit");
}, this);
+ this.addListener("changeRolesList", function(event){
+ var data = [];
+ event.getData().forEach(function(el){data.push([el]);});
+ this.tableModel.setData(data);
+ }, this);
this.setGuiMode("clear");
},
},
saveRoleModifications : function(deltaPlus, deltaMinus){
- console.log(deltaPlus);
- console.log(deltaMinus);
+ // LOAD CONCERNED USERS
+ var selectionModel = this.table.getSelectionModel();
+ if(!selectionModel.getSelectedCount()){
+ return;
+ }
+ var roleValue = this._selectionToValues(selectionModel)[0];
+
+ var users = deltaPlus.concat(deltaMinus);
+ var modal = new org.argeo.ria.components.Modal("Batch Update", "", "Please wait, updating roles for selected users");
+ modal.attachAndShow();
+ for(var i=0;i<users.length;i++){
+ var user = users[i];
+ var userDetailService = org.argeo.security.ria.SecurityAPI.getUserDetailsService(users[i]);
+ userDetailService.addListener("completed", function(response){
+ var userRoles = response.getContent().roles;
+ if(qx.lang.Array.contains(deltaPlus, user)){
+ userRoles.push(roleValue);
+ }else if(qx.lang.Array.contains(deltaMinus, user)){
+ qx.lang.Array.remove(userRoles, roleValue);
+ }
+ var userSaveService = org.argeo.security.ria.SecurityAPI.getUpdateUserService(response.getContent());
+ userSaveService.setAsynchronous(false);
+ userSaveService.send();
+ }, this);
+ userDetailService.setAsynchronous(false);
+ userDetailService.send();
+ }
+ this.fireDataEvent("changeRolesList", this.getRolesList());
+ modal.hide();
+ modal.destroy();
},
monitorChooserSelectionChanges : function(event){
*/
load : function(){
- var service = org.argeo.security.ria.SecurityAPI.getListRolesService();
- service.addListener("completed", function(response){
- var data = [];
- response.getContent().forEach(function(el){data.push([el]);});
- this.tableModel.setData(data);
- }, this);
- service.send();
-
var commands = this.getCommands();
this.toolBarPart.add(commands["new_role"].command.getToolbarButton());
this.toolBarPart.add(commands["delete_role"].command.getToolbarButton());
this.toolBar.add(this.cancelButton);
this.toolBar.setShow("icon");
+ this.loadRolesList();
+
+ },
+
+ loadRolesList : function(){
+ this.setRolesList([]);
+ var service = org.argeo.security.ria.SecurityAPI.getListRolesService();
+ service.addListener("completed", function(response){
+ this.setRolesList(response.getContent());
+ }, this);
+ service.send();
},
addScroll : function(){