Lot of changes in the user editor
authorCharles du Jeu <charles.dujeu@gmail.com>
Fri, 18 Sep 2009 16:33:23 +0000 (16:33 +0000)
committerCharles du Jeu <charles.dujeu@gmail.com>
Fri, 18 Sep 2009 16:33:23 +0000 (16:33 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@2973 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

15 files changed:
security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/RolesApplet.js
security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/SecurityAPI.js
security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/UserEditorApplet.js
security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/UsersApplet.js
security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/components/CoworkerNatureImpl.js
security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/components/INaturePane.js
security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/components/NaturesManager.js [new file with mode: 0644]
security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/components/SimpleUserNatureImpl.js
security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/model/Nature.js
security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/model/User.js
security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/resource/org.argeo.security.ria/dialog-apply.png [new file with mode: 0644]
security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/resource/org.argeo.security.ria/dialog-cancel.png [new file with mode: 0644]
security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/resource/org.argeo.security.ria/document-properties-22.png [new file with mode: 0644]
security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/resource/org.argeo.security.ria/identity.png [new file with mode: 0644]
security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/resource/org.argeo.security.ria/preferences-users.png [new file with mode: 0644]

index 6cd0b43995d850f8105841880830d933e8001704..da45d965bb08421cee79f69f2e5fad8c96b42fb4 100644 (file)
@@ -126,7 +126,7 @@ qx.Class.define("org.argeo.security.ria.RolesApplet",
                        this._selectionToValues(this.table.getSelectionModel(), this.getViewSelection());
                }, this);
                
