2 * Original code for Roojs - LGPL
3 * <script type="text/javascript">
8 * This needs some more thought..
14 * @class Roo.XComponent
15 * @extends Roo.data.Observable
17 * A delayed Element creator...
19 * Mypart.xyx = new Roo.XComponent({
21 parent : 'Mypart.xyz', // empty == document.element.!!
25 disabled : function() {}
27 items : [ // technically only one component..
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...
115 Roo.apply(Roo.XComponent,
117 * @property buildCompleted
118 * True when the builder has completed building the interface.
121 buildCompleted : false,
124 * @property topModule
125 * the upper most module - uses document.element as it's constructor.
133 * array of modules to be created by registration system.
134 * @type Roo.XComponent
141 * Register components to be built later.
142 * @param {Object} details about module
144 * This solves the following issues
145 * - Building is not done on page load, but after an authentication process has occured.
146 * - Interface elements are registered on page load
147 * - Parent Interface elements may not be loaded before child, so this handles that..
154 module : 'Pman.Tab.projectMgr',
156 parent : 'Pman.layout',
157 disabled : false, // or use a function..
161 register : function(obj) {
162 this.modules.push(obj);
166 * convert a string to an object..
170 toObject : function(str)
172 if (typeof(str) == 'object') {
175 var ar = str.split('.');
179 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
181 throw "Module not found : " + str;
183 Roo.each(ar, function(e) {
184 if (typeof(o[e]) == 'undefined') {
185 throw "Module not found : " + str;
195 * move modules into their correct place in the tree..
198 preBuild : function ()
200 var modules = this.modules;
201 this.modules = false;
203 Roo.each(modules , function (obj)
205 obj.parent = this.toObject(obj.parent);
208 this.topModule = obj;
211 obj.parent = toObject(obj.parent);
212 if (!obj.parent.modules) {
213 obj.parent.modules = new Roo.util.MixedCollection(false,
214 function(o) { return o.order + '' }
218 obj.parent.modules.add(obj);
223 * make a list of modules to build.
224 * @return {Array} list of modules.
227 buildOrder : function()
230 var cmp = function(a,b) {
231 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
234 if (!this.topModule || !this.topModule.modules) {
235 throw "No top level modules to build";
238 // make a flat list in order of modules to build.
239 var mods = [ this.topModule ];
242 // add modules to their parents..
243 var addMod = function(m) {
244 // console.log(m.modKey);
247 if (m.module.modules) {
248 m.module.modules.keySort('ASC', cmp );
249 m.module.modules.each(addMod);
252 m.finalize.name = m.name + " (clean up) ";
253 mods.push(m.finalize);
257 this.topModule.modules.keySort('ASC', cmp );
258 this.topModule.modules.each(addMod);
262 * Build the registered modules.
263 * @param {Object} parent element.
264 * @param {Function} optional method to call after module has been added.
272 var mods = this.buildOrder();
274 //this.allmods = mods;
277 if (!mods.length) { // should not happen
278 throw "NO modules!!!";
283 // flash it up as modal - so we store the mask!?
284 Roo.MessageBox.show({ title: 'loading' });
285 Roo.MessageBox.show({
286 title: "Please wait...",
287 msg: "Building Interface...",
294 var total = mods.length();
297 var progressRun = function() {
299 Roo.MessageBox.hide();
300 _this.topModule.fireEvent('buildcomplete', _this.topModule);
304 var m = mods.unshift();
306 if (typeof(m) == 'function') { // not sure if this is supported any more..
308 return progressRun.defer(10, _this);
311 Roo.MessageBox.updateProgress(
312 (total - mods.length)/total, "Building Interface " + (total - mods.length) +
314 (m.name ? (' - ' + m.name) : '')
319 var disabled = (typeof(m.module.disabled) == 'function') ?
320 m.module.disabled.call(m.module.disabled) : m.module.disabled;
324 return progressRun(); // we do not update the display!
327 m.el = m.parent.el.addxtype(m.items[0]);
328 m.fireEvent('built', m);
330 m.layout = m.panel.layout;
334 progressRun.defer(1, _this);