2 * Original code for Roojs - LGPL
3 * <script type="text/javascript">
8 * This needs some more thought..
12 * @class Roo.XComponent
13 * @extends Roo.data.Observable
15 * A delayed Element creator...
17 * Mypart.xyx = new Roo.XComponent({
19 parent : 'Mypart.xyz', // empty == document.element.!!
23 disabled : function() {}
29 xtype : 'NestedLayoutPanel',
38 Roo.XComponent = function(cfg) {
43 * Fires when this the componnt is built
44 * @param {Roo.XComponent} c the component
48 * @event buildcomplete
49 * Fires on the top level element when all elements have been built
50 * @param {Roo.XComponent} c the top level component.
52 'buildcomplete' : true,
56 Roo.XComponent.register(this);
58 this.el = false; // where the layout goes..
62 Roo.extend(Roo.XComponent, Roo.util.Observable, {
65 * The created element (with Roo.factory())
72 * for BC - use el in new code
79 * for BC - use el in new code
85 * @cfg {Function|boolean} disabled
86 * If this module is disabled by some rule, return true from the funtion
91 * @cfg {String} parent
92 * Name of parent element which it get xtype added to..
98 * Used to set the order in which elements are created (usefull for multiple tabs)
104 * String to display while loading.
109 * A single item array - the first element is the root of the tree..
110 * It's done this way to stay compatible with the Xtype system...
118 Roo.apply(Roo.XComponent, {
121 * @property buildCompleted
122 * True when the builder has completed building the interface.
125 buildCompleted : false,
128 * @property topModule
129 * the upper most module - uses document.element as it's constructor.
137 * array of modules to be created by registration system.
138 * @type Roo.XComponent
145 * Register components to be built later.
146 * @param {Object} details about module
148 * This solves the following issues
149 * - Building is not done on page load, but after an authentication process has occured.
150 * - Interface elements are registered on page load
151 * - Parent Interface elements may not be loaded before child, so this handles that..
158 module : 'Pman.Tab.projectMgr',
160 parent : 'Pman.layout',
161 disabled : false, // or use a function..
165 register : function(obj) {
166 this.modules.push(obj);
170 * convert a string to an object..
174 toObject : function(str)
176 if (!str || typeof(str) == 'object') {
179 var ar = str.split('.');
183 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
185 throw "Module not found : " + str;
187 Roo.each(ar, function(e) {
188 if (typeof(o[e]) == 'undefined') {
189 throw "Module not found : " + str;
199 * move modules into their correct place in the tree..
202 preBuild : function ()
205 Roo.each(this.modules , function (obj)
207 obj.parent = this.toObject(obj.parent);
210 this.topModule = obj;
214 if (!obj.parent.modules) {
215 obj.parent.modules = new Roo.util.MixedCollection(false,
216 function(o) { return o.order + '' }
220 obj.parent.modules.add(obj);
225 * make a list of modules to build.
226 * @return {Array} list of modules.
229 buildOrder : function()
232 var cmp = function(a,b) {
233 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
236 if (!this.topModule || !this.topModule.modules) {
237 throw "No top level modules to build";
240 // make a flat list in order of modules to build.
241 var mods = [ this.topModule ];
244 // add modules to their parents..
245 var addMod = function(m) {
246 // console.log(m.modKey);
250 m.modules.keySort('ASC', cmp );
251 m.modules.each(addMod);
253 // not sure if this is used any more..
255 m.finalize.name = m.name + " (clean up) ";
256 mods.push(m.finalize);
260 this.topModule.modules.keySort('ASC', cmp );
261 this.topModule.modules.each(addMod);
266 * Build the registered modules.
267 * @param {Object} parent element.
268 * @param {Function} optional method to call after module has been added.
276 var mods = this.buildOrder();
278 //this.allmods = mods;
281 if (!mods.length) { // should not happen
282 throw "NO modules!!!";
287 // flash it up as modal - so we store the mask!?
288 Roo.MessageBox.show({ title: 'loading' });
289 Roo.MessageBox.show({
290 title: "Please wait...",
291 msg: "Building Interface...",
298 var total = mods.length;
301 var progressRun = function() {
303 console.log('hide?');
304 Roo.MessageBox.hide();
305 _this.topModule.fireEvent('buildcomplete', _this.topModule);
309 var m = mods.shift();
311 if (typeof(m) == 'function') { // not sure if this is supported any more..
313 return progressRun.defer(10, _this);
316 Roo.MessageBox.updateProgress(
317 (total - mods.length)/total, "Building Interface " + (total - mods.length) +
319 (m.name ? (' - ' + m.name) : '')
324 var disabled = (typeof(m.disabled) == 'function') ?
325 m.disabled.call(m.module.disabled) : m.disabled;
329 return progressRun(); // we do not update the display!
333 // it's a top level one..
334 var layoutbase = new Ext.BorderLayout(document.body, {
342 alwaysShowTabs: true,
347 m.items[0].region = 'center';
348 m.el = layoutbase.addxtype( m.tree() );
350 m.layout = m.panel.layout;
351 return progressRun.defer(10, _this);
355 m.items[0].region = m.items[0].region || m.region;
356 m.el = m.parent.el.addxtype(m.tree());
357 m.fireEvent('built', m);
359 m.layout = m.panel.layout;
360 progressRun.defer(10, _this);
363 progressRun.defer(1, _this);