****************************************************/
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 :
{
/**
*/
view : {
init : null
- },
+ },
/**
* Commands definition, see {@link org.argeo.ria.event.CommandsManager#definitions}
*/
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
},
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;
}
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 :
* @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});
-
- // 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.initGUI(data.ROLES_LIST);
- 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"});
-
- },
-
- _attachListeners : function(){
- this.usernameField.addListener("changeValue", function(){
- this.setModified(true);
- }, this);
- this.rolesField.addListener("changeValue", 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.passPane.addListener("modified", function(){
- this.setModified(true);
- }, this);
- this.simpleNature.addListener("modified", function(){
- this.setModified(true);
- }, this);
- },
-
- _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"]);
- this._attachListeners();
+ 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;
},