2 * Original code for Roojs - LGPL
3 * <script type="text/javascript">
7 * @class Roo.XComponent
8 * A delayed Element creator...
9 * Or a way to group chunks of interface together.
11 * Mypart.xyx = new Roo.XComponent({
13 parent : 'Mypart.xyz', // empty == document.element.!!
17 disabled : function() {}
19 tree : function() { // return an tree of xtype declared components
23 xtype : 'NestedLayoutPanel',
30 * It can be used to build a big heiracy,
32 * MYPART.renderTo(Roo.Element | String(id) | dom_element )
35 * @extends Roo.util.Observable
37 * @param cfg {Object} configuration of component
40 Roo.XComponent = function(cfg) {
45 * Fires when this the componnt is built
46 * @param {Roo.XComponent} c the component
50 * @event buildcomplete
51 * Fires on the top level element when all elements have been built
52 * @param {Roo.XComponent} c the top level component.
54 'buildcomplete' : true
58 Roo.XComponent.register(this);
60 this.el = false; // where the layout goes..
64 Roo.extend(Roo.XComponent, Roo.util.Observable, {
67 * The created element (with Roo.factory())
74 * for BC - use el in new code
81 * for BC - use el in new code
87 * @cfg {Function|boolean} disabled
88 * If this module is disabled by some rule, return true from the funtion
93 * @cfg {String} parent
94 * Name of parent element which it get xtype added to..
100 * Used to set the order in which elements are created (usefull for multiple tabs)
106 * String to display while loading.
110 * @cfg {String} region
111 * Region to render component to (defaults to center)
117 * A single item array - the first element is the root of the tree..
118 * It's done this way to stay compatible with the Xtype system...
125 * render element to dom or tree
126 * @param {Roo.Element|String|DomElement} optional render to if parent is not set.
129 render : function(el)
134 el = el ? Roo.get(el) : false;
137 // it's a top level one..
139 el : new Ext.BorderLayout(el || document.body, {
147 alwaysShowTabs: el ? false : true,
154 var tree = this.tree();
155 tree.region = tree.region || this.region;
156 this.el = this.parent.el.addxtype(tree);
157 this.fireEvent('built', this);
159 this.panel = this.el;
160 this.layout = this.panel.layout;
169 Roo.apply(Roo.XComponent, {
172 * @property buildCompleted
173 * True when the builder has completed building the interface.
176 buildCompleted : false,
179 * @property topModule
180 * the upper most module - uses document.element as it's constructor.
188 * array of modules to be created by registration system.
189 * @type Roo.XComponent
196 * Register components to be built later.
198 * This solves the following issues
199 * - Building is not done on page load, but after an authentication process has occured.
200 * - Interface elements are registered on page load
201 * - Parent Interface elements may not be loaded before child, so this handles that..
208 module : 'Pman.Tab.projectMgr',
210 parent : 'Pman.layout',
211 disabled : false, // or use a function..
214 * * @param {Object} details about module
216 register : function(obj) {
217 this.modules.push(obj);
221 * convert a string to an object..
225 toObject : function(str)
227 if (!str || typeof(str) == 'object') {
230 var ar = str.split('.');
234 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
236 throw "Module not found : " + str;
238 Roo.each(ar, function(e) {
239 if (typeof(o[e]) == 'undefined') {
240 throw "Module not found : " + str;
250 * move modules into their correct place in the tree..
253 preBuild : function ()
256 Roo.each(this.modules , function (obj)
258 obj.parent = this.toObject(obj.parent);
261 this.topModule = obj;
265 if (!obj.parent.modules) {
266 obj.parent.modules = new Roo.util.MixedCollection(false,
267 function(o) { return o.order + '' }
271 obj.parent.modules.add(obj);
276 * make a list of modules to build.
277 * @return {Array} list of modules.
280 buildOrder : function()
283 var cmp = function(a,b) {
284 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
287 if (!this.topModule || !this.topModule.modules) {
288 throw "No top level modules to build";
291 // make a flat list in order of modules to build.
292 var mods = [ this.topModule ];
295 // add modules to their parents..
296 var addMod = function(m) {
297 // Roo.debug && Roo.log(m.modKey);
301 m.modules.keySort('ASC', cmp );
302 m.modules.each(addMod);
304 // not sure if this is used any more..
306 m.finalize.name = m.name + " (clean up) ";
307 mods.push(m.finalize);
311 this.topModule.modules.keySort('ASC', cmp );
312 this.topModule.modules.each(addMod);
317 * Build the registered modules.
318 * @param {Object} parent element.
319 * @param {Function} optional method to call after module has been added.
327 var mods = this.buildOrder();
329 //this.allmods = mods;
330 //Roo.debug && Roo.log(mods);
332 if (!mods.length) { // should not happen
333 throw "NO modules!!!";
338 // flash it up as modal - so we store the mask!?
339 Roo.MessageBox.show({ title: 'loading' });
340 Roo.MessageBox.show({
341 title: "Please wait...",
342 msg: "Building Interface...",
349 var total = mods.length;
352 var progressRun = function() {
354 Roo.debug && Roo.log('hide?');
355 Roo.MessageBox.hide();
356 _this.topModule.fireEvent('buildcomplete', _this.topModule);
360 var m = mods.shift();
363 Roo.debug && Roo.log(m);
364 // not sure if this is supported any more.. - modules that are are just function
365 if (typeof(m) == 'function') {
367 return progressRun.defer(10, _this);
372 Roo.MessageBox.updateProgress(
373 (total - mods.length)/total, "Building Interface " + (total - mods.length) +
375 (m.name ? (' - ' + m.name) : '')
379 // is the module disabled?
380 var disabled = (typeof(m.disabled) == 'function') ?
381 m.disabled.call(m.module.disabled) : m.disabled;
385 return progressRun(); // we do not update the display!
391 // it's 10 on top level, and 1 on others??? why...
392 return progressRun.defer(10, _this);
395 progressRun.defer(1, _this);