X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=security%2Fruntime%2Forg.argeo.security.ria%2Fsrc%2Fargeo-ria-lib%2Fsecurity%2Fclass%2Forg%2Fargeo%2Fsecurity%2Fria%2FUserEditorApplet.js;h=c7921dcc8ffc7af6be67d9dae0de9e4aa2a5aed0;hb=3112a8b93396eb3fb95fc8b1038a5dfb224d5006;hp=55316d26e5f980ae371bdf0e19208cae1d7528a2;hpb=1af54f2dad396ac71d9872d82c2981e4ac9c2281;p=lgpl%2Fargeo-commons.git diff --git a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/UserEditorApplet.js b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/UserEditorApplet.js index 55316d26e..c7921dcc8 100644 --- a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/UserEditorApplet.js +++ b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/UserEditorApplet.js @@ -9,12 +9,16 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet", { extend : qx.ui.container.Composite, implement : [org.argeo.ria.components.IView], - + construct : function(){ this.base(arguments); this.setLayout(new qx.ui.layout.VBox(5)); }, - + + events : { + "savedUser" : "qx.event.type.Data" + }, + properties : { /** @@ -22,7 +26,7 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet", */ view : { init : null - }, + }, /** * Commands definition, see {@link org.argeo.ria.event.CommandsManager#definitions} */ @@ -135,8 +139,14 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet", rolesList : { }, - instanceId : {init:""}, - instanceLabel : {init:"Editor"}, + instanceId : { + init:"", + event : "changeInstanceId" + }, + instanceLabel : { + init:"Editor", + event : "changeInstanceLabel" + }, loaded : { init : false }, @@ -180,8 +190,8 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet", this.setCurrentNatureTabs([]); this.naturesTab = new qx.ui.tabview.TabView("top"); - this.naturesTab.addListener("changeSelected", function(e){ - this.setSelectedNatureTab(e.getData()); + this.naturesTab.addListener("changeSelection", function(e){ + this.setSelectedNatureTab(e.getData()[0] || null); this.getViewSelection().triggerEvent(); }, this); @@ -249,15 +259,71 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet", saveUser : function(){ var user = this.getCurrentUser(); user.setName(this.usernameField.getValue()); - user.setRoles((this.rolesField.getValue()||"").split(",")); + var roles = this.rolesField.getValue(); + if(roles && roles != ""){ + user.setRoles(roles.split(",")); + }else{ + user.setRoles([]); + } + // GO TO AND RETURN FROM SERVER - var userService = user.getSaveService(); - userService.send(); - userService.addListener("completed", function(e){ + if(user.isCreate()){ + if(!this.passPane.validate()){ + this.error("Warning, passwords differ!"); + return; + } + user.setPassword(this.passPane.getData()); + var create = true; + var userExists = false; + var req = org.argeo.security.ria.SecurityAPI.getUserExistsService(user.getName()); + req.addListener("completed", function(response){ + userExists = response.getContent().value; + }, this); + req.setAsynchronous(false); + req.send(); + if(userExists){ + this.error("User already exists, choose another name!"); + return; + } + }else{ + var pass = this.passPane.getData(); + if(pass != null && !this.passPane.validate()){ + this.error("Warning, passwords differ!"); + return; + } + } + this.passPane.clear(); + var saveCompletedCallback = qx.lang.Function.bind(function(){ + if(create){ + this.setInstanceLabel("User " + user.getName()); + this.setInstanceId(user.getName()); + } + this._setGuiInCreateMode(false); this.partialRefreshUser(user, ["details","natures"]); this.setModified(false); this.getViewSelection().triggerEvent(); + this.fireDataEvent("savedUser", user); }, this); + var userService = user.getSaveService(); + userService.addListener("completed", function(response){ + if(response.getContent().status && response.getContent().status == "ERROR"){ + return; + } + user.load(response.getContent(), "json"); + if(pass!=null){ + var passService = org.argeo.security.ria.SecurityAPI.getUpdateUserPassService(user.getName(), pass); + passService.addListener("completed", function(response){ + if(response.getContent().status){ + this.info(response.getContent().message); + } + saveCompletedCallback(); + }, this); + passService.send(); + }else{ + saveCompletedCallback(); + } + }, this); + userService.send(); }, _addNatureTab : function(natureClass, natureData, select){ @@ -328,7 +394,7 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet", this.setNaturesModified(true); }, this); if(select){ - this.naturesTab.setSelected(page); + this.naturesTab.setSelection([page]); } return page; }, @@ -348,7 +414,8 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet", }, removeSelectedTab : function(){ - var selected = this.naturesTab.getSelected(); + if(this.naturesTab.isSelectionEmpty()) return; + var selected = this.naturesTab.getSelection()[0]; var tabClass = selected.getUserData("NATURE_CLASS"); var user = this.getCurrentUser(); user.removeNature(tabClass.NATURE_TYPE); @@ -357,11 +424,23 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet", }, removeAllTabs : function(){ - while(this.naturesTab.getSelected()){ - this._removeNatureTab(this.naturesTab.getSelected().getUserData("NATURE_CLASS")); + while(!this.naturesTab.isSelectionEmpty()){ + this._removeNatureTab(this.naturesTab.getSelection()[0].getUserData("NATURE_CLASS")); + } + }, + + _setGuiInCreateMode : function(bool){ + if(bool){ + if(!this.natureButtonGB.isVisible()) return; + this.natureButtonGB.hide(); + this.fakePane.setVisibility("excluded"); + }else{ + if(this.natureButtonGB.isVisible()) return; + this.natureButtonGB.show(); + this.fakePane.setVisibility("visible"); } }, - + _attachListeners : function(){ this.usernameField.addListener("changeValue", function(){ this.setModified(true); @@ -387,30 +466,40 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet", if(value) this.getViewSelection().triggerEvent(); }, - loadUserData : function(user){ - this.setCurrentUser(user); - this.usernameField.setValue(user.getName()); - this.usernameField.setReadOnly(true); - this.rolesField.setValue(user.getRoles()); - var userNatureTabs = this.naturesManager.detectNaturesInData(user.getNatures()); - if(userNatureTabs.length){ - userNatureTabs.forEach(function(el){ - this._addNatureTab(el.NATURE_CLASS, el.NATURE_DATA); - }, this); - } + loadUserData : function(userName){ + var userDataService = org.argeo.security.ria.SecurityAPI.getUserDetailsService(userName); + userDataService.addListener("completed", function(response){ + var user = new org.argeo.security.ria.model.User(); + user.load(response.getContent(), "json"); + this.setCurrentUser(user); + this.usernameField.setValue(user.getName()); + this.usernameField.setReadOnly(true); + this.rolesField.setValue(user.getRoles()); + var userNatureTabs = this.naturesManager.detectNaturesInData(user.getNatures()); + if(userNatureTabs.length){ + userNatureTabs.forEach(function(el){ + this._addNatureTab(el.NATURE_CLASS, el.NATURE_DATA); + }, this); + } + this._attachListeners(); + }, this); + userDataService.send(); }, partialRefreshUser : function(user, target){ - if(!qx.lang.Array.isArray(target)) target = [target]; + if(!qx.lang.Type.isArray(target)) target = [target]; if(qx.lang.Array.contains(target,"natures")){ + if(this.getSelectedNatureTab()){ + var selectedTab = this.getSelectedNatureTab().getUserData("NATURE_CLASS"); + } this.removeAllTabs(); var userNatureTabs = this.naturesManager.detectNaturesInData(user.getNatures()); if(userNatureTabs.length){ userNatureTabs.forEach(function(el){ - this._addNatureTab(el.NATURE_CLASS, el.NATURE_DATA); + this._addNatureTab(el.NATURE_CLASS, el.NATURE_DATA, (selectedTab && selectedTab == el.NATURE_CLASS)); }, this); - } + } } if(qx.lang.Array.contains(target,"details")){ this.setInstanceLabel("User "+user.getName()); @@ -424,7 +513,7 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet", * Load a given row : the data passed must be a simple data array. * @param data {Element} The text xml description. */ - load : function(user){ + load : function(userName){ if(this.getLoaded()){ return; } @@ -452,11 +541,12 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet", this.natureButtonGB.add(natureButton); this.natureButtonGB.add(removeButton); - if(user){ - this.loadUserData(user); - this._attachListeners(); + if(userName){ + this.loadUserData(userName); + this._setGuiInCreateMode(false); }else{ this.setCurrentUser(new org.argeo.security.ria.model.User()); + this._setGuiInCreateMode(true); this._attachListeners(); this.setModified(true); }