X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=security%2Fruntime%2Forg.argeo.security.ria%2Fsrc%2Fargeo-ria-lib%2Fsecurity%2Fclass%2Forg%2Fargeo%2Fsecurity%2Fria%2FUserEditorApplet.js;h=8e0eab7e1326d716a97445b850f408295c240a5f;hb=8cf334827522cbb7dec2151aec57f19634d1b9a2;hp=395d170c0a76ce08b810814a72eaf9aa4bf5c20e;hpb=829163c2a8aa042407a6fd2ee45d10cea69e933f;p=lgpl%2Fargeo-commons.git diff --git a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/UserEditorApplet.js b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/UserEditorApplet.js index 395d170c0..8e0eab7e1 100644 --- a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/UserEditorApplet.js +++ b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/UserEditorApplet.js @@ -7,15 +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()); - //this.setDecorator("tabview-pane"); }, - + properties : { /** @@ -23,7 +21,7 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet", */ view : { init : null - }, + }, /** * Commands definition, see {@link org.argeo.ria.event.CommandsManager#definitions} */ @@ -37,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.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 }, @@ -58,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; } @@ -77,14 +123,14 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet", nullable:false, check:"org.argeo.ria.components.ViewSelection" }, - modified : { - init : false - }, - rolesList : { - + instanceId : { + init:"", + event : "changeInstanceId" }, - instanceId : {init:""}, - instanceLabel : {init:"Editor"} + instanceLabel : { + init:"Editor", + event : "changeInstanceLabel" + } }, members : @@ -94,94 +140,83 @@ 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())); - - // 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.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.initGUI(data.ROLES_LIST); - 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(); - - 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); + }, /** * 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); + load : function(userName){ + if(this.getLoaded()){ + return; + } + // MUST BE DONE AFTER COMMANDS ARE INITIALIZED! + var commands = this.getCommands(); + 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]}); } - this.setRolesList(["ROLE_ADMIN", "ROLE_USER"]); - this._attachListeners(); + 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(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; },