]>
git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.webapp/src/main/webapp/argeo-ria-src/class/org/argeo/ria/components/Modal.js
2 * Generic modal popup window.
3 * It is layed out with a dock layout. When adding components to it, they are added as "center".
4 * @author Charles du Jeu
6 qx
.Class
.define("org.argeo.ria.components.Modal",
8 extend
: qx
.ui
.window
.Window
,
11 "ok" : "qx.event.type.Event"
15 * @param caption {String} Title of the window
16 * @param icon {String} Icon of the window
17 * @param text {String} Default content of the window.
19 construct : function(caption
, icon
, text
){
20 this.base(arguments
, caption
, icon
);
27 this.setLayout(new qx
.ui
.layout
.Dock());
37 * Display text inside the popup
38 * @param text {String} A string content for the popup
40 addLabel:function(text
){
41 var label
= new qx
.ui
.basic
.Label(text
);
43 label
.setTextAlign("center");
44 this.add(label
, {edge
:'center', width
:'100%'});
45 this.addCloseButton();
47 addConfirm : function(text
){
48 var label
= new qx
.ui
.basic
.Label(text
);
50 label
.setTextAlign("center");
51 this.add(label
, {edge
:'center', width
:'100%'});
55 * Display a component (panel) in the center of the popup
56 * @param panel {qx.ui.core.Widget} A gui component (will be set at width 100%).
58 addContent: function(panel
){
59 this.add(panel
, {edge
:'center', width
:'100%'});
60 this.addCloseButton();
63 * Automatically attach to the application root, then show.
65 attachAndShow:function(){
66 org
.argeo
.ria
.components
.ViewsManager
.getInstance().getApplicationRoot().add(this);
70 * Adds a close button bottom-center aligned to the popup
72 addCloseButton : function(){
73 this.closeButton
= new qx
.ui
.form
.Button("Close");
74 this.closeButton
.addListener("execute", this._closeAndDestroy
, this);
75 this.add(this.closeButton
, {edge
:'south'});
78 * Adds two buttons bottom-center aligned (Ok and Cancel).
79 * Ok button has no listener by default, Cancel will close and destroy the popup.
81 addOkCancel : function(){
82 var buttonPane
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.HBox(5, 'right'));
83 buttonPane
.setAlignX("center");
84 this.add(buttonPane
, {edge
:"south"});
85 this.okButton
= new qx
.ui
.form
.Button("Ok");
86 this.okButton
.addListener("execute", function(e
){
88 this._closeAndDestroy();
90 this.cancelButton
= new qx
.ui
.form
.Button("Cancel");
91 this.cancelButton
.addListener("execute", this._closeAndDestroy
, this);
92 buttonPane
.add(this.okButton
);
93 buttonPane
.add(this.cancelButton
);
96 * Adds a prompt form to the popup : a question, followed by a text input.
97 * @param questionString {String} The question to ask to the user
98 * @param validationCallback {Function} Callback to apply : takes the text input value as unique argument.
99 * @param callbackContext {Object} Context for the callback, optional.
101 makePromptForm:function(questionString
, validationCallback
, callbackContext
){
102 var label
= new qx
.ui
.basic
.Label(questionString
);
104 label
.setTextAlign("center");
105 this.add(label
, {edge
:'north'});
106 var textField
= new qx
.ui
.form
.TextField();
107 textField
.setMarginTop(10);
108 textField
.setMarginBottom(10);
109 this.add(textField
, {edge
:'center'});
112 validationCallback
= qx
.lang
.Function
.bind(validationCallback
, callbackContext
);
114 this.okButton
.addListener("execute", function(e
){
115 var valid
= validationCallback(textField
.getValue());
116 if(valid
) this._closeAndDestroy();
120 * Close this modal window and destroy it.
122 _closeAndDestroy : function(){