Use modal as prompt form
authorCharles du Jeu <charles.dujeu@gmail.com>
Mon, 8 Dec 2008 19:08:53 +0000 (19:08 +0000)
committerCharles du Jeu <charles.dujeu@gmail.com>
Mon, 8 Dec 2008 19:08:53 +0000 (19:08 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@1961 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

org.argeo.slc.webapp/src/main/webapp/source/class/org/argeo/ria/components/Modal.js

index 2c8aef04d6f6ce9b7338f9402fa2cae82809e07d..810431d044b44b1745ce2cd2bc28214868f31cb7 100644 (file)
@@ -14,7 +14,7 @@ qx.Class.define("org.argeo.ria.components.Modal",
         * @param text {String} Default content of the window.\r
         */\r
        construct : function(caption, icon, text){\r
-               this.base(arguments);\r
+               this.base(arguments, caption, icon);\r
                this.set({\r
                        showMaximize : false,\r
                        showMinimize : false,\r
@@ -22,13 +22,8 @@ qx.Class.define("org.argeo.ria.components.Modal",
                        height: 150\r
                });\r
                this.setLayout(new qx.ui.layout.Dock());\r
-               var closeButton = new qx.ui.form.Button("Close");\r
-               closeButton.addListener("execute", function(e){\r
-                       this.hide();\r
-                       this.destroy();\r
-               }, this);\r
-               this.add(closeButton, {edge:'south'});\r
                this.setModal(true);\r
+               this.addCloseButton();\r
                this.center();\r
                if(text){\r
                        this.addLabel(text);\r
@@ -56,6 +51,28 @@ qx.Class.define("org.argeo.ria.components.Modal",
                attachAndShow:function(){\r
                        org.argeo.ria.components.ViewsManager.getInstance().getApplicationRoot().add(this);                     \r
                        this.show();\r
+               },\r
+               addCloseButton : function(){\r
+                       this.closeButton = new qx.ui.form.Button("Close");\r
+                       this.closeButton.addListener("execute", this._closeAndDestroy, this);\r
+                       this.add(this.closeButton, {edge:'south'});                     \r
+               },\r
+               makePromptForm:function(questionString, validationCallback, callbackContext){\r
+                       this.add(new qx.ui.basic.Label(questionString), {edge:'north'});\r
+                       var textField = new qx.ui.form.TextField();\r
+                       this.add(textField, {edge:'center'});\r
+                       this.closeButton.removeListener("execute", this._closeAndDestroy, this);\r
+                       if(callbackContext){\r
+                               validationCallback = qx.lang.Function.bind(validationCallback, callbackContext);\r
+                       }\r
+                       this.closeButton.addListener("execute", function(e){\r
+                               var valid = validationCallback(textField.getValue());\r
+                               if(valid) this._closeAndDestroy();\r
+                       }, this);\r
+               },\r
+               _closeAndDestroy : function(){\r
+                       this.hide();\r
+                       this.destroy();                 \r
                }\r
        }\r
 });
\ No newline at end of file