viewsManager.registerViewPane(rolesPane);\r
var usersPane = new org.argeo.ria.components.ViewPane("users", "Users");\r
viewsManager.registerViewPane(usersPane);\r
- var editorPane = new org.argeo.ria.components.ViewPane("editor", "Editor");\r
+ var editorPane = new org.argeo.ria.components.TabbedViewPane("editor", "Editor");\r
viewsManager.registerViewPane(editorPane);\r
\r
this._firstSplit.add(rolesPane, 1);\r
\r
initViews : function(viewsManager) {\r
\r
+ var rolesView = viewsManager.initIViewClass(org.argeo.security.ria.RolesApplet, "roles");\r
+ rolesView.load();\r
+ \r
var usersView = viewsManager.initIViewClass(org.argeo.security.ria.UsersApplet, "users");\r
usersView.load();\r
\r
- var rolesView = viewsManager.initIViewClass(org.argeo.security.ria.RolesApplet, "roles");\r
- rolesView.load();\r
},\r
\r
remove : function(viewsManager) {\r
* 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:""}
},
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<ranges.length;i++){
+ for(var j=ranges[i].minIndex;j<=ranges[i].maxIndex;j++){
+ values.push(this.tableModel.getData()[j][0]);
+ if(viewSelection){
+ viewSelection.addNode(this.tableModel.getData()[j][0]);
+ }
+ }
+ }
+ if(viewSelection){
+ viewSelection.setBatchMode(false);
+ }
+ return values;
},
/**
--- /dev/null
+/**
+ * A simple Hello World applet for documentation purpose.
+ * The only associated command is the "Close" command.
+ */
+/* *************************************************
+#asset(resource/org.argeo.ria.sample/window-close.png)
+****************************************************/
+qx.Class.define("org.argeo.security.ria.UserEditorApplet",
+{
+ extend : qx.ui.container.Composite,
+ implement : [org.argeo.ria.components.IView],
+
+ construct : function(){
+ this.base(arguments);
+ this.setLayout(new qx.ui.layout.VBox());
+ //this.setDecorator("tabview-pane");
+ },
+
+ properties :
+ {
+ /**
+ * The viewPane inside which this applet is added.
+ */
+ view : {
+ init : null
+ },
+ /**
+ * Commands definition, see {@link org.argeo.ria.event.CommandsManager#definitions}
+ */
+ commands : {
+ init : {
+ "save_user" : {
+ label : "Save",
+ icon : "ria/window-close.png",
+ shortcut : "Control+s",
+ enabled : true,
+ menu : "Users",
+ toolbar : "user",
+ callback : function(e){
+
+ },
+ 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
+ },
+ "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
*/
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<crtUsers.length;i++){
+ alert("Delete " + crtUsers[i]);
+ }
+ },
+ selectionChange : function(viewName, data){
+ if(viewName != "users") return;
+ this.setEnabled(!(data == null || !data.length));
+ },
+ command : null
+ }
}
},
+
+ guiMode : {
+ init : "filter",
+ apply : "_applyGuiMode"
+ },
+
viewSelection : {
nullable:false,
check:"org.argeo.ria.components.ViewSelection"
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);
+
+ this.setGuiMode("chooser");
+ },
+
+ _applyGuiMode : function(newMode, oldMode){
+ this.table.getSelectionModel().clearSelection();
+ this.resetHiddenRows();
+ if(newMode == "filter"){
+ this.table.getSelectionModel().setSelectionMode(qx.ui.table.selection.Model.SINGLE_INTERVAL_SELECTION);
+ }else if(newMode == "chooser"){
+ this.table.getSelectionModel().setSelectionMode(qx.ui.table.selection.Model.MULTIPLE_INTERVAL_SELECTION_TOGGLE);
+ }else if(newMode == "clear"){
+ this.table.getSelectionModel().setSelectionMode(qx.ui.table.selection.Model.SINGLE_INTERVAL_SELECTION);
+ }
+ },
+
+ _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<ranges.length;i++){
+ for(var j=ranges[i].minIndex;j<=ranges[i].maxIndex;j++){
+ values.push(this.tableModel.getData()[j][0]);
+ if(viewSelection){
+ viewSelection.addNode(this.tableModel.getData()[j][0]);
+ }
+ }
+ }
+ if(viewSelection){
+ viewSelection.setBatchMode(false);
+ }
+ return values;
},
/**
* @param data {Element} The text xml description.
*/
load : function(){
- var data = [["mbaudier", "ROLE_ADMIN,ROLE_USER"], ["cdujeu","ROLE_USER"]];
- this.tableModel.setData(data);
- this.applyFilter("ROLE_ADMIN", "roles", true);
+ var data = [["root", "ROLE_ADMIN"], ["mbaudier", "ROLE_ADMIN,ROLE_USER"], ["cdujeu","ROLE_USER"], ["anonymous", ""]];
+ this.tableModel.setData(data);
},
- applyFilter : function(filterValue, target, ignoreCase){
- this.tableModel.addRegex("^((?!"+filterValue+").)*$", target, ignoreCase);
+ applySelection : function(selectionValues, target){
+ var selectionModel = this.table.getSelectionModel();
+ selectionModel.clearSelection();
+ if(!selectionValues){
+ return;
+ }
+ selectionModel.setBatchMode(true);
+ var data = this.tableModel.getData();
+ for(var i=0;i<this.tableModel.getRowCount();i++){
+ var value = this.tableModel.getRowDataAsMap(i)[target];
+ if(qx.lang.Array.contains(selectionValues, value)){
+ selectionModel.addSelectionInterval(i, i);
+ }
+ }
+ selectionModel.setBatchMode(false);
+ },
+
+ applyFilter : function(filterValues, target, ignoreCase){
+ this.table.clearSelection();
+ this.resetHiddenRows();
+ for(var i=0;i<filterValues.length;i++){
+ this.tableModel.addRegex("^((?!"+filterValues[i]+").)*$", target, ignoreCase);
+ }
this.tableModel.applyFilters();
},
--- /dev/null
+qx.Interface.define("org.argeo.security.ria.components.ICredentialPane", {\r
+ extend : org.argeo.security.ria.components.IUserDataPane,\r
+ members : {\r
+ setEditMode : function(editMode){return true;}\r
+ }\r
+});
\ No newline at end of file
--- /dev/null
+qx.Interface.define("org.argeo.security.ria.components.INaturePane", {\r
+ extend : org.argeo.security.ria.components.IUserDataPane,\r
+ members : {\r
+ getNatureLabel : function(){return true},\r
+ setData : function(dataMap, format){return true;}\r
+ }\r
+});
\ No newline at end of file
--- /dev/null
+qx.Interface.define("org.argeo.security.ria.components.IUserDataPane", {\r
+ members : {\r
+ getContainer : function(){return true;},\r
+ getData : function(format){return true;},\r
+ validate : function(){return true;}\r
+ },\r
+ events : {\r
+ "modified" : "qx.event.type.Event"\r
+ \r
+ }\r
+});
\ No newline at end of file
--- /dev/null
+qx.Class.define("org.argeo.security.ria.components.PasswordCredentialImpl", {\r
+ extend : qx.ui.container.Composite,\r
+ implement : [org.argeo.security.ria.components.ICredentialPane],\r
+ events : {\r
+ "modified" : "qx.event.type.Event" \r
+ },\r
+ \r
+ construct : function(){\r
+ this.base(arguments);\r
+ this.setLayout(new qx.ui.layout.HBox(5, "center"));\r
+ this.add(new qx.ui.basic.Label("Password"), {flex:1});\r
+ this.add(new qx.ui.form.TextField(), {flex:2});\r
+ this.add(new qx.ui.basic.Label("Confirm Password"), {flex:1});\r
+ this.add(new qx.ui.form.TextField(), {flex:2});\r
+ },\r
+ \r
+ members : {\r
+ getContainer : function(){\r
+ return this;\r
+ },\r
+ getData : function(format){return true;},\r
+ validate : function(){return true;},\r
+ setEditMode : function(editMode){return true;} \r
+ }\r
+});
\ No newline at end of file
--- /dev/null
+qx.Class.define("org.argeo.security.ria.components.SimpleUserNatureImpl", {\r
+ extend : qx.ui.container.Composite,\r
+ implement : [org.argeo.security.ria.components.INaturePane],\r
+ events : {\r
+ "modified" : "qx.event.type.Event" \r
+ },\r
+ \r
+ construct : function(){\r
+ this.base(arguments);\r
+ this.setLayout(new qx.ui.layout.Grid());\r
+ },\r
+ \r
+ members : {\r
+ getContainer : function(){\r
+ return this;\r
+ },\r
+ getNatureLabel : function(){\r
+ return "Basic User";\r
+ },\r
+ setData : function(dataMap, format){return true;},\r
+ getData : function(format){return true;},\r
+ validate : function(){return true;}\r
+ }\r
+});
\ No newline at end of file