-               this.rolesUsersStub = {"ROLE_ADMIN":["root","mbaudier"],"ROLE_USER":["mbaudier","cdujeu"]};
+               this.rolesUsersStub = {"ROLE_ADMIN":["gandalf"],"ROLE_USER":["demo","frodo","gandalf"]};
                                        
                this.toggleButton = new qx.ui.form.ToggleButton("Filter", "org.argeo.security.ria/go-next.png");
                this.toggleButton.set({
@@ -157,8 +157,14 @@ qx.Class.define("org.argeo.security.ria.RolesApplet",
                });
                
                this.saveButton.addListener("execute", function(){
-                       alert("Saving changes...");
-                       this.setGuiMode(this.initialState);
+                       if(!this.usersAppletReference){
+                               this.setGuiMode(this.initialState);
+                               return;
+                       }
+                       var newSelection = this.usersAppletReference.getViewSelection().getNodes();
+                       var diff = this._selectionDiff(this.getChooserOriginalSelection(), newSelection);
+                       this.saveRoleModifications(diff.deltaPlus, diff.deltaMinus);
+                       this.setGuiMode(this.initialState);
                }, this);
                this.cancelButton.addListener("execute", function(){
                        if(!this.getChooserSelectionModified()){
@@ -224,13 +230,17 @@ qx.Class.define("org.argeo.security.ria.RolesApplet",
                }
        },
        
+       saveRoleModifications : function(deltaPlus, deltaMinus){
+               console.log(deltaPlus);
+               console.log(deltaMinus);
+       },
+       
        monitorChooserSelectionChanges : function(event){
                if(!this.usersAppletReference || this.getChooserSelectionModified()) return;
                var initialSelection = this.getChooserOriginalSelection();
                var crtSelection = event.getTarget().getNodes();
                if(!qx.lang.Array.equals(initialSelection.sort(), crtSelection.sort())){
-                       this.setChooserSelectionModified(true);
-                       console.log("Changed!");
+                       this.setChooserSelectionModified(true);                         
                        this.saveButton.setEnabled(true);
                }
        },
@@ -282,6 +292,14 @@ qx.Class.define("org.argeo.security.ria.RolesApplet",
                return values;
        },
        
+       _selectionDiff : function(initialSelection, modifiedSelection){
+               var deltaMinus = qx.lang.Array.clone(initialSelection);
+               var deltaPlus = qx.lang.Array.clone(modifiedSelection);
+               qx.lang.Array.exclude(deltaPlus, initialSelection);
+               qx.lang.Array.exclude(deltaMinus, modifiedSelection);
+               return {deltaPlus : deltaPlus, deltaMinus : deltaMinus};
+       },
+       
        /**
         * Load a given row : the data passed must be a simple data array.
         * @param data {Element} The text xml description. 
index e4f3e846e51d364c83135127da19e5253bc07d95..e138d861b76ecc19b30b66322189ed08904eac4c 100644 (file)
@@ -2,7 +2,7 @@ qx.Class.define("org.argeo.security.ria.SecurityAPI", {
        extend : qx.core.Object,\r
        statics : {\r
                \r
-               DEFAULT_CONTEXT : "org.argeo.security.ria",\r
+               DEFAULT_CONTEXT : "/org.argeo.security.webapp",\r
                \r
                USERS_LIST_SERVICE : "getUsersList.security",\r
                USER_EXISTS_SERVICE : "userExists.security",            \r
@@ -31,7 +31,7 @@ qx.Class.define("org.argeo.security.ria.SecurityAPI", {
                getServiceRequest : function(serviceName) {\r
                        var serviceManager = org.argeo.ria.remote.RequestManager.getInstance();\r
                        return serviceManager.getRequest(\r
-                               org.argeo.slc.ria.SlcApi.DEFAULT_CONTEXT + "/" + serviceName, \r
+                               org.argeo.security.ria.SecurityAPI.DEFAULT_CONTEXT + "/" + serviceName, \r
                                "GET",\r
                                "application/json");\r
                },\r
index 772cf2e7fc18deb8ec57ce34581573a1c0d38225..2d51a172e3e7a17f39e7827cea1b58c25218ca43 100644 (file)
@@ -36,14 +36,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.getAvailableNatures()
+                                               && iApplet.getCurrentNatureTabs().length < qx.lang.Object.getLength(iApplet.getAvailableNatures())){
+                                               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 +105,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;
                                        }
@@ -78,7 +126,11 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet",
        },
        modified : {
                init : false,
-               apply : "_applyModified"
+               apply : "_applyDetailsModified"
+       },
+       naturesModified : {
+               init : false,
+               apply : "_applyNaturesModified"
        },
        rolesList : {
                
@@ -87,6 +139,16 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet",
        instanceLabel : {init:"Editor"},
        loaded : {
                init : false
+       },
+       currentNatureTabs : {           
+       },
+       availableNatures : {            
+       },
+       selectedNatureTab : {   
+               nullable : true
+       },
+       currentUser : {
+               
        }
   },
 
@@ -106,13 +168,28 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet",
                        this.setInstanceLabel("User " + data);
                }
                this.setView(viewPane);
-               this.setViewSelection(new org.argeo.ria.components.ViewSelection(viewPane.getViewId()));                
+               this.setViewSelection(new org.argeo.ria.components.ViewSelection(viewPane.getViewId()));
+
+               this.naturesManager = new org.argeo.security.ria.components.NaturesManager();
+               var detectedNatures = this.naturesManager.getDetectedNatures();
+               this.setAvailableNatures(detectedNatures);
                
                // TOOLBAR
                this.buttonGB = new qx.ui.container.Composite(new qx.ui.layout.HBox(5, "right"));
                this.add(this.buttonGB);
                
+               this.setCurrentNatureTabs([]);
+               this.naturesTab = new qx.ui.tabview.TabView("top");
+               this.naturesTab.addListener("changeSelected", function(e){
+                       this.setSelectedNatureTab(e.getData());
+                       this.getViewSelection().triggerEvent();
+               }, this);
+               
+               this.basicPage = new qx.ui.tabview.Page("Basic Information");
+               this.basicPage.setLayout(new qx.ui.layout.VBox(5));
+               
                // GROUPBOXES
+               
                this.basicGB = new qx.ui.groupbox.GroupBox("Base Informations");
                var grid = new qx.ui.layout.Grid(5,5);
                this.basicGB.setLayout(grid);
@@ -125,13 +202,8 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet",
                this.passGB.setLayout(new qx.ui.layout.VBox());
                this._initializeGroupBox(this.passGB);
 
-               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();
@@ -146,23 +218,137 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet",
                this.passPane = new org.argeo.security.ria.components.PasswordCredentialImpl();
                this.passGB.add(this.passPane.getContainer());
                
-               this.naturesTab = new qx.ui.tabview.TabView("top");
+               //this.naturesTab.add(this.basicPage);
+               this.natureButtonGB = new qx.ui.container.Composite(new qx.ui.layout.HBox(5, "right"));
+               this.natureButtonGB.setMarginTop(15);
+               this.add(this.natureButtonGB);
                
-               this.simpleNature = new org.argeo.security.ria.components.SimpleUserNatureImpl();               
-               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.add(this.naturesTab, {flex:1});
                
-               this.coWorkerNature = new org.argeo.security.ria.components.CoworkerNatureImpl();               
-               var page2 = new qx.ui.tabview.Page(this.coWorkerNature.getNatureLabel());
-               page2.setLayout(new qx.ui.layout.Dock());
-               page2.add(this.coWorkerNature.getContainer(), {edge:"center"});
-               this.naturesTab.add(page2);
+               this.naturesTab.setVisibility("excluded");
+               this.fakePane = new qx.ui.container.Composite(new qx.ui.layout.Canvas());
+               this.fakePane.setVisibility("visible");
+               this.fakePane.setDecorator("tabview-pane");
+               this.fakePane.setMarginTop(30);
+               this.add(this.fakePane, {flex:1});
                
-               this.naturesGB.add(this.naturesTab, {edge:"center"});
+               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");
+               title2.setFont(qx.bom.Font.fromString("16px sans-serif bold"));                 
+               this.natureButtonGB.add(title2);
+               this.natureButtonGB.add(new qx.ui.core.Spacer(), {flex:1});             
+               
                                        
        },
+       
+       saveUser : function(){
+               var user = this.getCurrentUser();
+               user.setName(this.usernameField.getValue());
+               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);                
+       },
+       
+       _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(){
+                       newClass.setEditMode(false);
+                       editB.setVisibility("visible");
+                       saveB.setVisibility("excluded");
+                       cancelB.setVisibility("excluded");
+               });
+               saveB.addListener("execute", function(){
+                       // SAVE CURRENT NATURE
+                       this.setNaturesModified(false);
+                       newClass.setEditMode(false);
+                       editB.setVisibility("visible");
+                       saveB.setVisibility("excluded");
+                       cancelB.setVisibility("excluded");
+               }, this);
+               if(natureData){
+                       newClass.setData(natureData);
+                       cancelB.execute();
+               }else{
+                       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();
+               this._removeNatureTab(selected.getUserData("NATURE_CLASS"));
+       },
+       
+       removeAllTabs : function(){
+               while(this.naturesTab.getSelected()){
+                       this._removeNatureTab(this.naturesTab.getSelected().getUserData("NATURE_CLASS"));
+               }
+       },
                
        _attachListeners : function(){
                this.usernameField.addListener("changeValue", function(){
@@ -174,12 +360,6 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet",
                this.passPane.addListener("modified", function(){
                        this.setModified(true);
                }, this);
-               this.simpleNature.addListener("modified", function(){
-                       this.setModified(true);
-               }, this);               
-               this.coWorkerNature.addListener("modified", function(){
-                       this.setModified(true);
-               }, this);               
        },
        
        _initializeGroupBox: function(groupBox){
@@ -187,32 +367,91 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet",
                groupBox.getChildrenContainer().setPadding(8);                  
        },
        
-       _applyModified : function(value){
+       _applyDetailsModified : function(value){                
                if(value) this.getViewSelection().triggerEvent();
        },
        
+       _applyNaturesModified : function(value){
+               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);
+               }               
+       },
+       
+       partialRefreshUser : function(user, target){
+               if(!qx.lang.Array.isArray(target)) target = [target];
+               
+               if(qx.lang.Array.contains(target,"natures")){
+                       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);
+                       }                                       
+               }
+               if(qx.lang.Array.contains(target,"details")){
+                       this.setInstanceLabel("User "+user.getName());
+                       this.usernameField.setValue(user.getName());
+                       this.rolesField.setValue(user.getRoles());  
+                       this.usernameField.setReadOnly(true);
+               }
+       },
+       
        /**
         * Load a given row : the data passed must be a simple data array.
         * @param data {Element} The text xml description. 
         */
-       load : function(userData){
+       load : function(user){
                if(this.getLoaded()){
                        return;
                }
-               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});
+               
+               // 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();
+               
+               var detectedNatures = this.getAvailableNatures();
+               var newMenu = [];
+               for(var key in detectedNatures){
+                       newMenu.push({"label" : detectedNatures[key].NATURE_LABEL, "icon":"", "commandId" : detectedNatures[key]});
+               }
+               commands["add_nature"].command.setMenu(newMenu);
+               
+               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(user){
+                       this.loadUserData(user);
+                       this._attachListeners();
+               }else{
+                       this.setCurrentUser(new org.argeo.security.ria.model.User());
+                       this._attachListeners();
+                       this.setModified(true);
+               }
+               
+               
                this.setLoaded(true);
                
        },
index f5e13c121a2862d5dcfbf02f3cc96bdd325e0224..9438113ffe9df51dc29ea7e184eb2d931777b658 100644 (file)
@@ -73,9 +73,10 @@ qx.Class.define("org.argeo.security.ria.UsersApplet",
                                callback        : function(e){
                                        // Call service to delete
                                        var crtUser = this.getViewSelection().getNodes()[0];
+                                       var userObject = this.getUsersList()[crtUser];
                                        var classObj = org.argeo.security.ria.UserEditorApplet;
                                        var iView = org.argeo.ria.components.ViewsManager.getInstance().initIViewClass(classObj, "editor", crtUser);
-                                       iView.load(crtUser);                                    
+                                       iView.load(userObject);                                 
                                },
                                selectionChange : function(viewName, data){
                                        if(viewName != "users") return;
@@ -95,6 +96,10 @@ qx.Class.define("org.argeo.security.ria.UsersApplet",
                nullable:false, 
                check:"org.argeo.ria.components.ViewSelection"
        },
+       usersList : {
+               check : "Map",
+               event : "changeUsersList"
+       },
        instanceId : {init:""},
        instanceLabel : {init:""}
   },
@@ -109,6 +114,7 @@ qx.Class.define("org.argeo.security.ria.UsersApplet",
                this.setView(viewPane);
                this.setViewSelection(new org.argeo.ria.components.ViewSelection(viewPane.getViewId()));
                
+               this.setUsersList({});
                this.toolBar = new qx.ui.toolbar.ToolBar();
                this.toolBarPart = new qx.ui.toolbar.Part();
                this.toolBar.add(this.toolBarPart);             
@@ -132,7 +138,9 @@ qx.Class.define("org.argeo.security.ria.UsersApplet",
                this.table.addListener("cellDblclick", function(cellEvent){
                        this.getCommands()["edit_user"].command.execute();
                }, this);
-               
+               this.addListener("changeUsersList", function(){
+                       this._updateTableModel();               
+               }, this);
                this.setGuiMode("clear");
        },
        
@@ -175,14 +183,33 @@ qx.Class.define("org.argeo.security.ria.UsersApplet",
         * @param data {Element} The text xml description. 
         */
        load : function(){              
-               var data = [["root", "ROLE_ADMIN"], ["mbaudier", "ROLE_ADMIN,ROLE_USER"], ["cdujeu","ROLE_USER"], ["anonymous", ""]];
-               this.tableModel.setData(data);                  
                var commands = this.getCommands();
                this.toolBarPart.add(commands["new_user"].command.getToolbarButton());
                this.toolBarPart.add(commands["delete_user"].command.getToolbarButton());
                this.toolBarPart.add(commands["edit_user"].command.getToolbarButton());                 
                this.toolBar.setShow("icon");
-               
+
+               var request = org.argeo.security.ria.SecurityAPI.getListUsersService();
+               request.addListener("completed", function(response){
+                       var jSon = response.getContent();
+                       var usMap = {};
+                       for(var i=0;i<jSon.length;i++){
+                               var user = new org.argeo.security.ria.model.User();
+                               user.load(jSon[i], "json");
+                               usMap[user.getName()] = user;
+                       }
+                       this.setUsersList(usMap);                       
+               }, this);
+               request.send();
+       },
+       
+       _updateTableModel : function(){
+               var usList = this.getUsersList();
+               var data = [];
+               qx.lang.Object.getValues(usList).forEach(function(usObject){
+                       data.push([usObject.getName(), usObject.getRoles().join(",")]);
+               });
+               this.tableModel.setData(data);                                  
        },
        
        applySelection : function(selectionValues, target){
index da11c72472c7cbd97e3402591290dc7a0c7586a1..a495563e603cb1fd53ed67c6881148f9e22a811d 100644 (file)
@@ -1,10 +1,9 @@
 qx.Class.define("org.argeo.security.ria.components.CoworkerNatureImpl", {\r
        extend : org.argeo.security.ria.components.SimpleUserNatureImpl,\r
-       properties : {\r
-               natureType : {\r
-                       refine : true,\r
-                       init : "Coworker"\r
-               }\r
+       statics : {\r
+               NATURE_TYPE : "org.argeo.security.nature.CoworkerNature",\r
+               NATURE_LABEL : "Co-Worker",\r
+               NATURE_ICON : ""\r
        },\r
        \r
        construct : function(){\r
@@ -39,10 +38,6 @@ qx.Class.define("org.argeo.security.ria.components.CoworkerNatureImpl", {
                                this.add(this.fields[key], {row:j,column:1});\r
                                j++;\r
                        }                       \r
-               },\r
-               \r
-               getNatureLabel : function(){\r
-                       return "Co-Worker";\r
-               }\r
+               }               \r
        }\r
 });
\ No newline at end of file
index 038a26d1acb9f5a4df2cb388a035621e79165edf..5d5c97e4d8aee2b5029fabed726d029c23527c46 100644 (file)
@@ -1,11 +1,18 @@
 qx.Interface.define("org.argeo.security.ria.components.INaturePane", {\r
        extend  : org.argeo.security.ria.components.IUserDataPane,\r
+       statics : {\r
+               NATURE_TYPE : "",\r
+               NATURE_LABEL : "",\r
+               NATURE_ICON : ""\r
+       },\r
        properties : {\r
-               natureUuid : {},\r
-               natureType : {}\r
+               editMode : {\r
+                       init : true,\r
+                       apply : "_applyEditMode",                       \r
+                       event : "changeEditMode"\r
+               }\r
        },\r
        members : {\r
-               getNatureLabel : function(){return true},\r
                setData : function(dataMap, format){return true;}\r
        }\r
 });
\ No newline at end of file
diff --git a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/components/NaturesManager.js b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/components/NaturesManager.js
new file mode 100644 (file)
index 0000000..f15bb33
--- /dev/null
@@ -0,0 +1,39 @@
+qx.Class.define("org.argeo.security.ria.components.NaturesManager",{\r
+       extend : qx.core.Object,\r
+       properties : {\r
+               detectedNatures : {\r
+                       check : "Map"\r
+               }\r
+       },\r
+       construct : function(){\r
+               this.base(arguments);\r
+               this.detectNatures();\r
+       },\r
+       members : {\r
+               detectNatures : function(){                     \r
+                       var natures = {};\r
+                       for (var key in qx.Bootstrap.$$registry) {\r
+                               if (qx.Class.hasInterface(qx.Bootstrap.$$registry[key], org.argeo.security.ria.components.INaturePane)) {\r
+                                       // FILTER BY ROLE HERE!\r
+                                       var klass = qx.Bootstrap.$$registry[key];\r
+                                       natures[klass.NATURE_TYPE] = klass;\r
+                               }\r
+                       }\r
+                       this.setDetectedNatures(natures);\r
+               },\r
+               detectNaturesInData : function(userNaturesList){\r
+                       var detected = this.getDetectedNatures();\r
+                       var userDetected = [];\r
+                       for(var i = 0;i<userNaturesList.length;i++){\r
+                               var type = userNaturesList[i].type;\r
+                               if(detected[type]){\r
+                                       userDetected.push({\r
+                                               NATURE_CLASS : detected[type],\r
+                                               NATURE_DATA  : userNaturesList[i]\r
+                                       });\r
+                               }\r
+                       }\r
+                       return userDetected;\r
+               }\r
+       }\r
+});
\ No newline at end of file
index 4b5e4c84b3f1687f8e71c1f92a401c3214f26782..342cee246bf91cae6891673a037d89ee42e48674 100644 (file)
@@ -4,27 +4,32 @@ qx.Class.define("org.argeo.security.ria.components.SimpleUserNatureImpl", {
        events : {\r
                "modified" : "qx.event.type.Event"              \r
        },\r
+       statics : {\r
+               NATURE_TYPE : "org.argeo.security.nature.SimpleUserNature",\r
+               NATURE_LABEL : "Simple User",\r
+               NATURE_ICON : ""\r
+       },\r
        properties : {\r
                valid : {\r
                        init : false\r
                },\r
-               natureUuid : {\r
-                       init : ""\r
-               },\r
-               natureType : {\r
-                       init : "SimpleUser"\r
-               },\r
                dataMap : {\r
                        \r
-               }\r
+               },\r
+               editMode : {\r
+                       init : true,\r
+                       apply : "_applyEditMode",\r
+                       event : "changeEditMode"\r
+               }               \r
        },\r
        \r
        construct : function(){\r
                this.base(arguments);   \r
                this._createGui();\r
+               this.setEditMode(false);                \r
        },\r
                \r
-       members : {\r
+       members : {             \r
                \r
                _createGui : function(){\r
                        var grid = new qx.ui.layout.Grid(5,5);\r
@@ -52,17 +57,19 @@ qx.Class.define("org.argeo.security.ria.components.SimpleUserNatureImpl", {
                                this.fields[key].addListener("changeValue", function(e){this.fireEvent("modified");}, this);\r
                                this.add(this.fields[key], {row:j,column:1});\r
                                j++;\r
-                       }                       \r
+                       }       \r
+               },\r
+               \r
+               _applyEditMode : function(value){\r
+                       for(var key in this.fields){\r
+                               this.fields[key].setEnabled(value);\r
+                       }\r
                },\r
+               \r
                getContainer  : function(){\r
                        return this;\r
                },\r
-               getNatureLabel : function(){\r
-                       return "Simple User";\r
-               },\r
                setData    : function(dataMap, format){\r
-                       this.setNatureUuid(dataMap["uuid"]);\r
-                       this.setNatureType(dataMap["type"]);\r
                        for(var key in this.fields){\r
                                if(dataMap[key]){\r
                                        this.fields[key].setValue(dataMap[key]);\r
index ff61c7be5927a90a2cffcec2863eca29982dde6f..981476b3c5a5f2c674d7c4c1ced2a64e7f8baef7 100644 (file)
@@ -1,9 +1,6 @@
 qx.Class.define("org.argeo.security.ria.model.Nature", {\r
        extend : qx.core.Object,\r
        properties : {\r
-               uuid : {\r
-                       check : "String"\r
-               },\r
                type : {\r
                        check : "String"\r
                },\r
@@ -16,7 +13,7 @@ qx.Class.define("org.argeo.security.ria.model.Nature", {
        },\r
        members : {\r
                load : function(data, format){\r
-                       \r
+                       this.setData(data);\r
                }\r
        }       \r
 });
\ No newline at end of file
index acf55725d172c08b710bae547c6cf3e3b08c7d34..9355388631334b6f880b50d00f9c2921b683607b 100644 (file)
@@ -2,6 +2,7 @@ qx.Class.define("org.argeo.security.ria.model.User", {
        extend : qx.core.Object,\r
        properties : {\r
                name : {\r
+                       init : "",\r
                        check : "String"\r
                },\r
                roles : {\r
@@ -9,16 +10,28 @@ qx.Class.define("org.argeo.security.ria.model.User", {
                },\r
                natures :{\r
                        check : "Array"\r
+               },\r
+               rawData : {\r
+                       \r
                }\r
        },\r
        construct : function(){\r
                this.base(arguments);\r
+               this.setRoles([]);\r
+               this.setNatures([]);\r
        },\r
        members : {\r
                load : function(data, format){\r
                        this.setName(data.username);\r
                        this.setRoles(data.roles);\r
                        this.setNatures(data.userNatures);\r
+                       this.setRawData(data);\r
+               },\r
+               toJSON : function(){\r
+                       var rawData = this.getRawData();\r
+                       rawData.username = this.getName();\r
+                       rawData.roles = this.getRoles();\r
+                       rawData.userNatures = this.getNatures();\r
                }\r
        }\r
        \r
diff --git a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/resource/org.argeo.security.ria/dialog-apply.png b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/resource/org.argeo.security.ria/dialog-apply.png
new file mode 100644 (file)
index 0000000..a3ae536
Binary files /dev/null and b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/resource/org.argeo.security.ria/dialog-apply.png differ
diff --git a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/resource/org.argeo.security.ria/dialog-cancel.png b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/resource/org.argeo.security.ria/dialog-cancel.png
new file mode 100644 (file)
index 0000000..df093e9
Binary files /dev/null and b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/resource/org.argeo.security.ria/dialog-cancel.png differ
diff --git a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/resource/org.argeo.security.ria/document-properties-22.png b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/resource/org.argeo.security.ria/document-properties-22.png
new file mode 100644 (file)
index 0000000..4a94ed9
Binary files /dev/null and b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/resource/org.argeo.security.ria/document-properties-22.png differ
diff --git a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/resource/org.argeo.security.ria/identity.png b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/resource/org.argeo.security.ria/identity.png
new file mode 100644 (file)
index 0000000..69abedd
Binary files /dev/null and b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/resource/org.argeo.security.ria/identity.png differ
diff --git a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/resource/org.argeo.security.ria/preferences-users.png b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/resource/org.argeo.security.ria/preferences-users.png
new file mode 100644 (file)
index 0000000..53f3a28
Binary files /dev/null and b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/resource/org.argeo.security.ria/preferences-users.png differ