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() {}
25 items : [ // technically only one component..
27 xtype : 'NestedLayoutPanel',
36 Roo.XComponent = function(cfg) {
41 * Fires when this the componnt is built
42 * @param {Roo.XComponent} c the component
46 * @event buildcomplete
47 * Fires on the top level element when all elements have been built
48 * @param {Roo.XComponent} c the top level component.
50 'buildcomplete' : true
54 Roo.XComponent.register(this);
56 this.el = false; // where the layout goes..
60 Roo.extend(Roo.XComponent, Roo.util.Observable {
63 * The created element (with Roo.factory())
70 * for BC - use el in new code
77 * for BC - use el in new code
83 * @cfg {Function|boolean} disabled
84 * If this module is disabled by some rule, return true from the funtion
89 * @cfg {String} parent
90 * Name of parent element which it get xtype added to..
96 * Used to set the order in which elements are created (usefull for multiple tabs)
102 * String to display while loading.
107 * A single item array - the first element is the root of the tree..
108 * It's done this way to stay compatible with the Xtype system...
113 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.
140 * @param {Object} details about module
142 * This solves the following issues
143 * - Building is not done on page load, but after an authentication process has occured.
144 * - Interface elements are registered on page load
145 * - Parent Interface elements may not be loaded before child, so this handles that..
152 module : 'Pman.Tab.projectMgr',
154 parent : 'Pman.layout',
155 disabled : false, // or use a function..
159 register : function(obj) {
160 this.modules.push(obj);
164 * convert a string to an object..
168 toObject : function(str)
170 if (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 ()
198 var modules = this.modules;
199 this.modules = false;
201 Roo.each(modules , function (obj)
203 obj.parent = this.toObject(obj.parent);
206 this.topModule = obj;
209 obj.parent = toObject(obj.parent);
210 if (!obj.parent.modules) {
211 obj.parent.modules = new Roo.util.MixedCollection(false,
212 function(o) { return o.order + '' }
216 obj.parent.modules.add(obj);
221 * make a list of modules to build.
222 * @return {Array} list of modules.
225 buildOrder : function()
228 var cmp = function(a,b) {
229 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
232 if (!this.topModule || !this.topModule.modules) {
233 throw "No top level modules to build";
236 // make a flat list in order of modules to build.
237 var mods = [ this.topModule ];
240 // add modules to their parents..
241 var addMod = function(m) {
242 // console.log(m.modKey);
245 if (m.module.modules) {
246 m.module.modules.keySort('ASC', cmp );
247 m.module.modules.each(addMod);
250 m.finalize.name = m.name + " (clean up) ";
251 mods.push(m.finalize);
255 this.topModule.modules.keySort('ASC', cmp );
256 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 Roo.MessageBox.hide();
298 _this.topModule.fireEvent('buildcomplete', _this.topModule);
302 var m = mods.unshift();
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.module.disabled) == 'function') ?
318 m.module.disabled.call(m.module.disabled) : m.module.disabled;
322 return progressRun(); // we do not update the display!
325 m.el = m.parent.el.addxtype(m.items[0]);
326 m.fireEvent('built', m);
328 m.layout = m.panel.layout;
332 progressRun.defer(1, _this);