2 * Original code for Roojs - LGPL
3 * <script type="text/javascript">
7 * @class Roo.XComponent
8 * A delayed Element creator...
10 * Mypart.xyx = new Roo.XComponent({
12 parent : 'Mypart.xyz', // empty == document.element.!!
16 disabled : function() {}
18 tree : function() { // return an tree of xtype declared components
22 xtype : 'NestedLayoutPanel',
28 * Roo.onReady(function() {
29 Roo.XComponent.build();
32 * @extends Roo.util.Observable
34 * @param cfg {Object} configuration of component
37 Roo.XComponent = function(cfg) {
42 * Fires when this the componnt is built
43 * @param {Roo.XComponent} c the component
47 * @event buildcomplete
48 * Fires on the top level element when all elements have been built
49 * @param {Roo.XComponent} c the top level component.
51 'buildcomplete' : true
55 Roo.XComponent.register(this);
57 this.el = false; // where the layout goes..
61 Roo.extend(Roo.XComponent, Roo.util.Observable, {
64 * The created element (with Roo.factory())
71 * for BC - use el in new code
78 * for BC - use el in new code
84 * @cfg {Function|boolean} disabled
85 * If this module is disabled by some rule, return true from the funtion
90 * @cfg {String} parent
91 * Name of parent element which it get xtype added to..
97 * Used to set the order in which elements are created (usefull for multiple tabs)
103 * String to display while loading.
108 * A single item array - the first element is the root of the tree..
109 * It's done this way to stay compatible with the Xtype system...
115 Roo.apply(Roo.XComponent, {
118 * @property buildCompleted
119 * True when the builder has completed building the interface.
122 buildCompleted : false,
125 * @property topModule
126 * the upper most module - uses document.element as it's constructor.
134 * array of modules to be created by registration system.
135 * @type Roo.XComponent
142 * Register components to be built later.
144 * This solves the following issues
145 * - Building is not done on page load, but after an authentication process has occured.
146 * - Interface elements are registered on page load
147 * - Parent Interface elements may not be loaded before child, so this handles that..
154 module : 'Pman.Tab.projectMgr',
156 parent : 'Pman.layout',
157 disabled : false, // or use a function..
160 * * @param {Object} details about module
162 register : function(obj) {
163 this.modules.push(obj);
167 * convert a string to an object..
168 * eg. 'AAA.BBB' -> finds AAA.BBB
172 toObject : function(str)
174 if (!str || typeof(str) == 'object') {
180 var ar = str.split('.');
184 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
189 throw "Module not found : " + str;
191 Roo.each(ar, function(e) {
192 if (typeof(o[e]) == 'undefined') {
193 throw "Module not found : " + str;
203 * move modules into their correct place in the tree..
206 preBuild : function ()
209 Roo.each(this.modules , function (obj)
211 obj.parent = this.toObject(obj.parent);
213 if (!obj.parent || typeof(obj.parent) == 'string') {
214 this.topModule = obj;
218 if (!obj.parent.modules) {
219 obj.parent.modules = new Roo.util.MixedCollection(false,
220 function(o) { return o.order + '' }
224 obj.parent.modules.add(obj);
229 * make a list of modules to build.
230 * @return {Array} list of modules.
233 buildOrder : function()
236 var cmp = function(a,b) {
237 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
240 if (!this.topModule || !this.topModule.modules) {
241 throw "No top level modules to build";
244 // make a flat list in order of modules to build.
245 var mods = [ this.topModule ];
248 // add modules to their parents..
249 var addMod = function(m) {
250 // Roo.debug && Roo.log(m.modKey);
254 m.modules.keySort('ASC', cmp );
255 m.modules.each(addMod);
257 // not sure if this is used any more..
259 m.finalize.name = m.name + " (clean up) ";
260 mods.push(m.finalize);
264 this.topModule.modules.keySort('ASC', cmp );
265 this.topModule.modules.each(addMod);
270 * Build the registered modules.
271 * @param {Object} parent element.
272 * @param {Function} optional method to call after module has been added.
280 var mods = this.buildOrder();
282 //this.allmods = mods;
283 //Roo.debug && Roo.log(mods);
285 if (!mods.length) { // should not happen
286 throw "NO modules!!!";
291 // flash it up as modal - so we store the mask!?
292 Roo.MessageBox.show({ title: 'loading' });
293 Roo.MessageBox.show({
294 title: "Please wait...",
295 msg: "Building Interface...",
302 var total = mods.length;
305 var progressRun = function() {
307 Roo.debug && Roo.log('hide?');
308 Roo.MessageBox.hide();
309 _this.topModule.fireEvent('buildcomplete', _this.topModule);
314 var m = mods.shift();
315 Roo.debug && Roo.log(m);
316 if (typeof(m) == 'function') { // not sure if this is supported any more..
318 return progressRun.defer(10, _this);
321 Roo.MessageBox.updateProgress(
322 (total - mods.length)/total, "Building Interface " + (total - mods.length) +
324 (m.name ? (' - ' + m.name) : '')
329 var disabled = (typeof(m.disabled) == 'function') ?
330 m.disabled.call(m.module.disabled) : m.disabled;
334 return progressRun(); // we do not update the display!
337 if (!m.parent || (typeof(m.parent) == 'string' && m.parent[0] == '#')) {
338 // it's a top level one..
339 var ctr = m.parent ? Roo.get(m.parent.substr(1)) : document.body;
341 Roo.log("not rendering module " + m.name + " " + m.parent + " no found");
342 return progressRun.defer(10, _this);
347 var layoutbase = new Ext.BorderLayout(
348 m.parent ? Roo.get(m.parent.substr(1)) : document.body,
356 alwaysShowTabs: true,
361 tree.region = 'center';
362 m.el = layoutbase.addxtype(tree);
364 m.layout = m.panel.layout;
365 return progressRun.defer(10, _this);
369 tree.region = tree.region || m.region;
370 m.el = m.parent.el.addxtype(tree);
371 m.fireEvent('built', m);
373 m.layout = m.panel.layout;
374 return progressRun.defer(10, _this);
377 progressRun.defer(1, _this);