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;
272 * move modules into their correct place in the tree..
275 preBuild : function ()
278 Roo.each(this.modules , function (obj)
280 obj.parent = this.toObject(obj.parent);
283 this.topModule = obj;
286 if (typeof(obj.parent) == 'string') {
287 this.elmodules.push(obj);
291 if (!obj.parent.modules) {
292 obj.parent.modules = new Roo.util.MixedCollection(false,
293 function(o) { return o.order + '' }
297 obj.parent.modules.add(obj);
302 * make a list of modules to build.
303 * @return {Array} list of modules.
306 buildOrder : function()
309 var cmp = function(a,b) {
310 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
312 if ((!this.topModule || !this.topModule.modules) && !this.elmodules.length) {
313 throw "No top level modules to build";
316 // make a flat list in order of modules to build.
317 var mods = this.topModule ? [ this.topModule ] : [];
318 Roo.each(this.elmodules,function(e) { mods.push(e) });
321 // add modules to their parents..
322 var addMod = function(m) {
323 // Roo.debug && Roo.log(m.modKey);
327 m.modules.keySort('ASC', cmp );
328 m.modules.each(addMod);
330 // not sure if this is used any more..
332 m.finalize.name = m.name + " (clean up) ";
333 mods.push(m.finalize);
337 if (this.topModule) {
338 this.topModule.modules.keySort('ASC', cmp );
339 this.topModule.modules.each(addMod);
345 * Build the registered modules.
346 * @param {Object} parent element.
347 * @param {Function} optional method to call after module has been added.
355 var mods = this.buildOrder();
357 //this.allmods = mods;
358 //Roo.debug && Roo.log(mods);
360 if (!mods.length) { // should not happen
361 throw "NO modules!!!";
366 // flash it up as modal - so we store the mask!?
367 Roo.MessageBox.show({ title: 'loading' });
368 Roo.MessageBox.show({
369 title: "Please wait...",
370 msg: "Building Interface...",
377 var total = mods.length;
380 var progressRun = function() {
382 Roo.debug && Roo.log('hide?');
383 Roo.MessageBox.hide();
384 if (_this.topModule) {
385 _this.topModule.fireEvent('buildcomplete', _this.topModule);
391 var m = mods.shift();
394 Roo.debug && Roo.log(m);
395 // not sure if this is supported any more.. - modules that are are just function
396 if (typeof(m) == 'function') {
398 return progressRun.defer(10, _this);
403 Roo.MessageBox.updateProgress(
404 (total - mods.length)/total, "Building Interface " + (total - mods.length) +
406 (m.name ? (' - ' + m.name) : '')
410 // is the module disabled?
411 var disabled = (typeof(m.disabled) == 'function') ?
412 m.disabled.call(m.module.disabled) : m.disabled;
416 return progressRun(); // we do not update the display!
422 // it's 10 on top level, and 1 on others??? why...
423 return progressRun.defer(10, _this);
426 progressRun.defer(1, _this);