]>
git.argeo.org Git - gpl/argeo-slc.git/blob - server/org.argeo.slc.ria/src/argeo-ria-lib/slc/class/org/argeo/slc/ria/execution/SpecEditor.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.slc.ria.execution.SpecEditor",
8 extend
: qx
.ui
.window
.Window
,
15 check
: "org.argeo.slc.ria.execution.BatchEntrySpec"
21 * Triggered when the user clicks the "save" button.
23 "save" : "qx.event.type.Event",
25 * Triggered when any data is modified
27 "modified" : "qx.event.type.Event"
31 * Opens an editor with the given values.
32 * @param batchEntrySpec {org.argeo.slc.ria.execution.BatchEntrySpec} The initial spec to edit
34 construct : function(batchEntrySpec
){
35 var editorLabel
= "Edit Specs for "+batchEntrySpec
.getLabel();
36 this.base(arguments
, editorLabel
);
38 batchEntrySpec
: batchEntrySpec
,
41 width
: Math
.min(parseInt(qx
.bom
.Viewport
.getWidth()*90/100), 400),
42 height
: parseInt(qx
.bom
.Viewport
.getHeight()*60/100)
44 this.setLayout(new qx
.ui
.layout
.Dock());
47 this._initFormObject(this.getBatchEntrySpec().getLabel());
48 this._addFormHeader(this.formObject
, editorLabel
);
49 this.createFormFromSpec();
50 this.addContent(this.formObject
.pane
);
52 this.addListener("save", function(e
){
53 this.saveFormToSpec();
59 * Builds the form from the BatchEntrySpec
61 createFormFromSpec : function(){
62 var values
= this.getBatchEntrySpec().getValues();
63 for(var key
in values
){
64 var valueObj
= values
[key
];
66 var hidden
= valueObj
.getHidden();
67 var disabled
= valueObj
.getFrozen();
68 var value
= valueObj
.getValue();
69 var type
= valueObj
.getSpecType();
70 var subType
= valueObj
.getSpecSubType();
71 if(type
== "primitive" && !hidden
){
72 this._addFormInputText(this.formObject
, key
, key
, value
, disabled
, subType
);
77 * Gather data from the form
79 saveFormToSpec : function(){
80 var values
= this.getBatchEntrySpec().getValues();
81 for(var key
in values
){
82 var valueObj
= values
[key
];
83 var hidden
= valueObj
.getHidden();
84 var disabled
= valueObj
.getFrozen();
85 if(valueObj
.getSpecType() == "primitive"){
86 if(!hidden
&& !disabled
){
87 valueObj
.setValue(this.formObject
.fields
[key
].getValue());
94 * Display a component (panel) in the center of the popup
95 * @param panel {qx.ui.core.Widget} A gui component (will be set at width 100%).
97 addContent: function(panel
){
98 this.add(new qx
.ui
.container
.Scroll(panel
), {edge
:'center', width
:'100%'});
101 * Automatically attach to the application root, then show.
103 attachAndShow:function(){
104 org
.argeo
.ria
.components
.ViewsManager
.getInstance().getApplicationRoot().add(this);
108 * Init a form part : creates a pane, a set of fields, etc.
109 * @param label {String} A label
110 * @return {Map} The form part.
112 _initFormObject : function(label
){
113 this.formObject
= {};
114 this.formObject
.hiddenFields
= {};
115 this.formObject
.freeFields
= [];
116 this.formObject
.fields
= {};
117 this.formObject
.label
= label
;
118 this.formObject
.pane
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.VBox(5));
119 return this.formObject
;
123 * Creates a simple label/input form entry.
124 * @param formObject {Map} The form part
125 * @param fieldName {String} Name
126 * @param fieldLabel {String} Label of the field
127 * @param defaultValue {String} The default value
128 * @param choiceValues {Map} An map of values
129 * @param disabled {Boolean} The field is not writable
130 * @param subType {String} The type expected (string, integer, etc).
132 _addFormInputText : function(formObject
, fieldName
, fieldLabel
, defaultValue
, disabled
, subType
, choiceValues
){
135 var fieldElement
= new qx
.ui
.form
.SelectBox();
136 for(var key
in choiceValues
){
137 fieldElement
.add(new qx
.ui
.form
.ListItem(choiceValues
[key
], null, key
));
139 fieldElement
.addListener("changeSelected", function(e
){this.fireEvent("modified")}, this);
141 var fieldElement
= new qx
.ui
.form
.TextField();
142 if(subType
== "integer"){
143 fieldElement
.addListener("changeValue", function(e
){
144 var isNum
= !isNaN(e
.getData() * 1);
146 alert("Warning, this field only accepts Integers!");
150 fieldElement
.addListener("input", function(e
){this.fireEvent("modified")}, this);
153 fieldElement
.setValue(defaultValue
);
155 if(fieldName
&& fieldLabel
){
156 labelElement
= new qx
.ui
.basic
.Label(fieldLabel
);
157 formObject
.fields
[fieldName
] = fieldElement
;
159 labelElement
= new qx
.ui
.form
.TextField();
160 formObject
.freeFields
.push({
161 labelEl
:labelElement
,
165 if(disabled
) fieldElement
.setEnabled(false);
166 this._addFormEntry(formObject
, labelElement
, fieldElement
);
171 * @param formObject {Map} The form part
172 * @param content {Mixed} Content to add.
173 * @param additionnalButton {Mixed} Any widget to add on the east.
175 _addFormHeader : function(formObject
, content
, additionnalButton
){
176 var header
= new qx
.ui
.basic
.Label('<big><b>'+content
+'</b></big>');
177 header
.setRich(true);
178 if(!additionnalButton
){
179 header
.setPaddingBottom(10);
180 formObject
.pane
.add(header
);
182 var pane
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.Dock());
183 pane
.setPaddingBottom(10);
184 pane
.setPaddingRight(10);
185 pane
.add(header
, {edge
:'center'});
186 pane
.add(additionnalButton
, {edge
:'east'});
187 formObject
.pane
.add(pane
);
192 * Adds a label/input like entry in the form.
193 * @param formObject {Map} The form part
194 * @param labelElement {Object} Either a label or an input
195 * @param fieldElement {Object} Any form input.
197 _addFormEntry : function(formObject
, labelElement
, fieldElement
){
198 var entryPane
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.HBox(5));
199 labelElement
.setWidth(150);
200 labelElement
.setTextAlign("right");
201 entryPane
.add(labelElement
);
202 entryPane
.add(new qx
.ui
.basic
.Label(':'));
203 fieldElement
.setWidth(150);
204 entryPane
.add(fieldElement
);
205 formObject
.pane
.add(entryPane
);
209 * Adds a close button bottom-center aligned to the popup
211 addCloseButton : function(){
212 this.closeButton
= new qx
.ui
.form
.Button("Close");
213 this.closeButton
.addListener("execute", this._closeAndDestroy
, this);
214 this.add(this.closeButton
, {edge
:'south'});
217 * Adds two buttons bottom-center aligned (Ok and Cancel).
218 * Ok button has no listener by default, Cancel will close and destroy the popup.
220 addOkCancel : function(){
221 var buttonPane
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.HBox(5, 'right'));
222 buttonPane
.setAlignX("center");
223 this.add(buttonPane
, {edge
:"south"});
224 this.okButton
= new qx
.ui
.form
.Button("Save");
225 this.okButton
.setEnabled(false);
226 this.addListener("modified", function(e
){
227 this.okButton
.setEnabled(true);
229 this.okButton
.addListener("execute", function(e
){
230 this.fireEvent("save");
231 this.okButton
.setEnabled(false);
233 this.cancelButton
= new qx
.ui
.form
.Button("Close");
234 this.cancelButton
.addListener("execute", this._closeAndDestroy
, this);
236 this.saveCloseButton
= new qx
.ui
.form
.Button("Save & Close");
237 this.saveCloseButton
.addListener("execute", function(e
){
238 this.fireEvent("save");
239 this._closeAndDestroy();
242 buttonPane
.add(this.okButton
);
243 buttonPane
.add(this.cancelButton
);
244 buttonPane
.add(this.saveCloseButton
);
247 * Close this modal window and destroy it.
249 _closeAndDestroy : function(){