+
+ saveUser : function(){
+ var user = this.getCurrentUser();
+ user.setName(this.usernameField.getValue());
+ 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();
+ },
+
+ _addNatureTab : function(natureClass, natureData, select){
+ var crtTabs = this.getCurrentNatureTabs();
+ if(qx.lang.Array.contains(crtTabs, natureClass.NATURE_TYPE)){
+ this.error("There can only be one instance of a given nature type!");
+ return null;
+ }
+ if(!this.naturesTab.isVisible()){
+ if(this.fakePane) this.fakePane.setVisibility("excluded");
+ this.naturesTab.setVisibility("visible");
+ }
+ var page = new qx.ui.tabview.Page("Nature : " + natureClass.NATURE_LABEL);
+ page.setLayout(new qx.ui.layout.Dock());
+ page.setUserData("NATURE_CLASS", natureClass);
+ var newClass = new natureClass();
+ page.add(newClass.getContainer(), {edge:"center"});
+
+ buttons = new qx.ui.container.Composite(new qx.ui.layout.HBox(5, "center"));
+ var editB = new qx.ui.form.Button("Edit this Nature", "org.argeo.security.ria/document-properties-22.png");
+ var saveB = new qx.ui.form.Button("Save", "org.argeo.security.ria/dialog-apply.png");
+ var cancelB = new qx.ui.form.Button("Cancel", "org.argeo.security.ria/dialog-cancel.png");
+ buttons.add(editB);
+ buttons.add(saveB);
+ buttons.add(cancelB);
+ page.add(buttons, {edge:"south"});
+ editB.addListener("execute", function(){
+ newClass.setEditMode(true);
+ editB.setVisibility("excluded");
+ saveB.setVisibility("visible");
+ cancelB.setVisibility("visible");
+ });
+ cancelB.addListener("execute", function(){
+ if(newClass.getIsNew()){
+ this._removeNatureTab(natureClass);
+ }
+ newClass.setEditMode(false);
+ editB.setVisibility("visible");
+ saveB.setVisibility("excluded");
+ cancelB.setVisibility("excluded");
+ }, this);
+ saveB.addListener("execute", function(){
+ // SAVE CURRENT NATURE
+ var data = newClass.getData();
+ if(newClass.getIsNew()){
+ this.getCurrentUser().addNature(data);
+ }else{
+ this.getCurrentUser().updateNature(data);
+ }
+ this.saveUser();
+ this.setNaturesModified(false);
+ newClass.setEditMode(false);
+ editB.setVisibility("visible");
+ saveB.setVisibility("excluded");
+ cancelB.setVisibility("excluded");
+ }, this);
+ if(natureData){
+ newClass.setData(natureData);
+ cancelB.execute();
+ }else{
+ newClass.setIsNew(true);
+ editB.execute();
+ }
+ this.naturesTab.add(page);
+ crtTabs.push(natureClass.NATURE_TYPE);
+ this.getViewSelection().triggerEvent();
+ newClass.addListener("modified", function(){
+ this.setNaturesModified(true);
+ }, this);
+ if(select){
+ this.naturesTab.setSelected(page);
+ }
+ return page;
+ },
+
+ _removeNatureTab : function(natureClass){
+ this.naturesTab.getChildren().forEach(function(el){
+ if(el.getUserData("NATURE_CLASS") == natureClass){
+ this.naturesTab.remove(el);
+ qx.lang.Array.remove(this.getCurrentNatureTabs(), natureClass.NATURE_TYPE);
+ this.getViewSelection().triggerEvent();
+ }
+ }, this);
+ if(this.naturesTab.getChildren().length == 0){
+ this.naturesTab.setVisibility("excluded");
+ this.fakePane.setVisibility("visible");
+ }
+ },
+
+ removeSelectedTab : function(){
+ var selected = this.naturesTab.getSelected();
+ var tabClass = selected.getUserData("NATURE_CLASS");
+ var user = this.getCurrentUser();
+ user.removeNature(tabClass.NATURE_TYPE);
+ this.saveUser();
+ this._removeNatureTab(tabClass);
+ },
+
+ removeAllTabs : function(){
+ while(this.naturesTab.getSelected()){
+ this._removeNatureTab(this.naturesTab.getSelected().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");
+ }
+ },
+