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...
110 Roo.apply(Roo.XComponent, {
113 * @property buildCompleted
114 * True when the builder has completed building the interface.
117 buildCompleted : false,
120 * @property topModule
121 * the upper most module - uses document.element as it's constructor.
129 * array of modules to be created by registration system.
130 * @type Roo.XComponent
137 * Register components to be built later.
139 * This solves the following issues
140 * - Building is not done on page load, but after an authentication process has occured.
141 * - Interface elements are registered on page load
142 * - Parent Interface elements may not be loaded before child, so this handles that..
149 module : 'Pman.Tab.projectMgr',
151 parent : 'Pman.layout',
152 disabled : false, // or use a function..
155 * * @param {Object} details about module
157 register : function(obj) {
158 this.modules.push(obj);
162 * convert a string to an object..
163 * eg. 'AAA.BBB' -> finds AAA.BBB
167 toObject : function(str)
169 if (!str || typeof(str) == 'object') {
175 var ar = str.split('.');
179 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
184 throw "Module not found : " + str;
186 Roo.each(ar, function(e) {
187 if (typeof(o[e]) == 'undefined') {
188 throw "Module not found : " + str;
198 * move modules into their correct place in the tree..
201 preBuild : function ()
204 Roo.each(this.modules , function (obj)
206 obj.parent = this.toObject(obj.parent);
209 this.topModule = obj;
213 if (!obj.parent.modules) {
214 obj.parent.modules = new Roo.util.MixedCollection(false,
215 function(o) { return o.order + '' }
219 obj.parent.modules.add(obj);
224 * make a list of modules to build.
225 * @return {Array} list of modules.
228 buildOrder : function()
231 var cmp = function(a,b) {
232 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
235 if (!this.topModule || !this.topModule.modules) {
236 throw "No top level modules to build";
239 // make a flat list in order of modules to build.
240 var mods = [ this.topModule ];
243 // add modules to their parents..
244 var addMod = function(m) {
245 // Roo.debug && Roo.log(m.modKey);
249 m.modules.keySort('ASC', cmp );
250 m.modules.each(addMod);
252 // not sure if this is used any more..
254 m.finalize.name = m.name + " (clean up) ";
255 mods.push(m.finalize);
259 this.topModule.modules.keySort('ASC', cmp );
260 this.topModule.modules.each(addMod);
265 * Build the registered modules.
266 * @param {Object} parent element.
267 * @param {Function} optional method to call after module has been added.
275 var mods = this.buildOrder();
277 //this.allmods = mods;
278 //Roo.debug && Roo.log(mods);
280 if (!mods.length) { // should not happen
281 throw "NO modules!!!";
286 // flash it up as modal - so we store the mask!?
287 Roo.MessageBox.show({ title: 'loading' });
288 Roo.MessageBox.show({
289 title: "Please wait...",
290 msg: "Building Interface...",
297 var total = mods.length;
300 var progressRun = function() {
302 Roo.debug && Roo.log('hide?');
303 Roo.MessageBox.hide();
304 _this.topModule.fireEvent('buildcomplete', _this.topModule);
308 var m = mods.shift();
309 Roo.debug && Roo.log(m);
310 if (typeof(m) == 'function') { // not sure if this is supported any more..
312 return progressRun.defer(10, _this);
315 Roo.MessageBox.updateProgress(
316 (total - mods.length)/total, "Building Interface " + (total - mods.length) +
318 (m.name ? (' - ' + m.name) : '')
323 var disabled = (typeof(m.disabled) == 'function') ?
324 m.disabled.call(m.module.disabled) : m.disabled;
328 return progressRun(); // we do not update the display!
331 if (!m.parent || (typeof(m.parent) == 'string' && m.parent[0] == '#')) {
332 // it's a top level one..
333 var ctr = m.parent ? Roo.get(m.parent.substr(1)) : document.body;
335 Roo.log("not rendering module " + m.name + " " + m.parent " no found");
341 var layoutbase = new Ext.BorderLayout(
342 m.parent ? Roo.get(m.parent.substr(1)) : document.body,
350 alwaysShowTabs: true,
355 tree.region = 'center';
356 m.el = layoutbase.addxtype(tree);
358 m.layout = m.panel.layout;
359 return progressRun.defer(10, _this);
363 tree.region = tree.region || m.region;
364 m.el = m.parent.el.addxtype(tree);
365 m.fireEvent('built', m);
367 m.layout = m.panel.layout;
368 progressRun.defer(10, _this);
371 progressRun.defer(1, _this);