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)
133 if (!el && typeof(this.parent) == 'string' && this.parent[0] == '#') {
134 // if parent is a '#.....' string, then let's use that..
135 var ename = this.parent.substr(1)
139 Roo.log("Warning - element can not be found :#" + ename );
145 el = el ? Roo.get(el) : false;
147 // it's a top level one..
149 el : new Roo.BorderLayout(el || document.body, {
157 alwaysShowTabs: el ? false : true,
158 hideTabs: el ? true : false,
167 var tree = this.tree();
168 tree.region = tree.region || this.region;
169 this.el = this.parent.el.addxtype(tree);
170 this.fireEvent('built', this);
172 this.panel = this.el;
173 this.layout = this.panel.layout;
179 Roo.apply(Roo.XComponent, {
182 * @property buildCompleted
183 * True when the builder has completed building the interface.
186 buildCompleted : false,
189 * @property topModule
190 * the upper most module - uses document.element as it's constructor.
198 * array of modules to be created by registration system.
199 * @type {Array} of Roo.XComponent
204 * @property elmodules
205 * array of modules to be created by which use #ID
206 * @type {Array} of Roo.XComponent
213 * Register components to be built later.
215 * This solves the following issues
216 * - Building is not done on page load, but after an authentication process has occured.
217 * - Interface elements are registered on page load
218 * - Parent Interface elements may not be loaded before child, so this handles that..
225 module : 'Pman.Tab.projectMgr',
227 parent : 'Pman.layout',
228 disabled : false, // or use a function..
231 * * @param {Object} details about module
233 register : function(obj) {
234 this.modules.push(obj);
238 * convert a string to an object..
239 * eg. 'AAA.BBB' -> finds AAA.BBB
243 toObject : function(str)
245 if (!str || typeof(str) == 'object') {
252 var ar = str.split('.');
256 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
258 throw "Module not found : " + str;
260 Roo.each(ar, function(e) {
261 if (typeof(o[e]) == 'undefined') {
262 throw "Module not found : " + str;
273 * move modules into their correct place in the tree..
276 preBuild : function ()
279 Roo.each(this.modules , function (obj)
281 var opar = obj.parent;
282 obj.parent = this.toObject(opar);
285 this.topModule = obj;
288 if (typeof(obj.parent) == 'string') {
289 this.elmodules.push(obj);
292 if (obj.parent.constructor != Roo.XComponent) {
293 Roo.log("Object Parent is not instance of XComponent:" + opar)
295 if (!obj.parent.modules) {
296 obj.parent.modules = new Roo.util.MixedCollection(false,
297 function(o) { return o.order + '' }
301 obj.parent.modules.add(obj);
306 * make a list of modules to build.
307 * @return {Array} list of modules.
310 buildOrder : function()
313 var cmp = function(a,b) {
314 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
316 if ((!this.topModule || !this.topModule.modules) && !this.elmodules.length) {
317 throw "No top level modules to build";
320 // make a flat list in order of modules to build.
321 var mods = this.topModule ? [ this.topModule ] : [];
322 Roo.each(this.elmodules,function(e) { mods.push(e) });
325 // add modules to their parents..
326 var addMod = function(m) {
327 // Roo.debug && Roo.log(m.modKey);
331 m.modules.keySort('ASC', cmp );
332 m.modules.each(addMod);
334 // not sure if this is used any more..
336 m.finalize.name = m.name + " (clean up) ";
337 mods.push(m.finalize);
341 if (this.topModule) {
342 this.topModule.modules.keySort('ASC', cmp );
343 this.topModule.modules.each(addMod);
349 * Build the registered modules.
350 * @param {Object} parent element.
351 * @param {Function} optional method to call after module has been added.
359 var mods = this.buildOrder();
361 //this.allmods = mods;
362 //Roo.debug && Roo.log(mods);
364 if (!mods.length) { // should not happen
365 throw "NO modules!!!";
370 // flash it up as modal - so we store the mask!?
371 Roo.MessageBox.show({ title: 'loading' });
372 Roo.MessageBox.show({
373 title: "Please wait...",
374 msg: "Building Interface...",
381 var total = mods.length;
384 var progressRun = function() {
386 Roo.debug && Roo.log('hide?');
387 Roo.MessageBox.hide();
388 if (_this.topModule) {
389 _this.topModule.fireEvent('buildcomplete', _this.topModule);
395 var m = mods.shift();
398 Roo.debug && Roo.log(m);
399 // not sure if this is supported any more.. - modules that are are just function
400 if (typeof(m) == 'function') {
402 return progressRun.defer(10, _this);
407 Roo.MessageBox.updateProgress(
408 (total - mods.length)/total, "Building Interface " + (total - mods.length) +
410 (m.name ? (' - ' + m.name) : '')
414 // is the module disabled?
415 var disabled = (typeof(m.disabled) == 'function') ?
416 m.disabled.call(m.module.disabled) : m.disabled;
420 return progressRun(); // we do not update the display!
426 // it's 10 on top level, and 1 on others??? why...
427 return progressRun.defer(10, _this);
430 progressRun.defer(1, _this);