X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=security%2Fruntime%2Forg.argeo.security.ria%2Fsrc%2Fargeo-ria-lib%2Fsecurity%2Fclass%2Forg%2Fargeo%2Fsecurity%2Fria%2FUserEditorApplet.js;h=8e0eab7e1326d716a97445b850f408295c240a5f;hb=8cf334827522cbb7dec2151aec57f19634d1b9a2;hp=7f18caaed2e49245245013ef2315273c636feb2e;hpb=81579a12a1b3fa8a21e1ad7944e5dccaa8beeadf;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 7f18caaed..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 @@ -3,19 +3,17 @@ * The only associated command is the "Close" command. */ /* ************************************************* -#asset(resource/org.argeo.ria.sample/window-close.png) +#asset(resource/org.argeo.security.ria/*) ****************************************************/ 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} */ @@ -31,33 +29,91 @@ qx.Class.define("org.argeo.security.ria.UserEditorApplet", init : { "save_user" : { label : "Save", - icon : "ria/window-close.png", + icon : "org.argeo.security.ria/document-save.png", shortcut : "Control+s", enabled : true, 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 }, "close" : { label : "Close", - icon : "org.argeo.ria.sample/window-close.png", + icon : "org.argeo.security.ria/window-close.png", shortcut : "Control+w", enabled : true, menu : "Users", toolbar : "user", callback : function(e){ // Call service to delete - this.getView().closeCurrent(); + var iApplet = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById("editor").getContent(); + if(!iApplet.getModified() && !iApplet.getNaturesModified()){ + this.getView().closeCurrent(); + return; + } + var modal = new org.argeo.ria.components.Modal("Warning"); + modal.addConfirm("There are unsaved changes!\n Are you sure you want to close?"); + modal.addListener("ok", function(){ + this.getView().closeCurrent(); + }, this); + modal.attachAndShow(); }, command : null } @@ -67,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 : @@ -84,81 +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}); + this.initGUI(data.ROLES_LIST); - // FIELDS - this.usernameField = new qx.ui.form.TextField(); - this.usernameField.addListener("changeValue", function(){ - this.setModified(true); - this.getViewSelection().triggerEvent(); + this.addListener("savedUser", function(e){ + if(this.getCurrentUser()){ + this.setInstanceLabel("User " + this.getCurrentUser().getName()); + this.setInstanceId(this.getCurrentUser().getName()); + } }, this); - 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.naturesGB.add(this.naturesTab, {edge:"center"}); - - }, - - _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"]); + 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; },