]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/components/UserEditor.js
Start preparing 0.3.0
[lgpl/argeo-commons.git] / security / runtime / org.argeo.security.ria / src / argeo-ria-lib / security / class / org / argeo / security / ria / components / UserEditor.js
index 9d7f299a03549cc21e45c83066547097fd626a72..0af8bfdf5df3802171e49d7ed01acee85f539aad 100644 (file)
@@ -3,7 +3,7 @@
  * The only associated command is the "Close" command.
  */
 /* *************************************************
-#asset(resource/org.argeo.security.ria/*)
+#asset(resource/org/argeo/security/ria/*)
 ****************************************************/
 qx.Class.define("org.argeo.security.ria.components.UserEditor",
 {
@@ -20,6 +20,9 @@ qx.Class.define("org.argeo.security.ria.components.UserEditor",
   
   properties : 
   {
+       selfEdition : {
+               init : false
+       },
        modified : {
                init : false,
                apply : "_applyDetailsModified"
@@ -36,7 +39,8 @@ qx.Class.define("org.argeo.security.ria.components.UserEditor",
        },
        currentNatureTabs : {           
        },
-       availableNatures : {            
+       naturesManager : { 
+               check : "org.argeo.security.ria.components.NaturesManager"
        },
        selectedNatureTab : {   
                nullable : true
@@ -49,9 +53,8 @@ qx.Class.define("org.argeo.security.ria.components.UserEditor",
   {
        initGUI : function(ROLES_LIST){
 
-               this.naturesManager = new org.argeo.security.ria.components.NaturesManager();
-               var detectedNatures = this.naturesManager.getDetectedNatures();
-               this.setAvailableNatures(detectedNatures);
+               var naturesManager = new org.argeo.security.ria.components.NaturesManager();
+               this.setNaturesManager(naturesManager);
                
                // TOOLBAR
                this.buttonGB = new qx.ui.container.Composite(new qx.ui.layout.HBox(5, "right"));
@@ -95,7 +98,7 @@ qx.Class.define("org.argeo.security.ria.components.UserEditor",
                this.basicGB.add(new qx.ui.basic.Label("Roles"), {row:1,column:0});             
                this.basicGB.add(this.rolesField, {row:1,column:1});
                
-               this.passPane = new org.argeo.security.ria.components.PasswordCredentialImpl();
+               this.passPane = new org.argeo.security.ria.components.PasswordCredentialImpl(this.getSelfEdition());
                this.passGB.add(this.passPane.getContainer());
                
                //this.naturesTab.add(this.basicPage);
@@ -113,12 +116,12 @@ qx.Class.define("org.argeo.security.ria.components.UserEditor",
                this.fakePane.setMarginTop(30);
                this.add(this.fakePane, {flex:1});
                
-               title = new qx.ui.basic.Atom("User Details", "org.argeo.security.ria/preferences-users.png");
+               title = new qx.ui.basic.Atom("User Details", "org/argeo/security/ria/preferences-users.png");
                title.setFont(qx.bom.Font.fromString("16px sans-serif bold"));                  
                this.buttonGB.add(title);
                this.buttonGB.add(new qx.ui.core.Spacer(), {flex:1});
 
-               var title2 = new qx.ui.basic.Atom("User Natures", "org.argeo.security.ria/identity.png");
+               var title2 = new qx.ui.basic.Atom("User Natures", "org/argeo/security/ria/identity.png");
                title2.setFont(qx.bom.Font.fromString("16px sans-serif bold"));                 
                this.natureButtonGB.add(title2);
                this.natureButtonGB.add(new qx.ui.core.Spacer(), {flex:1});             
@@ -162,7 +165,7 @@ qx.Class.define("org.argeo.security.ria.components.UserEditor",
                        if(pass != null && !this.passPane.validate()){
                                this.error("Warning, passwords differ!");
                                return;                                 
-                       }
+                       }                       
                }
                this.passPane.clear();
                var saveCompletedCallback = qx.lang.Function.bind(function(){
@@ -171,16 +174,21 @@ qx.Class.define("org.argeo.security.ria.components.UserEditor",
                        this.setModified(false);
                        this.fireDataEvent("savedUser", user);                          
                }, this);
-               var userService = user.getSaveService();
+               var userService = user.getSaveService(this.getSelfEdition());
                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);
+                               var passService;
+                               if(!this.getSelfEdition()){
+                                       passService = org.argeo.security.ria.SecurityAPI.getUpdateUserPassService(user.getName(), pass);
+                               }else{
+                                       passService = org.argeo.security.ria.SecurityAPI.getUpdatePassService(pass.oldPass, pass.newPass);
+                               }
                                passService.addListener("completed", function(response){
-                                       if(response.getContent().status){
+                                       if(response.getContent().status != "ERROR"){
                                                this.info(response.getContent().message);
                                        }
                                        saveCompletedCallback();
@@ -207,12 +215,12 @@ qx.Class.define("org.argeo.security.ria.components.UserEditor",
                page.setLayout(new qx.ui.layout.Dock());
                page.setUserData("NATURE_CLASS", natureClass);
                var newClass = new natureClass();
-               page.add(newClass.getContainer(), {edge:"center"});
+               page.add(new qx.ui.container.Scroll(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");
+               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);
@@ -332,7 +340,7 @@ qx.Class.define("org.argeo.security.ria.components.UserEditor",
                        this.usernameField.setValue(user.getName());
                        this.usernameField.setReadOnly(true);
                        this.rolesField.setValue(user.getRoles());
-                       var userNatureTabs = this.naturesManager.detectNaturesInData(user.getNatures());
+                       var userNatureTabs = this.getNaturesManager().detectNaturesInData(user.getNatures());
                        if(userNatureTabs.length){
                                userNatureTabs.forEach(function(el){
                                        this._addNatureTab(el.NATURE_CLASS, el.NATURE_DATA);
@@ -343,6 +351,12 @@ qx.Class.define("org.argeo.security.ria.components.UserEditor",
                userDataService.send();
        },
        
+       clearUserData : function(){
+               this.usernameField.setValue("");
+               this.rolesField.setValue([]);
+               this.removeAllTabs();
+       },
+       
        partialRefreshUser : function(user, target){
                if(!qx.lang.Type.isArray(target)) target = [target];
                
@@ -351,7 +365,7 @@ qx.Class.define("org.argeo.security.ria.components.UserEditor",
                                var selectedTab = this.getSelectedNatureTab().getUserData("NATURE_CLASS");
                        }
                        this.removeAllTabs();
-                       var userNatureTabs = this.naturesManager.detectNaturesInData(user.getNatures());
+                       var userNatureTabs = this.getNaturesManager().detectNaturesInData(user.getNatures());
                        if(userNatureTabs.length){
                                userNatureTabs.forEach(function(el){
                                        this._addNatureTab(el.NATURE_CLASS, el.NATURE_DATA, (selectedTab && selectedTab == el.NATURE_CLASS));