- user.setRoles((this.rolesField.getValue()||"").split(","));
- // GO TO AND RETURN FROM SERVER
- user.setNatures([
- {
- "email" : "",
- "firstName" : "",
- "lastName" : "",
- "type" : "org.argeo.security.nature.SimpleUserNature"
- }]
- );
- this.partialRefreshUser(user, ["details","natures"]);
- this.setModified(false);
+ var roles = this.rolesField.getValue();
+ if(roles && roles != ""){
+ user.setRoles(roles.split(","));
+ }else{
+ user.setRoles([]);
+ }
+
+ // GO TO AND RETURN FROM SERVER
+ 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();