]>
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
3d3150b348b415e56e7a518440fecae954284d58
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
,
12 * Triggered when the user clicks the "ok" button.
14 "ok" : "qx.event.type.Event"
18 * @param caption {String} Title of the window
19 * @param icon {String} Icon of the window
20 * @param text {String} Default content of the window.
22 construct : function(caption
, icon
, text
){
23 this.base(arguments
, caption
, icon
);
30 this.setLayout(new qx
.ui
.layout
.Dock());
40 * Display text inside the popup
41 * @param text {String} A string content for the popup
43 addLabel:function(text
){
44 var label
= new qx
.ui
.basic
.Label(text
);
46 label
.setTextAlign("center");
47 this.add(label
, {edge
:'center', width
:'100%'});
48 this.addCloseButton();
51 * Add a question and ok / cancel buttons
52 * @param text {String} The question to ask to the user
54 addConfirm : function(text
){
55 var label
= new qx
.ui
.basic
.Label(text
);
57 label
.setTextAlign("center");
58 this.add(label
, {edge
:'center', width
:'100%'});
62 * Display a component (panel) in the center of the popup
63 * @param panel {qx.ui.core.Widget} A gui component (will be set at width 100%).
65 addContent: function(panel
){
66 this.add(panel
, {edge
:'center', width
:'100%'});
67 this.addCloseButton();
70 * Automatically attach to the application root, then show.
72 attachAndShow:function(){
73 org
.argeo
.ria
.components
.ViewsManager
.getInstance().getApplicationRoot().add(this);
77 * Adds a close button bottom-center aligned to the popup
79 addCloseButton : function(){
80 this.closeButton
= new qx
.ui
.form
.Button("Close");
81 this.closeButton
.addListener("execute", this._closeAndDestroy
, this);
82 this.add(this.closeButton
, {edge
:'south'});
85 * Adds two buttons bottom-center aligned (Ok and Cancel).
86 * Ok button has no listener by default, Cancel will close and destroy the popup.
88 addOkCancel : function(){
89 var buttonPane
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.HBox(5, 'right'));
90 buttonPane
.setAlignX("center");
91 this.add(buttonPane
, {edge
:"south"});
92 this.okButton
= new qx
.ui
.form
.Button("Ok");
93 this.okButton
.addListener("execute", function(e
){
95 this._closeAndDestroy();
97 this.cancelButton
= new qx
.ui
.form
.Button("Cancel");
98 this.cancelButton
.addListener("execute", this._closeAndDestroy
, this);
99 buttonPane
.add(this.okButton
);
100 buttonPane
.add(this.cancelButton
);
103 * Adds a prompt form to the popup : a question, followed by a text input.
104 * @param questionString {String} The question to ask to the user
105 * @param validationCallback {Function} Callback to apply : takes the text input value as unique argument.
106 * @param callbackContext {Object} Context for the callback, optional.
108 makePromptForm:function(questionString
, validationCallback
, callbackContext
){
109 var label
= new qx
.ui
.basic
.Label(questionString
);
111 label
.setTextAlign("center");
112 this.add(label
, {edge
:'north'});
113 var textField
= new qx
.ui
.form
.TextField();
114 textField
.setMarginTop(10);
115 textField
.setMarginBottom(10);
116 this.add(textField
, {edge
:'center'});
119 validationCallback
= qx
.lang
.Function
.bind(validationCallback
, callbackContext
);
121 this.okButton
.addListener("execute", function(e
){
122 var valid
= validationCallback(textField
.getValue());
123 if(valid
) this._closeAndDestroy();
127 * Close this modal window and destroy it.
129 _closeAndDestroy : function(){