]> 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/UserEditorApplet.js
Fixes on natures management
[lgpl/argeo-commons.git] / security / runtime / org.argeo.security.ria / src / argeo-ria-lib / security / class / org / argeo / security / ria / UserEditorApplet.js
index 29d8aa0fedf7deb08fdbaa262ae0d27abfc4c6bd..8298228291ddf7a047b40477a969ba225be7f034 100644 (file)
@@ -7,14 +7,13 @@
 ****************************************************/
 qx.Class.define("org.argeo.security.ria.UserEditorApplet",
 {
-  extend : qx.ui.container.Composite,
+  extend : org.argeo.security.ria.components.UserEditor,
   implement : [org.argeo.ria.components.IView], 
-
+  
   construct : function(){
        this.base(arguments);
-       this.setLayout(new qx.ui.layout.VBox(5));
   },
-
+  
   properties : 
   {
        /**
@@ -22,7 +21,7 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet",
         */
        view : {
                init : null
-       },
+       },      
        /**
         * Commands definition, see {@link org.argeo.ria.event.CommandsManager#definitions} 
         */
@@ -36,14 +35,62 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet",
                                menu            : "Users",
                                toolbar         : "user",
                                callback        : function(e){
-                                       
+                                       // CALL SERVICE AND GET UP TO DATE USER
+                                       this.saveUser();
                                },
-                               selectionChange : function(viewName, data){
+                               selectionChange : function(viewName, data){
                                        if(viewName != "editor") return;
                                        var iApplet = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById("editor").getContent();
-                                       if(iApplet == null) this.setEnabled(true);
                                        this.setEnabled(iApplet.getModified());
-                                       //this.setEnabled(!(data == null || !data.length || data.length > 1));                                          
+                               },
+                               command         : null
+                       },
+                       "add_nature" : {
+                               label           : "Add Nature ...", 
+                               icon            : "org.argeo.security.ria/list-add.png",
+                               shortcut        : null,
+                               enabled         : true,
+                               menu            : "Natures",
+                               toolbar         : null,
+                               callback        : function(e){
+                               },
+                               submenuCallback : function(commandClass){
+                                       this._addNatureTab(commandClass, null, true);
+                               },
+                               submenu         : [
+                                       {"label" : "Totot", "icon":"","commandId" : "toto"},
+                                       {"label" : "Totot", "icon":"","commandId" : "toto"}
+                               ],
+                               selectionChange : function(viewName, data){
+                                       if(viewName != "editor") return;
+                                       var iApplet = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById("editor").getContent();
+                                       if(iApplet && iApplet.getCurrentNatureTabs() && iApplet.getNaturesManager().getDetectedNatures()
+                                               && iApplet.getCurrentNatureTabs().length < qx.lang.Object.getLength(iApplet.getNaturesManager().getDetectedNatures())){
+                                               this.setEnabled(true);
+                                       }else{
+                                               this.setEnabled(false);
+                                       }
+                               },
+                               command         : null                                  
+                       },
+                       "remove_nature" : {
+                               label           : "Remove Nature", 
+                               icon            : "org.argeo.security.ria/list-remove.png",
+                               shortcut        : null,
+                               enabled         : true,
+                               menu            : "Natures",
+                               toolbar         : null,
+                               callback        : function(e){
+                                       this.removeSelectedTab();
+                               },
+                               selectionChange : function(viewName, data){
+                                       if(viewName != "editor") return;
+                                       var iApplet = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById("editor").getContent();
+                                       if(iApplet && iApplet.getSelectedNatureTab() && iApplet.getSelectedNatureTab().getUserData("NATURE_CLASS")){
+                                               this.setEnabled(true);
+                                       }else{
+                                               this.setEnabled(false);
+                                       }
                                },
                                command         : null
                        },
@@ -57,7 +104,7 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet",
                                callback        : function(e){
                                        // Call service to delete
                                        var iApplet = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById("editor").getContent();
-                                       if(!iApplet.getModified()){
+                                       if(!iApplet.getModified() && !iApplet.getNaturesModified()){
                                                this.getView().closeCurrent();
                                                return;
                                        }
@@ -76,15 +123,14 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet",
                nullable:false, 
                check:"org.argeo.ria.components.ViewSelection"
        },
-       modified : {
-               init : false,
-               apply : "_applyModified"
-       },
-       rolesList : {
-               
+       instanceId : {
+               init:"",
+               event : "changeInstanceId"
        },
-       instanceId : {init:""},
-       instanceLabel : {init:"Editor"}         
+       instanceLabel : {
+               init:"Editor",
+               event : "changeInstanceLabel"
+       }
   },
 
   members :
@@ -94,112 +140,89 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet",
         * @param viewPane {org.argeo.ria.components.ViewPane} The viewPane.
         */
        init : function(viewPane, data){
-               if(!data){
+               if(!data.USER){
                        var now = new Date();
                        this.setInstanceId(now.getTime());
                        this.setInstanceLabel("New User");                      
                }else{
-                       this.setInstanceId(data);
-                       this.setInstanceLabel("User " + data);
+                       this.setInstanceId(data.USER);
+                       this.setInstanceLabel("User " + data.USER);
                }
                this.setView(viewPane);
-               this.setViewSelection(new org.argeo.ria.components.ViewSelection(viewPane.getViewId()));                
-               
-               // TOOLBAR
-               this.buttonGB = new qx.ui.container.Composite(new qx.ui.layout.HBox(5, "right"));
-               this.add(this.buttonGB);
-               
-               // GROUPBOXES
-               this.basicGB = new qx.ui.groupbox.GroupBox("Base Informations");
-               var grid = new qx.ui.layout.Grid(5,5);
-               this.basicGB.setLayout(grid);
-               grid.setColumnFlex(0,1);
-               grid.setColumnAlign(0,"right", "middle");
-               grid.setColumnFlex(1,2);
-               this._initializeGroupBox(this.basicGB);
-                               
-               this.passGB = new qx.ui.groupbox.GroupBox("Set/Modify Password");
-               this.passGB.setLayout(new qx.ui.layout.VBox());
-               this._initializeGroupBox(this.passGB);
+               this.setViewSelection(new org.argeo.ria.components.ViewSelection(viewPane.getViewId()));
 
-               this.naturesGB = new qx.ui.groupbox.GroupBox("User Natures");
-               this.naturesGB.setLayout(new qx.ui.layout.Dock());
-               this._initializeGroupBox(this.naturesGB);
-               
-               this.add(this.basicGB);
-               this.add(this.passGB);
-               this.add(this.naturesGB, {flex:1});             
-               
-               // FIELDS
-               this.usernameField = new qx.ui.form.TextField();
-               this.basicGB.add(new qx.ui.basic.Label("Username"), {row:0,column:0});                  
-               this.basicGB.add(this.usernameField, {row:0,column:1});
-               
-               this.rolesField = new org.argeo.ria.components.ui.MultipleComboBox();
-               this.rolesField.setChoiceValues(["ROLE_ADMIN", "ROLE_USER", "ROLE_USER1"]);
-               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.passGB.add(this.passPane.getContainer());
-               
-               this.naturesTab = new qx.ui.tabview.TabView("top");
-               this.simpleNature = new org.argeo.security.ria.components.SimpleUserNatureImpl();
+               this.initGUI(data.ROLES_LIST);
                
-               var page1 = new qx.ui.tabview.Page(this.simpleNature.getNatureLabel());
-               page1.setLayout(new qx.ui.layout.Dock());
-               page1.add(this.simpleNature.getContainer(), {edge:"center"});
-               this.naturesTab.add(page1);
-               this.naturesGB.add(this.naturesTab, {edge:"center"});
-                                       
-       },
-               
-       _attachListeners : function(){
-               this.usernameField.addListener("changeValue", function(){
-                       this.setModified(true);
-               }, this);
-               this.rolesField.addListener("changeValue", function(){
-                       this.setModified(true);
+               this.addListener("savedUser", function(e){  
+                       if(this.getCurrentUser()){
+                               this.setInstanceLabel("User " + this.getCurrentUser().getName());
+                               this.setInstanceId(this.getCurrentUser().getName());
+                       }
                }, this);
-               this.passPane.addListener("modified", function(){
-                       this.setModified(true);
-               }, this);
-               this.simpleNature.addListener("modified", function(){
-                       this.setModified(true);
-               }, this);               
-       },
-       
-       _initializeGroupBox: function(groupBox){
-               groupBox.setPadding(0);
-               groupBox.getChildrenContainer().setPadding(8);                  
-       },
-       
-       _applyModified : function(value){
-               if(value) this.getViewSelection().triggerEvent();
+                                                       
        },
        
        /**
         * Load a given row : the data passed must be a simple data array.
         * @param data {Element} The text xml description. 
         */
-       load : function(userData){
-               if(userData){
-                       this.usernameField.setValue(userData);
-               }
-               this.setRolesList(["ROLE_ADMIN", "ROLE_USER"]);
-               this._attachListeners();
-               var title = new qx.ui.basic.Atom(this.getInstanceLabel(), "org.argeo.security.ria/preferences-user.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});
+       load : function(userName){
+               if(this.getLoaded()){
+                       return;
+               }               
+               // MUST BE DONE AFTER COMMANDS ARE INITIALIZED! 
                var commands = this.getCommands();
-               var button = new qx.ui.form.Button("Save", "org.argeo.security.ria/document-save.png", commands["save_user"].command);                  
-               var button2 = new qx.ui.form.Button("Close", "org.argeo.security.ria/window-close.png", commands["close"].command);             
-               this.buttonGB.add(button);
-               this.buttonGB.add(button2);
+               var saveButton = commands["save_user"].command.getFormButton(); 
+               var closeButton = commands["close"].command.getFormButton(); 
+               var removeButton = commands["remove_nature"].command.getFormButton();
+               var natureButton = commands["add_nature"].command.getFormButton();
+               
+               this.getNaturesManager().addListener("changeNonAssignedNatures", function(event){
+                       var natures = event.getData();
+                       var newMenu = [];
+                       for(var key in natures){
+                               newMenu.push({
+                                       "label" : natures[key].NATURE_LABEL, 
+                                       "icon":"", 
+                                       "commandId" : natures[key]
+                                       });
+                       }
+                       commands["add_nature"].command.setMenu(newMenu);                
+               }, this);
+               
+               natureButton.setShow("icon");
+               removeButton.setShow("icon");
+               saveButton.setShow("icon");
+               closeButton.setShow("icon");
+               
+               this.buttonGB.add(saveButton);
+               this.buttonGB.add(closeButton);                 
+               this.natureButtonGB.add(natureButton);
+               this.natureButtonGB.add(removeButton);
+               
+               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);
+               }
+               
+               
+               this.setLoaded(true);
                
        },
                 
+       _applyDetailsModified : function(value){                
+               if(value) this.getViewSelection().triggerEvent();
+       },
+       
+       _applyNaturesModified : function(value){
+               if(value) this.getViewSelection().triggerEvent();
+       },      
+       
        addScroll : function(){
                return false;
        },