|
26 |
* /usr/share/common-licenses/AGPL-3; if not, see |
26 |
* /usr/share/common-licenses/AGPL-3; if not, see |
27 |
* <http://www.gnu.org/licenses/>. |
27 |
* <http://www.gnu.org/licenses/>. |
28 |
*/ |
28 |
*/ |
29 |
/*global define */ |
29 |
/*global define require console*/ |
30 |
|
30 |
|
31 |
define([ |
31 |
define([ |
32 |
"dojo/_base/declare", |
32 |
"dojo/_base/declare", |
33 |
"dojo/_base/lang", |
33 |
"dojo/_base/lang", |
34 |
"dojo/_base/array", |
34 |
"dojo/_base/array", |
35 |
"dojo/Deferred", |
35 |
"dojo/Deferred", |
36 |
"dojo/on", |
36 |
"dojo/promise/all", |
37 |
"dojo/dom-style", |
37 |
"dojo/dom-style", |
38 |
"dijit/form/Form", |
38 |
"dijit/form/Form", |
39 |
"umc/tools", |
39 |
"umc/tools", |
40 |
"umc/render" |
40 |
"umc/render" |
41 |
], function(declare, lang, array, Deferred, on, style, Form, tools, render) { |
41 |
], function(declare, lang, array, Deferred, all, style, Form, tools, render) { |
42 |
|
42 |
|
43 |
// in order to break circular dependencies (umc.dialog needs a Form and |
43 |
// in order to break circular dependencies (umc.dialog needs a Form and |
44 |
// Form needs umc/dialog), we define umc/dialog as an empty object and |
44 |
// Form needs umc/dialog), we define umc/dialog as an empty object and |
|
121 |
|
121 |
|
122 |
//'class': 'umcNoBorder', |
122 |
//'class': 'umcNoBorder', |
123 |
|
123 |
|
124 |
_initializingElements: 0, |
124 |
_allReady: null, |
125 |
|
125 |
|
126 |
_initializedDeferred: null, |
|
|
127 |
|
128 |
postMixInProperties: function() { |
126 |
postMixInProperties: function() { |
129 |
this.inherited(arguments); |
127 |
this.inherited(arguments); |
130 |
|
128 |
|
|
|
129 |
// initialize with empty list |
130 |
this._allReady = []; |
131 |
|
131 |
// in case no layout is specified and no content, either, create one automatically |
132 |
// in case no layout is specified and no content, either, create one automatically |
132 |
if ((!this.layout || !this.layout.length) && !this.content) { |
133 |
if ((!this.layout || !this.layout.length) && !this.content) { |
133 |
this.layout = []; |
134 |
this.layout = []; |
|
183 |
buildRendering: function() { |
184 |
buildRendering: function() { |
184 |
this.inherited(arguments); |
185 |
this.inherited(arguments); |
185 |
|
186 |
|
186 |
this._initializedDeferred = new Deferred(); |
|
|
187 |
|
188 |
if (this.scrollable) { |
187 |
if (this.scrollable) { |
189 |
style.set(this.containerNode, { |
188 |
style.set(this.containerNode, { |
190 |
overflow: 'auto' |
189 |
overflow: 'auto' |
|
225 |
} |
224 |
} |
226 |
} |
225 |
} |
227 |
|
226 |
|
228 |
|
227 |
this._updateAllReady(); |
229 |
// send an event when all dynamic elements have been initialized |
|
|
230 |
this._initializingElements = 0; |
231 |
//console.log('# Form.buildRendering()'); |
232 |
tools.forIn(this._widgets, function(iname, iwidget) { |
233 |
// only consider elements that load values dynamically |
234 |
//console.log('# iwidget:', iwidget.name); |
235 |
if ('onValuesLoaded' in iwidget && !(iwidget._valuesLoaded && !iwidget._deferredOrValues)) { |
236 |
// widget values have not been loaded completely so far |
237 |
//console.log('# -> has event "valuesLoaded"'); |
238 |
++this._initializingElements; |
239 |
on.once(iwidget, 'valuesLoaded', lang.hitch(this, function() { |
240 |
//console.log('# -> valuesLoaded:', iwidget.name, iwidget.get('value')); |
241 |
// decrement the internal counter |
242 |
--this._initializingElements; |
243 |
//console.log('# _initializingElements:', this._initializingElements); |
244 |
|
245 |
// send event when the last element has been initialized |
246 |
if (0 === this._initializingElements) { |
247 |
this._initializedDeferred.resolve(); |
248 |
} |
249 |
})); |
250 |
} |
251 |
}, this); |
252 |
|
253 |
// maybe all elements are already initialized |
254 |
if (!this._initializingElements) { |
255 |
this._initializedDeferred.resolve(); |
256 |
} |
257 |
|
258 |
}, |
228 |
}, |
259 |
|
229 |
|
260 |
startup: function() { |
230 |
startup: function() { |
|
|
231 |
//console.log('### Form: startup - container:', this._container); |
261 |
this.inherited(arguments); |
232 |
this.inherited(arguments); |
262 |
if (this._container) { |
233 |
if (this._container) { |
263 |
// call the containers startup function if necessary |
234 |
// call the containers startup function if necessary |
264 |
this._container.startup(); |
235 |
this._container.startup(); |
265 |
} |
236 |
} |
266 |
this._initializedDeferred.then(lang.hitch(this, function() { |
237 |
this.ready().then(lang.hitch(this, function() { |
|
|
238 |
//console.log('### Form: all ready'); |
267 |
this.onValuesInitialized(); |
239 |
this.onValuesInitialized(); |
268 |
//console.log('# valuesInitialized'); |
|
|
269 |
})); |
240 |
})); |
270 |
}, |
241 |
}, |
271 |
|
242 |
|
|
553 |
dialog.notify(error_msg); |
524 |
dialog.notify(error_msg); |
554 |
} |
525 |
} |
555 |
})); |
526 |
})); |
556 |
} |
527 |
}, |
557 |
|
528 |
|
|
|
529 |
_updateAllReady: function() { |
530 |
// wait for all widgets to be ready |
531 |
this._allReady = []; |
532 |
//console.log('### Form: iterate over widgets.ready'); |
533 |
tools.forIn(this._widgets, function(iname, iwidget) { |
534 |
//console.log('### ' + iname + ' -> ', iwidget.ready ? iwidget.ready() : null); |
535 |
this._allReady.push(iwidget.ready ? iwidget.ready() : null); |
536 |
}, this); |
537 |
}, |
538 |
|
539 |
ready: function() { |
540 |
// update the internal list in order to wait until everybody is ready |
541 |
if (!this._allReady.length) { |
542 |
_updateAllReady(); |
543 |
} |
544 |
var ret = all(this._allReady); |
545 |
|
546 |
// empty list when all widgets are ready |
547 |
ret.then(lang.hitch(this, function() { |
548 |
this._allReady = []; |
549 |
})); |
550 |
return ret; |
551 |
} |
558 |
}); |
552 |
}); |
559 |
}); |
553 |
}); |
560 |
|
554 |
|