X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=security%2Fruntime%2Forg.argeo.security.ria%2Fsrc%2Fargeo-ria-lib%2Fsecurity%2Fclass%2Forg%2Fargeo%2Fsecurity%2Fria%2FUsersApplet.js;h=7f0c55335b3f3e54284daea95310122342621458;hb=06f80b7b50619d1c997e2660eddb32a584cfc8a8;hp=4522746ac10cdcefc24c781304820623193a86db;hpb=81579a12a1b3fa8a21e1ad7944e5dccaa8beeadf;p=lgpl%2Fargeo-commons.git diff --git a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/UsersApplet.js b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/UsersApplet.js index 4522746ac..7f0c55335 100644 --- a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/UsersApplet.js +++ b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/UsersApplet.js @@ -3,7 +3,7 @@ * The only associated command is the "Close" command. */ /* ************************************************* -#asset(resource/org.argeo.ria.sample/window-close.png) +#asset(resource/org.argeo.security.ria/*) ****************************************************/ qx.Class.define("org.argeo.security.ria.UsersApplet", { @@ -29,60 +29,98 @@ qx.Class.define("org.argeo.security.ria.UsersApplet", commands : { init : { "new_user" : { - label : "Create User", - icon : "ria/window-close.png", + label : "New User", + icon : "org.argeo.security.ria/list-add.png", shortcut : "Control+n", enabled : true, menu : "Users", - toolbar : "user", + toolbar : null, callback : function(e){ // Call service to delete var classObj = org.argeo.security.ria.UserEditorApplet; - var iView = org.argeo.ria.components.ViewsManager.getInstance().initIViewClass(classObj, "editor"); + var initData = {USER:null,ROLES_LIST:this.getRolesList()}; + var iView = org.argeo.ria.components.ViewsManager.getInstance().initIViewClass(classObj, "editor", initData); iView.load(); + iView.addListener("savedUser", function(e){ + this.refreshUserEntry(e.getData()); + }, this); }, command : null - }, - "edit_user" : { - label : "Edit User", - icon : "ria/window-close.png", - shortcut : "Control+u", + }, + "delete_user" : { + label : "Delete User", + icon : "org.argeo.security.ria/list-remove.png", + shortcut : "Control+d", enabled : true, menu : "Users", - toolbar : "user", + toolbar : null, callback : function(e){ // Call service to delete - var crtUser = this.getViewSelection().getNodes()[0]; - var classObj = org.argeo.security.ria.UserEditorApplet; - var iView = org.argeo.ria.components.ViewsManager.getInstance().initIViewClass(classObj, "editor", crtUser); - iView.load(crtUser); + var username = this.getViewSelection().getNodes()[0]; + var deleteService = org.argeo.security.ria.SecurityAPI.getDeleteUserService(username); + deleteService.addListener("completed", function(response){ + if(response.getContent().status && response.getContent().status == "OK"){ + this.loadUsersList(); + } + }, this); + // Check if tab is opened before closing! + var editorTabPane = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById("editor"); + var iApplet = editorTabPane.contentExists(username); + var modal = new org.argeo.ria.components.Modal("Delete"); + if(iApplet){ + if(iApplet.getModified()){ + modal.addConfirm("There are unsaved changes, are you sure you want to delete this user?"); + modal.addListener("ok", function(e){ + editorTabPane.closeCurrent(); + deleteService.send(); + }, this); + modal.attachAndShow(); + }else{ + modal.addConfirm("Are you sure you want to delete user " + username + "?"); + modal.addListener("ok", function(e){ + editorTabPane.closeCurrent(); + deleteService.send(); + }, this); + modal.attachAndShow(); + } + }else{ + modal.addConfirm("Are you sure you want to delete user " + username + "?"); + modal.addListener("ok", function(e){ + deleteService.send(); + }, this); + modal.attachAndShow(); + } }, selectionChange : function(viewName, data){ if(viewName != "users") return; - this.setEnabled(!(data == null || !data.length || data.length > 1)); + this.setEnabled(!(data == null || !data.length || data.length>1)); }, command : null - }, - "delete_user" : { - label : "Delete User", - icon : "ria/window-close.png", - shortcut : "Control+s", + }, + "edit_user" : { + label : "Edit User", + icon : "org.argeo.security.ria/document-properties.png", + shortcut : "Control+u", enabled : true, menu : "Users", - toolbar : "user", + toolbar : null, callback : function(e){ // Call service to delete - var crtUsers = this.getViewSelection().getNodes(); - for(var i=0;i 1)); }, command : null - } + } } }, @@ -95,6 +133,14 @@ qx.Class.define("org.argeo.security.ria.UsersApplet", nullable:false, check:"org.argeo.ria.components.ViewSelection" }, + usersList : { + check : "Map", + apply : "_applyUsersList", + event : "changeUsersList" + }, + rolesList : { + check : "Array" + }, instanceId : {init:""}, instanceLabel : {init:""} }, @@ -107,7 +153,13 @@ qx.Class.define("org.argeo.security.ria.UsersApplet", */ init : function(viewPane){ this.setView(viewPane); - this.setViewSelection(new org.argeo.ria.components.ViewSelection(viewPane.getViewId())); + this.setViewSelection(new org.argeo.ria.components.ViewSelection(viewPane.getViewId())); + + this.toolBar = new qx.ui.toolbar.ToolBar(); + this.toolBarPart = new qx.ui.toolbar.Part(); + this.toolBar.add(this.toolBarPart); + viewPane.add(this.toolBar); + this.tableModel = new qx.ui.table.model.Filtered(); this.tableModel.setColumns(["username", "roles"]); this.table = new qx.ui.table.Table(this.tableModel, { @@ -123,19 +175,24 @@ qx.Class.define("org.argeo.security.ria.UsersApplet", this.table.getSelectionModel().addListener("changeSelection", function(){ this._selectionToValues(this.table.getSelectionModel(), this.getViewSelection()); }, this); - - this.setGuiMode("chooser"); + this.table.addListener("cellDblclick", function(cellEvent){ + this.getCommands()["edit_user"].command.execute(); + }, this); + + this.setRolesList([]); + this.setUsersList({}); + this.setGuiMode("clear"); }, _applyGuiMode : function(newMode, oldMode){ this.table.getSelectionModel().clearSelection(); this.resetHiddenRows(); if(newMode == "filter"){ - this.table.getSelectionModel().setSelectionMode(qx.ui.table.selection.Model.SINGLE_INTERVAL_SELECTION); + this.table.getSelectionModel().setSelectionMode(qx.ui.table.selection.Model.SINGLE_SELECTION); }else if(newMode == "chooser"){ this.table.getSelectionModel().setSelectionMode(qx.ui.table.selection.Model.MULTIPLE_INTERVAL_SELECTION_TOGGLE); }else if(newMode == "clear"){ - this.table.getSelectionModel().setSelectionMode(qx.ui.table.selection.Model.SINGLE_INTERVAL_SELECTION); + this.table.getSelectionModel().setSelectionMode(qx.ui.table.selection.Model.SINGLE_SELECTION); } }, @@ -166,21 +223,81 @@ qx.Class.define("org.argeo.security.ria.UsersApplet", * @param data {Element} The text xml description. */ load : function(){ - var data = [["root", "ROLE_ADMIN"], ["mbaudier", "ROLE_ADMIN,ROLE_USER"], ["cdujeu","ROLE_USER"], ["anonymous", ""]]; - this.tableModel.setData(data); + var commands = this.getCommands(); + this.toolBarPart.add(commands["new_user"].command.getToolbarButton()); + this.toolBarPart.add(commands["delete_user"].command.getToolbarButton()); + this.toolBarPart.add(commands["edit_user"].command.getToolbarButton()); + this.toolBar.setShow("icon"); + this.loadUsersList(); + + var rolesApplet = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById("roles").getContent(); + rolesApplet.addListener("changeRolesList", function(e){ + this.setRolesList(e.getData()); + this.loadUsersList(); + }, this); + + }, + + loadUsersList : function(){ + var selectionModel = this.table.getSelectionModel(); + selectionModel.clearSelection(); + var request = org.argeo.security.ria.SecurityAPI.getListUsersService(); + request.addListener("completed", function(response){ + var jSon = response.getContent(); + var usMap = {}; + for(var i=0;i