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%2FRolesApplet.js;h=676aaa3d9bbf46b55020b2dfffe0c3cae0b0eb40;hb=f7c73e12f9534b0b796686e207dd4b43193977fa;hp=f2f488d31a3220a38d4a93f35a773b2a2e992522;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/RolesApplet.js b/security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/RolesApplet.js index f2f488d31..676aaa3d9 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 @@ -34,7 +34,7 @@ qx.Class.define("org.argeo.security.ria.RolesApplet", shortcut : "Control+n", enabled : true, menu : "Roles", - toolbar : "role", + toolbar : null, callback : function(e){ // Prompt for new name }, @@ -46,7 +46,7 @@ qx.Class.define("org.argeo.security.ria.RolesApplet", shortcut : "Control+s", enabled : true, menu : "Roles", - toolbar : "role", + toolbar : null, callback : function(e){ // Call service to delete var crtUsers = this.getViewSelection().getNodes(); @@ -55,7 +55,7 @@ qx.Class.define("org.argeo.security.ria.RolesApplet", } }, selectionChange : function(viewName, data){ - if(viewName != "role") return; + if(viewName != "roles") return; this.setEnabled(!(data == null || !data.length)); }, command : null @@ -66,7 +66,7 @@ qx.Class.define("org.argeo.security.ria.RolesApplet", shortcut : "Control+r", enabled : true, menu : "Roles", - toolbar : "role", + toolbar : null, callback : function(e){ // Call service to delete this.setGuiMode("edit"); @@ -103,7 +103,13 @@ qx.Class.define("org.argeo.security.ria.RolesApplet", */ init : function(viewPane){ this.setView(viewPane); - this.setViewSelection(new org.argeo.ria.components.ViewSelection(viewPane.getViewId())); + this.setViewSelection(new org.argeo.ria.components.ViewSelection(viewPane.getViewId())); + + this.toolBar = new qx.ui.toolbar.ToolBar(); + this.toolBarPart = new qx.ui.toolbar.Part(); + this.toolBar.add(this.toolBarPart); + viewPane.add(this.toolBar); + this.tableModel = new qx.ui.table.model.Simple(); this.tableModel.setColumns(["Role Name"]); this.table = new qx.ui.table.Table(this.tableModel, { @@ -120,21 +126,14 @@ 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"]}; - - 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.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({ 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){ @@ -148,7 +147,6 @@ qx.Class.define("org.argeo.security.ria.RolesApplet", toolTip :new qx.ui.tooltip.ToolTip("Save changes"), visibility : "excluded" }); - buttonPane.add(this.saveButton); this.cancelButton = new qx.ui.form.Button("Cancel", "org.argeo.security.ria/window-close.png"); this.cancelButton.set({ @@ -157,11 +155,16 @@ qx.Class.define("org.argeo.security.ria.RolesApplet", toolTip :new qx.ui.tooltip.ToolTip("Cancel changes"), visibility : "excluded" }); - buttonPane.add(this.cancelButton); 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()){ @@ -227,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); } }, @@ -256,10 +263,11 @@ qx.Class.define("org.argeo.security.ria.RolesApplet", return; } var uniqueValue = this._selectionToValues(selectionModel)[0]; - var initSelection = this.rolesUsersStub[uniqueValue]; + //var initSelection = this.rolesUsersStub[uniqueValue]; + this.usersAppletReference.applySelection(uniqueValue, "roles"); + var initSelection = this.usersAppletReference.getViewSelection().getNodes(); this.setChooserOriginalSelection(initSelection); this.setChooserSelectionModified(false); - this.usersAppletReference.applySelection(initSelection, "username"); this.saveButton.setEnabled(false); }, @@ -285,13 +293,43 @@ 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. */ - load : function(){ + load : function(){ + // WARNING, THE USERS APPLET MUST BE LOADED! + var vManager = org.argeo.ria.components.ViewsManager.getInstance(); + this.usersAppletReference = vManager.getViewPaneById("users").getContent(); + + this.usersAppletReference.addListener("changeRolesList", function(event){ + var rolesList = event.getData(); + var data = []; + rolesList.forEach(function(el){data.push([el]);}); + this.tableModel.setData(data); + }, this); + /* var data = [["ROLE_ADMIN"],["ROLE_USER"]]; this.tableModel.setData(data); + */ + var commands = this.getCommands(); + this.toolBarPart.add(commands["new_role"].command.getToolbarButton()); + this.toolBarPart.add(commands["delete_role"].command.getToolbarButton()); + this.toolBarPart.add(commands["edit_role"].command.getToolbarButton()); + this.toolBar.addSpacer(); + this.toolBar.add(this.toggleButton); + this.toolBar.add(this.saveButton); + this.toolBar.add(this.cancelButton); + this.toolBar.setShow("icon"); + }, addScroll : function(){