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
56 this.region = this.region || 'center'; // default..
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)
132 var hp = this.parent ? 1 : 0;
134 if (!el && typeof(this.parent) == 'string' && this.parent[0] == '#') {
135 // if parent is a '#.....' string, then let's use that..
136 var ename = this.parent.substr(1)
140 Roo.log("Warning - element can not be found :#" + ename );
148 el = el ? Roo.get(el) : false;
150 // it's a top level one..
152 el : new Roo.BorderLayout(el || document.body, {
160 alwaysShowTabs: el && hp? false : true,
161 hideTabs: el || !hp ? true : false,
170 var tree = this.tree();
171 tree.region = tree.region || this.region;
172 this.el = this.parent.el.addxtype(tree);
173 this.fireEvent('built', this);
175 this.panel = this.el;
176 this.layout = this.panel.layout;
182 Roo.apply(Roo.XComponent, {
185 * @property buildCompleted
186 * True when the builder has completed building the interface.
189 buildCompleted : false,
192 * @property topModule
193 * the upper most module - uses document.element as it's constructor.
201 * array of modules to be created by registration system.
202 * @type {Array} of Roo.XComponent
207 * @property elmodules
208 * array of modules to be created by which use #ID
209 * @type {Array} of Roo.XComponent
216 * Register components to be built later.
218 * This solves the following issues
219 * - Building is not done on page load, but after an authentication process has occured.
220 * - Interface elements are registered on page load
221 * - Parent Interface elements may not be loaded before child, so this handles that..
228 module : 'Pman.Tab.projectMgr',
230 parent : 'Pman.layout',
231 disabled : false, // or use a function..
234 * * @param {Object} details about module
236 register : function(obj) {
237 this.modules.push(obj);
241 * convert a string to an object..
242 * eg. 'AAA.BBB' -> finds AAA.BBB
246 toObject : function(str)
248 if (!str || typeof(str) == 'object') {
255 var ar = str.split('.');
259 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
261 throw "Module not found : " + str;
263 Roo.each(ar, function(e) {
264 if (typeof(o[e]) == 'undefined') {
265 throw "Module not found : " + str;
276 * move modules into their correct place in the tree..
279 preBuild : function ()
282 Roo.each(this.modules , function (obj)
284 var opar = obj.parent;
285 obj.parent = this.toObject(opar);
288 this.topModule = obj;
291 if (typeof(obj.parent) == 'string') {
292 this.elmodules.push(obj);
295 if (obj.parent.constructor != Roo.XComponent) {
296 Roo.log("Object Parent is not instance of XComponent:" + obj.name)
298 if (!obj.parent.modules) {
299 obj.parent.modules = new Roo.util.MixedCollection(false,
300 function(o) { return o.order + '' }
304 obj.parent.modules.add(obj);
309 * make a list of modules to build.
310 * @return {Array} list of modules.
313 buildOrder : function()
316 var cmp = function(a,b) {
317 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
319 if ((!this.topModule || !this.topModule.modules) && !this.elmodules.length) {
320 throw "No top level modules to build";
323 // make a flat list in order of modules to build.
324 var mods = this.topModule ? [ this.topModule ] : [];
325 Roo.each(this.elmodules,function(e) { mods.push(e) });
328 // add modules to their parents..
329 var addMod = function(m) {
330 // Roo.debug && Roo.log(m.modKey);
334 m.modules.keySort('ASC', cmp );
335 m.modules.each(addMod);
337 // not sure if this is used any more..
339 m.finalize.name = m.name + " (clean up) ";
340 mods.push(m.finalize);
344 if (this.topModule) {
345 this.topModule.modules.keySort('ASC', cmp );
346 this.topModule.modules.each(addMod);
352 * Build the registered modules.
353 * @param {Object} parent element.
354 * @param {Function} optional method to call after module has been added.
362 var mods = this.buildOrder();
364 //this.allmods = mods;
365 //Roo.debug && Roo.log(mods);
367 if (!mods.length) { // should not happen
368 throw "NO modules!!!";
373 // flash it up as modal - so we store the mask!?
374 Roo.MessageBox.show({ title: 'loading' });
375 Roo.MessageBox.show({
376 title: "Please wait...",
377 msg: "Building Interface...",
384 var total = mods.length;
387 var progressRun = function() {
389 Roo.debug && Roo.log('hide?');
390 Roo.MessageBox.hide();
391 if (_this.topModule) {
392 _this.topModule.fireEvent('buildcomplete', _this.topModule);
398 var m = mods.shift();
401 Roo.debug && Roo.log(m);
402 // not sure if this is supported any more.. - modules that are are just function
403 if (typeof(m) == 'function') {
405 return progressRun.defer(10, _this);
410 Roo.MessageBox.updateProgress(
411 (total - mods.length)/total, "Building Interface " + (total - mods.length) +
413 (m.name ? (' - ' + m.name) : '')
417 // is the module disabled?
418 var disabled = (typeof(m.disabled) == 'function') ?
419 m.disabled.call(m.module.disabled) : m.disabled;
423 return progressRun(); // we do not update the display!
429 // it's 10 on top level, and 1 on others??? why...
430 return progressRun.defer(10, _this);
433 progressRun.defer(1, _this);