From: Charles du Jeu Date: Wed, 16 Sep 2009 18:35:23 +0000 (+0000) Subject: New components, enhance applets X-Git-Tag: argeo-commons-2.1.30~1805 X-Git-Url: https://git.argeo.org/?p=lgpl%2Fargeo-commons.git;a=commitdiff_plain;h=81579a12a1b3fa8a21e1ad7944e5dccaa8beeadf New components, enhance applets git-svn-id: https://svn.argeo.org/commons/trunk@2939 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/Perspective.js b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/Perspective.js index 6154dca55..c3f167496 100644 --- a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/Perspective.js +++ b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/Perspective.js @@ -34,7 +34,7 @@ qx.Class.define("org.argeo.security.ria.Perspective", { viewsManager.registerViewPane(rolesPane); var usersPane = new org.argeo.ria.components.ViewPane("users", "Users"); viewsManager.registerViewPane(usersPane); - var editorPane = new org.argeo.ria.components.ViewPane("editor", "Editor"); + var editorPane = new org.argeo.ria.components.TabbedViewPane("editor", "Editor"); viewsManager.registerViewPane(editorPane); this._firstSplit.add(rolesPane, 1); @@ -48,11 +48,12 @@ qx.Class.define("org.argeo.security.ria.Perspective", { initViews : function(viewsManager) { + var rolesView = viewsManager.initIViewClass(org.argeo.security.ria.RolesApplet, "roles"); + rolesView.load(); + var usersView = viewsManager.initIViewClass(org.argeo.security.ria.UsersApplet, "users"); usersView.load(); - var rolesView = viewsManager.initIViewClass(org.argeo.security.ria.RolesApplet, "roles"); - rolesView.load(); }, remove : function(viewsManager) { diff --git a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/RolesApplet.js b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/RolesApplet.js index 3d6ad869f..3803968a9 100644 --- a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/RolesApplet.js +++ b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/RolesApplet.js @@ -27,12 +27,38 @@ qx.Class.define("org.argeo.security.ria.RolesApplet", * Commands definition, see {@link org.argeo.ria.event.CommandsManager#definitions} */ commands : { - init : {} + init : { + "edit_role" : { + label : "Edit Role", + icon : "ria/window-close.png", + shortcut : "Control+r", + enabled : true, + menu : "Roles", + toolbar : "role", + callback : function(e){ + // Call service to delete + this.setGuiMode("edit"); + }, + selectionChange : function(viewName, data){ + if(viewName != "roles") return; + this.setEnabled(!(data == null || !data.length || data.length > 1)); + }, + command : null + } + } }, viewSelection : { nullable:false, check:"org.argeo.ria.components.ViewSelection" }, + guiMode : { + apply : "_applyGuiMode" + }, + chooserOriginalSelection : {}, + chooserSelectionModified : { + init:false, + event : "chooserSelectionWasModified" + }, instanceId : {init:""}, instanceLabel : {init:""} }, @@ -53,13 +79,167 @@ qx.Class.define("org.argeo.security.ria.RolesApplet", return new qx.ui.table.columnmodel.Resize(obj) } }); - this.table.setStatusBarVisible(false); + this.table.setStatusBarVisible(false); + this.table.setShowCellFocusIndicator(false); + this.table.setColumnVisibilityButtonVisible(false); + this.table.highlightFocusedRow(false); viewPane.add(this.table, {height:"100%"}); + this.table.getSelectionModel().addListener("changeSelection", function(){ + this._selectionToValues(this.table.getSelectionModel(), this.getViewSelection()); + }, this); + - var selectionModel = this.table.getSelectionModel(); - selectionModel.addListener("changeSelection", function(){ - var ranges = selectionModel.getSelectedRanges(); + this.rolesUsersStub = {"ROLE_ADMIN":["root","mbaudier"],"ROLE_USER":["mbaudier","cdujeu"]}; + + var buttonPane = new qx.ui.container.Composite(new qx.ui.layout.HBox(2, "right")); + this.getView().header.setPadding(0); + if(this.getView().headerLabel) this.getView().headerLabel.setMargin(8); + this.getView().header.add(buttonPane, {edge:"east"}); + + this.toggleButton = new qx.ui.form.ToggleButton("Filter", "ria/go-right.png"); + this.toggleButton.set({ + show:"icon", + margin:2, + toolTip :new qx.ui.tooltip.ToolTip("Apply automatic filtering on Users list") + }); + buttonPane.add(this.toggleButton); + + // TOGGLE THE GUI MODES + this.toggleButton.addListener("changeChecked", function(event){ + this.setGuiMode(event.getData()?"filter":"clear"); + }, this); + + this.saveButton = new qx.ui.form.Button("Save"); + this.saveButton.set({ + show:"label", + margin:2, + toolTip :new qx.ui.tooltip.ToolTip("Save changes"), + visibility : "excluded" }); + buttonPane.add(this.saveButton); + + this.cancelButton = new qx.ui.form.Button("Cancel"); + this.cancelButton.set({ + show:"label", + margin:2, + toolTip :new qx.ui.tooltip.ToolTip("Cancel changes"), + visibility : "excluded" + }); + buttonPane.add(this.cancelButton); + + var listener = function(){ + this.setGuiMode(this.initialState); + }; + this.saveButton.addListener("execute", listener, this); + this.cancelButton.addListener("execute", listener, this); + + this.table.addListener("cellDblclick", function(cellEvent){ + this.setGuiMode("edit"); + }, this); + + this.setGuiMode("clear"); + }, + + _applyGuiMode : function(guiMode, previousMode){ + var selectionModel = this.table.getSelectionModel(); + if(!this.usersAppletReference){ + var vManager = org.argeo.ria.components.ViewsManager.getInstance(); + this.usersAppletReference = vManager.getViewPaneById("users").getContent(); + } + + this.saveButton.setVisibility((guiMode=="edit"?"visible":"excluded")); + this.cancelButton.setVisibility((guiMode=="edit"?"visible":"excluded")); + this.table.setEnabled((guiMode=="edit"?false:true)); + this.toggleButton.setVisibility((guiMode=="edit"?"excluded":"visible")); + + if(guiMode == "filter"){ + if(this.usersAppletReference){ + this.usersAppletReference.setGuiMode(("filter")); + var viewSel = this.usersAppletReference.getViewSelection(); + viewSel.removeListener("changeSelection", this.monitorChooserSelectionChanges, this); + } + selectionModel.addListener("changeSelection", this.selectionToFilter, this); + selectionModel.setSelectionMode(qx.ui.table.selection.Model.MULTIPLE_INTERVAL_SELECTION_TOGGLE); + this.selectionToFilter(); + }else if(guiMode == "edit"){ + if(!this.usersAppletReference) return; + this.initialState = previousMode; + if(previousMode == "filter"){ + this.usersAppletReference.setGuiMode(("clear")); + selectionModel.removeListener("changeSelection", this.selectionToFilter, this); + } + this.usersAppletReference.setGuiMode(("chooser")); + this.selectionToChooser(); // Warning, to be called before calling listener! + var viewSel = this.usersAppletReference.getViewSelection(); + viewSel.addListener("changeSelection", this.monitorChooserSelectionChanges, this); + }else if(guiMode == "clear"){ + if(this.usersAppletReference){ + this.usersAppletReference.setGuiMode(("clear")); + var viewSel = this.usersAppletReference.getViewSelection(); + viewSel.removeListener("changeSelection", this.monitorChooserSelectionChanges, this); + } + this.table.setEnabled(true); + selectionModel.removeListener("changeSelection", this.selectionToFilter, this); + selectionModel.setSelectionMode(qx.ui.table.selection.Model.SINGLE_SELECTION); + } + }, + + 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.saveButton.setEnabled(true); + } + }, + + selectionToFilter : function(){ + if(!this.usersAppletReference) return; + var selectionModel = this.table.getSelectionModel(); + if(!selectionModel.getSelectedCount()){ + this.usersAppletReference.resetHiddenRows(); + return; + } + this.usersAppletReference.applyFilter(this._selectionToValues(selectionModel), "roles", true); + }, + + selectionToChooser : function(){ + if(!this.usersAppletReference) return; + var selectionModel = this.table.getSelectionModel(); + if(!selectionModel.getSelectedCount()){ + this.usersAppletReference.resetHiddenRows(); + return; + } + var uniqueValue = this._selectionToValues(selectionModel)[0]; + var initSelection = this.rolesUsersStub[uniqueValue]; + this.setChooserOriginalSelection(initSelection); + this.setChooserSelectionModified(false); + this.usersAppletReference.applySelection(initSelection, "username"); + this.saveButton.setEnabled(false); + }, + + _selectionToValues : function(selectionModel, viewSelection){ + if(viewSelection){ + viewSelection.setBatchMode(true); + viewSelection.clear(); + } + if(!selectionModel.getSelectedCount()) return []; + var ranges = selectionModel.getSelectedRanges(); + var values = []; + for(var i=0;i 1)); + }, + command : null + }, + "close" : { + label : "Close", + icon : "org.argeo.ria.sample/window-close.png", + shortcut : "Control+w", + enabled : true, + menu : "Users", + toolbar : "user", + callback : function(e){ + // Call service to delete + this.getView().closeCurrent(); + }, + command : null + } + } + }, + viewSelection : { + nullable:false, + check:"org.argeo.ria.components.ViewSelection" + }, + modified : { + init : false + }, + rolesList : { + + }, + instanceId : {init:""}, + instanceLabel : {init:"Editor"} + }, + + members : + { + /** + * Called at applet creation. Just registers viewPane. + * @param viewPane {org.argeo.ria.components.ViewPane} The viewPane. + */ + init : function(viewPane, data){ + if(!data){ + var now = new Date(); + this.setInstanceId(now.getTime()); + this.setInstanceLabel("New User"); + }else{ + this.setInstanceId(data); + this.setInstanceLabel("User " + data); + } + 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.usernameField.addListener("changeValue", function(){ + this.setModified(true); + this.getViewSelection().triggerEvent(); + }, 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); + } + this.setRolesList(["ROLE_ADMIN", "ROLE_USER"]); + }, + + addScroll : function(){ + return false; + }, + + close : function(){ + return false; + } + + } +}); \ 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/UsersApplet.js b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/UsersApplet.js index 72074cd15..4522746ac 100644 --- a/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/UsersApplet.js +++ b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/UsersApplet.js @@ -28,21 +28,69 @@ qx.Class.define("org.argeo.security.ria.UsersApplet", */ commands : { init : { - "close" : { - label : "Close", + "new_user" : { + label : "Create User", icon : "ria/window-close.png", - shortcut : "Control+w", + shortcut : "Control+n", enabled : true, - menu : "Applet", - toolbar : "result", + menu : "Users", + toolbar : "user", callback : function(e){ // Call service to delete - this.getView().empty(); + var classObj = org.argeo.security.ria.UserEditorApplet; + var iView = org.argeo.ria.components.ViewsManager.getInstance().initIViewClass(classObj, "editor"); + iView.load(); }, command : null - } + }, + "edit_user" : { + label : "Edit User", + icon : "ria/window-close.png", + shortcut : "Control+u", + enabled : true, + menu : "Users", + toolbar : "user", + callback : function(e){ + // Call service to delete + var crtUser = this.getViewSelection().getNodes()[0]; + var classObj = org.argeo.security.ria.UserEditorApplet; + var iView = org.argeo.ria.components.ViewsManager.getInstance().initIViewClass(classObj, "editor", crtUser); + iView.load(crtUser); + }, + selectionChange : function(viewName, data){ + if(viewName != "users") return; + this.setEnabled(!(data == null || !data.length || data.length > 1)); + }, + command : null + }, + "delete_user" : { + label : "Delete User", + icon : "ria/window-close.png", + shortcut : "Control+s", + enabled : true, + menu : "Users", + toolbar : "user", + callback : function(e){ + // Call service to delete + var crtUsers = this.getViewSelection().getNodes(); + for(var i=0;i