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, with parent etc.
31 * or you can just use this to render a single compoent to a dom element
32 * MYPART.render(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.
109 * @cfg {String} region
110 * Region to render component to (defaults to center)
116 * A single item array - the first element is the root of the tree..
117 * It's done this way to stay compatible with the Xtype system...
124 * render element to dom or tree
125 * @param {Roo.Element|String|DomElement} optional render to if parent is not set.
128 render : function(el)
133 if (!el && typeof(m.parent) == 'string' && m.parent[0] == '#') {
134 // if parent is a '#.....' string, then let's use that..
136 el = Roo.get(m.substr(1));
140 el = el ? Roo.get(el) : false;
142 // it's a top level one..
144 el : new Ext.BorderLayout(el || document.body, {
152 alwaysShowTabs: el ? false : true,
153 hideTabs: el ? true : false,
160 var tree = this.tree();
161 tree.region = tree.region || this.region;
162 this.el = this.parent.el.addxtype(tree);
163 this.fireEvent('built', this);
165 this.panel = this.el;
166 this.layout = this.panel.layout;
174 Roo.apply(Roo.XComponent, {
177 * @property buildCompleted
178 * True when the builder has completed building the interface.
181 buildCompleted : false,
184 * @property topModule
185 * the upper most module - uses document.element as it's constructor.
193 * array of modules to be created by registration system.
194 * @type {Array} of Roo.XComponent
199 * @property elmodules
200 * array of modules to be created by which use #ID
201 * @type {Array} of Roo.XComponent
208 * Register components to be built later.
210 * This solves the following issues
211 * - Building is not done on page load, but after an authentication process has occured.
212 * - Interface elements are registered on page load
213 * - Parent Interface elements may not be loaded before child, so this handles that..
220 module : 'Pman.Tab.projectMgr',
222 parent : 'Pman.layout',
223 disabled : false, // or use a function..
226 * * @param {Object} details about module
228 register : function(obj) {
229 this.modules.push(obj);
233 * convert a string to an object..
234 * eg. 'AAA.BBB' -> finds AAA.BBB
238 toObject : function(str)
240 if (!str || typeof(str) == 'object') {
247 var ar = str.split('.');
251 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
253 throw "Module not found : " + str;
255 Roo.each(ar, function(e) {
256 if (typeof(o[e]) == 'undefined') {
257 throw "Module not found : " + str;
267 * move modules into their correct place in the tree..
270 preBuild : function ()
273 Roo.each(this.modules , function (obj)
275 obj.parent = this.toObject(obj.parent);
278 this.topModule = obj;
281 if (typeof(obj.parent) == 'string') {
282 this.elmodules.push(obj);
286 if (!obj.parent.modules) {
287 obj.parent.modules = new Roo.util.MixedCollection(false,
288 function(o) { return o.order + '' }
292 obj.parent.modules.add(obj);
297 * make a list of modules to build.
298 * @return {Array} list of modules.
301 buildOrder : function()
304 var cmp = function(a,b) {
305 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
307 if ((!this.topModule || !this.topModule.modules) && !this.elmodules.length) {
308 throw "No top level modules to build";
311 // make a flat list in order of modules to build.
312 var mods = this.topModule ? [ this.topModule ] : [];
313 Roo.each(this.elmodules,function(e) { mods.push(e) });
316 // add modules to their parents..
317 var addMod = function(m) {
318 // Roo.debug && Roo.log(m.modKey);
322 m.modules.keySort('ASC', cmp );
323 m.modules.each(addMod);
325 // not sure if this is used any more..
327 m.finalize.name = m.name + " (clean up) ";
328 mods.push(m.finalize);
332 if (this.topModule) {
333 this.topModule.modules.keySort('ASC', cmp );
334 this.topModule.modules.each(addMod);
340 * Build the registered modules.
341 * @param {Object} parent element.
342 * @param {Function} optional method to call after module has been added.
350 var mods = this.buildOrder();
352 //this.allmods = mods;
353 //Roo.debug && Roo.log(mods);
355 if (!mods.length) { // should not happen
356 throw "NO modules!!!";
361 // flash it up as modal - so we store the mask!?
362 Roo.MessageBox.show({ title: 'loading' });
363 Roo.MessageBox.show({
364 title: "Please wait...",
365 msg: "Building Interface...",
372 var total = mods.length;
375 var progressRun = function() {
377 Roo.debug && Roo.log('hide?');
378 Roo.MessageBox.hide();
379 if (_this.topModule) {
380 _this.topModule.fireEvent('buildcomplete', _this.topModule);
386 var m = mods.shift();
389 Roo.debug && Roo.log(m);
390 // not sure if this is supported any more.. - modules that are are just function
391 if (typeof(m) == 'function') {
393 return progressRun.defer(10, _this);
398 Roo.MessageBox.updateProgress(
399 (total - mods.length)/total, "Building Interface " + (total - mods.length) +
401 (m.name ? (' - ' + m.name) : '')
405 // is the module disabled?
406 var disabled = (typeof(m.disabled) == 'function') ?
407 m.disabled.call(m.module.disabled) : m.disabled;
411 return progressRun(); // we do not update the display!
417 // it's 10 on top level, and 1 on others??? why...
418 return progressRun.defer(10, _this);
421 progressRun.defer(1, _this);