]>
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
,
19 * Triggered when the user clicks the "ok" button.
21 "ok" : "qx.event.type.Event"
25 * @param caption {String} Title of the window
26 * @param icon {String} Icon of the window
27 * @param text {String} Default content of the window.
29 construct : function(caption
, icon
, text
){
30 this.base(arguments
, caption
, icon
);
37 this.setLayout(new qx
.ui
.layout
.Dock());
47 addCenter : function(component
){
48 if(!this.getPersistent()){
49 this.add(component
, {edge
: 'center', width
:'100%'});
51 if(!this.centerScroller
){
52 this.centerScroller
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.VBox(1));
53 this.add(new qx
.ui
.container
.Scroll(this.centerScroller
), {edge
: 'center', width
:'100%', height
:'100%'});
55 this.centerScroller
.add(component
);
60 * Display text inside the popup
61 * @param text {String} A string content for the popup
63 addLabel:function(text
){
64 var label
= new qx
.ui
.basic
.Label(text
);
66 label
.setTextAlign("center");
67 this.addCenter(label
);
68 this.addCloseButton();
71 * Add a question and ok / cancel buttons
72 * @param text {String} The question to ask to the user
74 addConfirm : function(text
){
75 var label
= new qx
.ui
.basic
.Label(text
);
77 label
.setTextAlign("center");
78 this.addCenter(label
);
82 * Display a component (panel) in the center of the popup
83 * @param panel {qx.ui.core.Widget} A gui component (will be set at width 100%).
85 addContent: function(panel
){
86 this.addCenter(panel
);
87 this.addCloseButton();
90 * Automatically attach to the application root, then show.
92 attachAndShow:function(){
94 org
.argeo
.ria
.components
.ViewsManager
.getInstance().getApplicationRoot().add(this);
100 * Adds a close button bottom-center aligned to the popup
102 addCloseButton : function(){
103 this.closeButton
= new qx
.ui
.form
.Button("Close");
104 this.closeButton
.addListener("execute", this._closeAndDestroy
, this);
105 this.add(this.closeButton
, {edge
:'south'});
108 * Adds two buttons bottom-center aligned (Ok and Cancel).
109 * Ok button has no listener by default, Cancel will close and destroy the popup.
111 addOkCancel : function(){
112 var buttonPane
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.HBox(5, 'right'));
113 buttonPane
.setAlignX("center");
114 this.add(buttonPane
, {edge
:"south"});
115 this.okButton
= new qx
.ui
.form
.Button("Ok");
116 this.okButton
.addListener("execute", function(e
){
117 this.fireEvent("ok");
118 this._closeAndDestroy();
120 this.cancelButton
= new qx
.ui
.form
.Button("Cancel");
121 this.cancelButton
.addListener("execute", this._closeAndDestroy
, this);
122 buttonPane
.add(this.okButton
);
123 buttonPane
.add(this.cancelButton
);
126 * Adds a prompt form to the popup : a question, followed by a text input.
127 * @param questionString {String} The question to ask to the user
128 * @param validationCallback {Function} Callback to apply : takes the text input value as unique argument.
129 * @param callbackContext {Object} Context for the callback, optional.
131 makePromptForm:function(questionString
, validationCallback
, callbackContext
){
132 var label
= new qx
.ui
.basic
.Label(questionString
);
134 label
.setTextAlign("center");
135 this.add(label
, {edge
:'north'});
136 var textField
= new qx
.ui
.form
.TextField();
137 textField
.setMarginTop(10);
138 textField
.setMarginBottom(10);
139 this.add(textField
, {edge
:'center'});
142 validationCallback
= qx
.lang
.Function
.bind(validationCallback
, callbackContext
);
144 this.okButton
.addListener("execute", function(e
){
145 var valid
= validationCallback(textField
.getValue());
146 if(valid
) this._closeAndDestroy();
150 * Close this modal window and destroy it.
152 _closeAndDestroy : function(){
154 if(!this.getPersistent()){
157 if(this.centerScroller
) this.centerScroller
.removeAll();