From a31a99db17f339a032aa9c489bae88636dd53431 Mon Sep 17 00:00:00 2001 From: Charles du Jeu Date: Tue, 9 Dec 2008 11:43:11 +0000 Subject: [PATCH] Handle "toggle" command, clean modal layout, handle separators in submenus. git-svn-id: https://svn.argeo.org/slc/trunk@1977 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../source/class/org/argeo/ria/Application.js | 8 +-- .../class/org/argeo/ria/components/Modal.js | 18 ++++- .../class/org/argeo/ria/event/Command.js | 66 ++++++++++++++----- .../org/argeo/ria/event/CommandsManager.js | 6 ++ 4 files changed, 73 insertions(+), 25 deletions(-) diff --git a/org.argeo.slc.webapp/src/main/webapp/source/class/org/argeo/ria/Application.js b/org.argeo.slc.webapp/src/main/webapp/source/class/org/argeo/ria/Application.js index 5544aa9ae..ce299c444 100644 --- a/org.argeo.slc.webapp/src/main/webapp/source/class/org/argeo/ria/Application.js +++ b/org.argeo.slc.webapp/src/main/webapp/source/class/org/argeo/ria/Application.js @@ -93,13 +93,7 @@ qx.Class.define("org.argeo.ria.Application", } var perspective = new perspectiveClass; perspective.initViewPanes(viewsManager); - perspective.initViews(viewsManager); - - // Test - org.argeo.ria.remote.RequestManager.getInstance().addListener("reload", function(e){ - qx.log.Logger.info("Received reload event for data type : "+ e.getDataType()); - }); - + perspective.initViews(viewsManager); } } diff --git a/org.argeo.slc.webapp/src/main/webapp/source/class/org/argeo/ria/components/Modal.js b/org.argeo.slc.webapp/src/main/webapp/source/class/org/argeo/ria/components/Modal.js index 810431d04..b69c1580f 100644 --- a/org.argeo.slc.webapp/src/main/webapp/source/class/org/argeo/ria/components/Modal.js +++ b/org.argeo.slc.webapp/src/main/webapp/source/class/org/argeo/ria/components/Modal.js @@ -23,7 +23,6 @@ qx.Class.define("org.argeo.ria.components.Modal", }); this.setLayout(new qx.ui.layout.Dock()); this.setModal(true); - this.addCloseButton(); this.center(); if(text){ this.addLabel(text); @@ -37,6 +36,7 @@ qx.Class.define("org.argeo.ria.components.Modal", */ addLabel:function(text){ this.add(new qx.ui.basic.Label(text), {edge:'center', width:'100%'}); + this.addCloseButton(); }, /** * Display a component (panel) in the center of the popup @@ -44,6 +44,7 @@ qx.Class.define("org.argeo.ria.components.Modal", */ addContent: function(panel){ this.add(panel, {edge:'center', width:'100%'}); + this.addCloseButton(); }, /** * Automatically attach to the application root, then show. @@ -57,15 +58,26 @@ qx.Class.define("org.argeo.ria.components.Modal", this.closeButton.addListener("execute", this._closeAndDestroy, this); this.add(this.closeButton, {edge:'south'}); }, + addOkCancel : function(){ + var buttonPane = new qx.ui.container.Composite(new qx.ui.layout.HBox(5, 'right')); + buttonPane.setAlignX("center"); + this.add(buttonPane, {edge:"south"}); + this.okButton = new qx.ui.form.Button("Ok"); + this.cancelButton = new qx.ui.form.Button("Cancel"); + this.cancelButton.addListener("execute", this._closeAndDestroy, this); + buttonPane.add(this.cancelButton); + buttonPane.add(this.okButton); + }, makePromptForm:function(questionString, validationCallback, callbackContext){ this.add(new qx.ui.basic.Label(questionString), {edge:'north'}); var textField = new qx.ui.form.TextField(); + textField.setMarginTop(20); this.add(textField, {edge:'center'}); - this.closeButton.removeListener("execute", this._closeAndDestroy, this); + this.addOkCancel(); if(callbackContext){ validationCallback = qx.lang.Function.bind(validationCallback, callbackContext); } - this.closeButton.addListener("execute", function(e){ + this.okButton.addListener("execute", function(e){ var valid = validationCallback(textField.getValue()); if(valid) this._closeAndDestroy(); }, this); diff --git a/org.argeo.slc.webapp/src/main/webapp/source/class/org/argeo/ria/event/Command.js b/org.argeo.slc.webapp/src/main/webapp/source/class/org/argeo/ria/event/Command.js index 83641c416..2579d2c4d 100644 --- a/org.argeo.slc.webapp/src/main/webapp/source/class/org/argeo/ria/event/Command.js +++ b/org.argeo.slc.webapp/src/main/webapp/source/class/org/argeo/ria/event/Command.js @@ -21,6 +21,10 @@ * Icon of the command */ icon : {init:""}, + /** + * Weather this command is a true/false state + */ + toggle : {init:false}, /** * Sub menu if needed */ @@ -59,18 +63,23 @@ * @return {qx.ui.menu.Button} */ getMenuButton : function(){ - var button = new qx.ui.menu.Button( - this.getLabel(), - this.getIcon(), - this, - this.getMenuClone() - ); - this.addTooltip(button); - if(this.getMenu()){ - this.addListener("changeMenu", function(event){ - button.setMenu(this.getMenuClone()); - }, this); + if(this.getToggle()){ + button = new qx.ui.menu.CheckBox(this.getLabel()); + this._registerToggleButtonListeners(button); + }else{ + var button = new qx.ui.menu.Button( + this.getLabel(), + this.getIcon(), + this, + this.getMenuClone() + ); + if(this.getMenu()){ + this.addListener("changeMenu", function(event){ + button.setMenu(this.getMenuClone()); + }, this); + } } + this.addTooltip(button); return button; }, @@ -93,6 +102,9 @@ this.setEnabled(e.getData()); }, button); button.setEnabled(this.getEnabled()); + }else if(this.getToggle()){ + button = new qx.ui.toolbar.CheckBox(this.getLabel(), this.getIcon()); + this._registerToggleButtonListeners(button); }else{ button = new qx.ui.toolbar.Button( this.getLabel(), @@ -104,19 +116,43 @@ return button; }, + /** + * Special tricks using UserData to enable/disable listeners to avoid loops... + * @param button {qx.ui.core.Widget} toolbar Checkbox or menu Checkbox button. + */ + _registerToggleButtonListeners : function(button){ + button.addListener("changeChecked", function(event){ + if(button.getUserData("disableListener")) return; + this.setUserData("slc.command.toggleState", event.getData()); + this.setUserData("slc.command.toggleStateSource", button); + this.fireEvent("execute"); + }, this); + this.addListener("execute", function(event){ + if(this.getUserData("slc;command.toggleStateSource") == button) return; + button.setUserData("disableListener", true); + button.setChecked(this.getUserData("slc.command.toggleState")); + button.setUserData("disableListener", false); + }, this); + }, + /** * Clones the command menu * @return {qx.ui.menu.Menu} */ getMenuClone : function(){ var menuClone = new qx.ui.menu.Menu(); + menuClone.setMinWidth(100); var submenus = this.getMenu(); if(!submenus) return; for(var i=0;i