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',
29 * @extends Roo.util.Observable
31 Roo.XComponent = function(cfg) {
36 * Fires when this the componnt is built
37 * @param {Roo.XComponent} c the component
41 * @event buildcomplete
42 * Fires on the top level element when all elements have been built
43 * @param {Roo.XComponent} c the top level component.
45 'buildcomplete' : true,
49 Roo.XComponent.register(this);
51 this.el = false; // where the layout goes..
55 Roo.extend(Roo.XComponent, Roo.util.Observable, {
58 * The created element (with Roo.factory())
65 * for BC - use el in new code
72 * for BC - use el in new code
78 * @cfg {Function|boolean} disabled
79 * If this module is disabled by some rule, return true from the funtion
84 * @cfg {String} parent
85 * Name of parent element which it get xtype added to..
91 * Used to set the order in which elements are created (usefull for multiple tabs)
97 * String to display while loading.
102 * A single item array - the first element is the root of the tree..
103 * It's done this way to stay compatible with the Xtype system...
111 Roo.apply(Roo.XComponent, {
114 * @property buildCompleted
115 * True when the builder has completed building the interface.
118 buildCompleted : false,
121 * @property topModule
122 * the upper most module - uses document.element as it's constructor.
130 * array of modules to be created by registration system.
131 * @type Roo.XComponent
138 * Register components to be built later.
139 * @param {Object} details about module
141 * This solves the following issues
142 * - Building is not done on page load, but after an authentication process has occured.
143 * - Interface elements are registered on page load
144 * - Parent Interface elements may not be loaded before child, so this handles that..
151 module : 'Pman.Tab.projectMgr',
153 parent : 'Pman.layout',
154 disabled : false, // or use a function..
158 register : function(obj) {
159 this.modules.push(obj);
163 * convert a string to an object..
167 toObject : function(str)
169 if (!str || typeof(str) == 'object') {
172 var ar = str.split('.');
176 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
178 throw "Module not found : " + str;
180 Roo.each(ar, function(e) {
181 if (typeof(o[e]) == 'undefined') {
182 throw "Module not found : " + str;
192 * move modules into their correct place in the tree..
195 preBuild : function ()
198 Roo.each(this.modules , function (obj)
200 obj.parent = this.toObject(obj.parent);
203 this.topModule = obj;
207 if (!obj.parent.modules) {
208 obj.parent.modules = new Roo.util.MixedCollection(false,
209 function(o) { return o.order + '' }
213 obj.parent.modules.add(obj);
218 * make a list of modules to build.
219 * @return {Array} list of modules.
222 buildOrder : function()
225 var cmp = function(a,b) {
226 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
229 if (!this.topModule || !this.topModule.modules) {
230 throw "No top level modules to build";
233 // make a flat list in order of modules to build.
234 var mods = [ this.topModule ];
237 // add modules to their parents..
238 var addMod = function(m) {
239 // console.log(m.modKey);
243 m.modules.keySort('ASC', cmp );
244 m.modules.each(addMod);
246 // not sure if this is used any more..
248 m.finalize.name = m.name + " (clean up) ";
249 mods.push(m.finalize);
253 this.topModule.modules.keySort('ASC', cmp );
254 this.topModule.modules.each(addMod);
259 * Build the registered modules.
260 * @param {Object} parent element.
261 * @param {Function} optional method to call after module has been added.
269 var mods = this.buildOrder();
271 //this.allmods = mods;
274 if (!mods.length) { // should not happen
275 throw "NO modules!!!";
280 // flash it up as modal - so we store the mask!?
281 Roo.MessageBox.show({ title: 'loading' });
282 Roo.MessageBox.show({
283 title: "Please wait...",
284 msg: "Building Interface...",
291 var total = mods.length;
294 var progressRun = function() {
296 console.log('hide?');
297 Roo.MessageBox.hide();
298 _this.topModule.fireEvent('buildcomplete', _this.topModule);
302 var m = mods.shift();
304 if (typeof(m) == 'function') { // not sure if this is supported any more..
306 return progressRun.defer(10, _this);
309 Roo.MessageBox.updateProgress(
310 (total - mods.length)/total, "Building Interface " + (total - mods.length) +
312 (m.name ? (' - ' + m.name) : '')
317 var disabled = (typeof(m.disabled) == 'function') ?
318 m.disabled.call(m.module.disabled) : m.disabled;
322 return progressRun(); // we do not update the display!
326 // it's a top level one..
327 var layoutbase = new Ext.BorderLayout(document.body, {
335 alwaysShowTabs: true,
340 tree.region = 'center';
341 m.el = layoutbase.addxtype(tree);
343 m.layout = m.panel.layout;
344 return progressRun.defer(10, _this);
348 tree.region = tree.region || m.region;
349 m.el = m.parent.el.addxtype(tree);
350 m.fireEvent('built', m);
352 m.layout = m.panel.layout;
353 progressRun.defer(10, _this);
356 progressRun.defer(1, _this);