2 * Original code for Roojs - LGPL
3 * <script type="text/javascript">
7 * @class Roo.XComponent
8 * A delayed Element creator...
10 * Mypart.xyx = new Roo.XComponent({
12 parent : 'Mypart.xyz', // empty == document.element.!!
16 disabled : function() {}
18 tree : function() { // return an tree of xtype declared components
22 xtype : 'NestedLayoutPanel',
28 * Roo.onReady(function() {
29 Roo.XComponent.build();
32 * @extends Roo.util.Observable
34 * @param cfg {Object} configuration of component
37 Roo.XComponent = function(cfg) {
42 * Fires when this the componnt is built
43 * @param {Roo.XComponent} c the component
47 * @event buildcomplete
48 * Fires on the top level element when all elements have been built
49 * @param {Roo.XComponent} c the top level component.
51 'buildcomplete' : true
55 Roo.XComponent.register(this);
57 this.el = false; // where the layout goes..
61 Roo.extend(Roo.XComponent, Roo.util.Observable, {
64 * The created element (with Roo.factory())
71 * for BC - use el in new code
78 * for BC - use el in new code
84 * @cfg {Function|boolean} disabled
85 * If this module is disabled by some rule, return true from the funtion
90 * @cfg {String} parent
91 * Name of parent element which it get xtype added to..
97 * Used to set the order in which elements are created (usefull for multiple tabs)
103 * String to display while loading.
108 * A single item array - the first element is the root of the tree..
109 * It's done this way to stay compatible with the Xtype system...
115 Roo.apply(Roo.XComponent, {
118 * @property buildCompleted
119 * True when the builder has completed building the interface.
122 buildCompleted : false,
125 * @property topModule
126 * the upper most module - uses document.element as it's constructor.
134 * array of modules to be created by registration system.
135 * @type {Array} of Roo.XComponent
141 * @property elmodules
142 * array of modules to be created by which use #ID
143 * @type {Array} of Roo.XComponent
148 * Register components to be built later.
150 * This solves the following issues
151 * - Building is not done on page load, but after an authentication process has occured.
152 * - Interface elements are registered on page load
153 * - Parent Interface elements may not be loaded before child, so this handles that..
160 module : 'Pman.Tab.projectMgr',
162 parent : 'Pman.layout',
163 disabled : false, // or use a function..
166 * * @param {Object} details about module
168 register : function(obj) {
169 this.modules.push(obj);
173 * convert a string to an object..
174 * eg. 'AAA.BBB' -> finds AAA.BBB
178 toObject : function(str)
180 if (!str || typeof(str) == 'object') {
186 var ar = str.split('.');
190 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
195 throw "Module not found : " + str;
197 Roo.each(ar, function(e) {
198 if (typeof(o[e]) == 'undefined') {
199 throw "Module not found : " + str;
209 * move modules into their correct place in the tree..
212 preBuild : function ()
215 Roo.each(this.modules , function (obj)
217 obj.parent = this.toObject(obj.parent);
220 this.topModule = obj;
223 if (typeof(obj.parent) == 'string') {
224 this.elmodules.push(obj);
228 if (!obj.parent.modules) {
229 obj.parent.modules = new Roo.util.MixedCollection(false,
230 function(o) { return o.order + '' }
234 obj.parent.modules.add(obj);
239 * make a list of modules to build.
240 * @return {Array} list of modules.
243 buildOrder : function()
246 var cmp = function(a,b) {
247 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
250 if ((!this.topModule || !this.topModule.modules) && !this.elmodules.length) {
251 throw "No top level modules to build";
254 // make a flat list in order of modules to build.
255 var mods = this.topModule ? [ this.topModule ] : [];
256 Roo.each(this.elmodules,function(e) { mods.push(e) });
259 // add modules to their parents..
260 var addMod = function(m) {
261 // Roo.debug && Roo.log(m.modKey);
265 m.modules.keySort('ASC', cmp );
266 m.modules.each(addMod);
268 // not sure if this is used any more..
270 m.finalize.name = m.name + " (clean up) ";
271 mods.push(m.finalize);
275 if (this.topModule) {
276 this.topModule.modules.keySort('ASC', cmp );
277 this.topModule.modules.each(addMod);
283 * Build the registered modules.
284 * @param {Object} parent element.
285 * @param {Function} optional method to call after module has been added.
293 var mods = this.buildOrder();
295 //this.allmods = mods;
296 //Roo.debug && Roo.log(mods);
298 if (!mods.length) { // should not happen
299 throw "NO modules!!!";
304 // flash it up as modal - so we store the mask!?
305 Roo.MessageBox.show({ title: 'loading' });
306 Roo.MessageBox.show({
307 title: "Please wait...",
308 msg: "Building Interface...",
315 var total = mods.length;
318 var progressRun = function() {
320 Roo.debug && Roo.log('hide?');
321 Roo.MessageBox.hide();
322 if (_this.topModule) {
323 _this.topModule.fireEvent('buildcomplete', _this.topModule);
329 var m = mods.shift();
330 Roo.debug && Roo.log(m);
331 if (typeof(m) == 'function') { // not sure if this is supported any more..
333 return progressRun.defer(10, _this);
336 Roo.MessageBox.updateProgress(
337 (total - mods.length)/total, "Building Interface " + (total - mods.length) +
339 (m.name ? (' - ' + m.name) : '')
344 var disabled = (typeof(m.disabled) == 'function') ?
345 m.disabled.call(m.module.disabled) : m.disabled;
349 return progressRun(); // we do not update the display!
352 if (!m.parent || (typeof(m.parent) == 'string' && m.parent[0] == '#')) {
353 // it's a top level one..
354 var ctr = m.parent ? Roo.get(m.parent.substr(1)) : document.body;
356 Roo.log("not rendering module " + m.name + " " + m.parent + " no found");
357 return progressRun.defer(10, _this);
362 var layoutbase = new Ext.BorderLayout(
363 m.parent ? Roo.get(m.parent.substr(1)) : document.body,
371 alwaysShowTabs: m.parent ? false : true,
372 hideTabs : m.parent ? true : false,
377 tree.region = 'center';
378 m.el = layoutbase.addxtype(tree);
380 m.layout = m.panel.layout;
381 return progressRun.defer(10, _this);
385 tree.region = tree.region || m.region;
386 m.el = m.parent.el.addxtype(tree);
387 m.fireEvent('built', m);
389 m.layout = m.panel.layout;
390 return progressRun.defer(10, _this);
393 progressRun.defer(1, _this);