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=772cf2e7fc18deb8ec57ce34581573a1c0d38225;hpb=83061f79058ddddf7a888a4580c913d5caa18c91;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 772cf2e7f..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,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.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 +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,17 +123,13 @@ 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"}, - loaded : { - init : false + instanceLabel : { + init:"Editor", + event : "changeInstanceLabel" } }, @@ -97,126 +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())); - - // 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(); - 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.initGUI(data.ROLES_LIST); - 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.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); - this.passPane.addListener("modified", 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.simpleNature.addListener("modified", function(){ - this.setModified(true); - }, this); - this.coWorkerNature.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){ + 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]}); } - if(userData){ - this.usernameField.setValue(userData); + 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.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}); - 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); + + this.setLoaded(true); }, + _applyDetailsModified : function(value){ + if(value) this.getViewSelection().triggerEvent(); + }, + + _applyNaturesModified : function(value){ + if(value) this.getViewSelection().triggerEvent(); + }, + addScroll : function(){ return false; },