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',
29 * It can be used to build a big heiracy,
31 * MYPART.renderTo(Roo.Element | String(id) | dom_element )
34 * @extends Roo.util.Observable
36 * @param cfg {Object} configuration of component
39 Roo.XComponent = function(cfg) {
44 * Fires when this the componnt is built
45 * @param {Roo.XComponent} c the component
49 * @event buildcomplete
50 * Fires on the top level element when all elements have been built
51 * @param {Roo.XComponent} c the top level component.
53 'buildcomplete' : true
57 Roo.XComponent.register(this);
59 this.el = false; // where the layout goes..
63 Roo.extend(Roo.XComponent, Roo.util.Observable, {
66 * The created element (with Roo.factory())
73 * for BC - use el in new code
80 * for BC - use el in new code
86 * @cfg {Function|boolean} disabled
87 * If this module is disabled by some rule, return true from the funtion
92 * @cfg {String} parent
93 * Name of parent element which it get xtype added to..
99 * Used to set the order in which elements are created (usefull for multiple tabs)
105 * String to display while loading.
110 * A single item array - the first element is the root of the tree..
111 * It's done this way to stay compatible with the Xtype system...
115 renderTo : function(el)
120 el = el ? Roo.get(el) : false;
123 // it's a top level one..
124 var layoutbase = new Ext.BorderLayout(el || document.body, {
132 alwaysShowTabs: el ? false : true,
137 var tree = this.tree();
138 tree.region = 'center';
140 // set up component properties..
141 this.el = layoutbase.addxtype(tree);
142 this.panel = this.el;
143 this.layout = this.panel.layout;
145 return progressRun.defer(10, _this);
149 tree.region = tree.region || m.region;
150 m.el = m.parent.el.addxtype(tree);
151 m.fireEvent('built', m);
153 m.layout = m.panel.layout;
154 progressRun.defer(10, _this);
170 Roo.apply(Roo.XComponent, {
173 * @property buildCompleted
174 * True when the builder has completed building the interface.
177 buildCompleted : false,
180 * @property topModule
181 * the upper most module - uses document.element as it's constructor.
189 * array of modules to be created by registration system.
190 * @type Roo.XComponent
197 * Register components to be built later.
199 * This solves the following issues
200 * - Building is not done on page load, but after an authentication process has occured.
201 * - Interface elements are registered on page load
202 * - Parent Interface elements may not be loaded before child, so this handles that..
209 module : 'Pman.Tab.projectMgr',
211 parent : 'Pman.layout',
212 disabled : false, // or use a function..
215 * * @param {Object} details about module
217 register : function(obj) {
218 this.modules.push(obj);
222 * convert a string to an object..
226 toObject : function(str)
228 if (!str || typeof(str) == 'object') {
231 var ar = str.split('.');
235 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
237 throw "Module not found : " + str;
239 Roo.each(ar, function(e) {
240 if (typeof(o[e]) == 'undefined') {
241 throw "Module not found : " + str;
251 * move modules into their correct place in the tree..
254 preBuild : function ()
257 Roo.each(this.modules , function (obj)
259 obj.parent = this.toObject(obj.parent);
262 this.topModule = obj;
266 if (!obj.parent.modules) {
267 obj.parent.modules = new Roo.util.MixedCollection(false,
268 function(o) { return o.order + '' }
272 obj.parent.modules.add(obj);
277 * make a list of modules to build.
278 * @return {Array} list of modules.
281 buildOrder : function()
284 var cmp = function(a,b) {
285 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
288 if (!this.topModule || !this.topModule.modules) {
289 throw "No top level modules to build";
292 // make a flat list in order of modules to build.
293 var mods = [ this.topModule ];
296 // add modules to their parents..
297 var addMod = function(m) {
298 // Roo.debug && Roo.log(m.modKey);
302 m.modules.keySort('ASC', cmp );
303 m.modules.each(addMod);
305 // not sure if this is used any more..
307 m.finalize.name = m.name + " (clean up) ";
308 mods.push(m.finalize);
312 this.topModule.modules.keySort('ASC', cmp );
313 this.topModule.modules.each(addMod);
318 * Build the registered modules.
319 * @param {Object} parent element.
320 * @param {Function} optional method to call after module has been added.
328 var mods = this.buildOrder();
330 //this.allmods = mods;
331 //Roo.debug && Roo.log(mods);
333 if (!mods.length) { // should not happen
334 throw "NO modules!!!";
339 // flash it up as modal - so we store the mask!?
340 Roo.MessageBox.show({ title: 'loading' });
341 Roo.MessageBox.show({
342 title: "Please wait...",
343 msg: "Building Interface...",
350 var total = mods.length;
353 var progressRun = function() {
355 Roo.debug && Roo.log('hide?');
356 Roo.MessageBox.hide();
357 _this.topModule.fireEvent('buildcomplete', _this.topModule);
361 var m = mods.shift();
364 Roo.debug && Roo.log(m);
365 // not sure if this is supported any more.. - modules that are are just function
366 if (typeof(m) == 'function') {
368 return progressRun.defer(10, _this);
373 Roo.MessageBox.updateProgress(
374 (total - mods.length)/total, "Building Interface " + (total - mods.length) +
376 (m.name ? (' - ' + m.name) : '')
380 // is the module disabled?
381 var disabled = (typeof(m.disabled) == 'function') ?
382 m.disabled.call(m.module.disabled) : m.disabled;
386 return progressRun(); // we do not update the display!
395 // it's a top level one..
396 var layoutbase = new Ext.BorderLayout(document.body, {
404 alwaysShowTabs: true,
409 tree.region = 'center';
410 m.el = layoutbase.addxtype(tree);
412 m.layout = m.panel.layout;
413 return progressRun.defer(10, _this);
417 tree.region = tree.region || m.region;
418 m.el = m.parent.el.addxtype(tree);
419 m.fireEvent('built', m);
421 m.layout = m.panel.layout;
422 progressRun.defer(10, _this);
425 progressRun.defer(1, _this);