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',
27 * @extends Roo.util.Observable
29 * @param cfg {Object} configuration of component
32 Roo.XComponent = function(cfg) {
37 * Fires when this the componnt is built
38 * @param {Roo.XComponent} c the component
42 * @event buildcomplete
43 * Fires on the top level element when all elements have been built
44 * @param {Roo.XComponent} c the top level component.
46 'buildcomplete' : true,
50 Roo.XComponent.register(this);
52 this.el = false; // where the layout goes..
56 Roo.extend(Roo.XComponent, Roo.util.Observable, {
59 * The created element (with Roo.factory())
66 * for BC - use el in new code
73 * for BC - use el in new code
79 * @cfg {Function|boolean} disabled
80 * If this module is disabled by some rule, return true from the funtion
85 * @cfg {String} parent
86 * Name of parent element which it get xtype added to..
92 * Used to set the order in which elements are created (usefull for multiple tabs)
98 * String to display while loading.
103 * A single item array - the first element is the root of the tree..
104 * It's done this way to stay compatible with the Xtype system...
112 Roo.apply(Roo.XComponent, {
115 * @property buildCompleted
116 * True when the builder has completed building the interface.
119 buildCompleted : false,
122 * @property topModule
123 * the upper most module - uses document.element as it's constructor.
131 * array of modules to be created by registration system.
132 * @type Roo.XComponent
139 * Register components to be built later.
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..
157 * * @param {Object} details about module
159 register : function(obj) {
160 this.modules.push(obj);
164 * convert a string to an object..
168 toObject : function(str)
170 if (!str || typeof(str) == 'object') {
173 var ar = str.split('.');
177 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
179 throw "Module not found : " + str;
181 Roo.each(ar, function(e) {
182 if (typeof(o[e]) == 'undefined') {
183 throw "Module not found : " + str;
193 * move modules into their correct place in the tree..
196 preBuild : function ()
199 Roo.each(this.modules , function (obj)
201 obj.parent = this.toObject(obj.parent);
204 this.topModule = obj;
208 if (!obj.parent.modules) {
209 obj.parent.modules = new Roo.util.MixedCollection(false,
210 function(o) { return o.order + '' }
214 obj.parent.modules.add(obj);
219 * make a list of modules to build.
220 * @return {Array} list of modules.
223 buildOrder : function()
226 var cmp = function(a,b) {
227 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
230 if (!this.topModule || !this.topModule.modules) {
231 throw "No top level modules to build";
234 // make a flat list in order of modules to build.
235 var mods = [ this.topModule ];
238 // add modules to their parents..
239 var addMod = function(m) {
240 // console.log(m.modKey);
244 m.modules.keySort('ASC', cmp );
245 m.modules.each(addMod);
247 // not sure if this is used any more..
249 m.finalize.name = m.name + " (clean up) ";
250 mods.push(m.finalize);
254 this.topModule.modules.keySort('ASC', cmp );
255 this.topModule.modules.each(addMod);
260 * Build the registered modules.
261 * @param {Object} parent element.
262 * @param {Function} optional method to call after module has been added.
270 var mods = this.buildOrder();
272 //this.allmods = mods;
275 if (!mods.length) { // should not happen
276 throw "NO modules!!!";
281 // flash it up as modal - so we store the mask!?
282 Roo.MessageBox.show({ title: 'loading' });
283 Roo.MessageBox.show({
284 title: "Please wait...",
285 msg: "Building Interface...",
292 var total = mods.length;
295 var progressRun = function() {
297 console.log('hide?');
298 Roo.MessageBox.hide();
299 _this.topModule.fireEvent('buildcomplete', _this.topModule);
303 var m = mods.shift();
305 if (typeof(m) == 'function') { // not sure if this is supported any more..
307 return progressRun.defer(10, _this);
310 Roo.MessageBox.updateProgress(
311 (total - mods.length)/total, "Building Interface " + (total - mods.length) +
313 (m.name ? (' - ' + m.name) : '')
318 var disabled = (typeof(m.disabled) == 'function') ?
319 m.disabled.call(m.module.disabled) : m.disabled;
323 return progressRun(); // we do not update the display!
327 // it's a top level one..
328 var layoutbase = new Ext.BorderLayout(document.body, {
336 alwaysShowTabs: true,
341 tree.region = 'center';
342 m.el = layoutbase.addxtype(tree);
344 m.layout = m.panel.layout;
345 return progressRun.defer(10, _this);
349 tree.region = tree.region || m.region;
350 m.el = m.parent.el.addxtype(tree);
351 m.fireEvent('built', m);
353 m.layout = m.panel.layout;
354 progressRun.defer(10, _this);
357 progressRun.defer(1, _this);