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 {Button} this
45 * @param {EventObject} e The click event
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())
67 * for BC - use el in new code
75 * for BC - use el in new code
81 * @cfg {Function|boolean} disabled
82 * If this module is disabled by some rule, return true from the funtion
86 * @cfg {String} parent
87 * 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...
109 Roo.apply(Roo.XComponent,
111 * @property buildCompleted
112 * True when the builder has completed building the interface.
115 buildCompleted : false,
118 * @property topModule
119 * the upper most module - uses document.element as it's constructor.
127 * array of modules to be created by registration system.
128 * @type Roo.XComponent
135 * Register components to be built later.
136 * @param {Object} details about module
138 * This solves the following issues
139 * - Building is not done on page load, but after an authentication process has occured.
140 * - Interface elements are registered on page load
141 * - Parent Interface elements may not be loaded before child, so this handles that..
148 module : 'Pman.Tab.projectMgr',
150 parent : 'Pman.layout',
151 disabled : false, // or use a function..
155 register : function(obj) {
156 this.modules.push(obj);
160 * convert a string to an object..
164 toObject : function(str)
166 if (typeof(str) == 'object') {
169 var ar = str.split('.');
173 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
175 throw "Module not found : " + str;
177 Roo.each(ar, function(e) {
178 if (typeof(o[e]) == 'undefined') {
179 throw "Module not found : " + str;
189 * move modules into their correct place in the tree..
192 preBuild : function ()
194 var modules = this.modules;
195 this.modules = false;
197 Roo.each(modules , function (obj)
199 obj.parent = this.toObject(obj.parent);
202 this.topModule = obj;
205 obj.parent = toObject(obj.parent);
206 if (!obj.parent.modules) {
207 obj.parent.modules = new Roo.util.MixedCollection(false,
208 function(o) { return o.order + '' }
212 obj.parent.modules.add(obj);
217 * make a list of modules to build.
218 * @return {Array} list of modules.
221 buildOrder : function()
224 var cmp = function(a,b) {
225 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
228 if (!this.topModule || !this.topModule.modules) {
229 throw "No top level modules to build";
232 // make a flat list in order of modules to build.
233 var mods = [ this.topModule ];
236 // add modules to their parents..
237 var addMod = function(m) {
238 // console.log(m.modKey);
241 if (m.module.modules) {
242 m.module.modules.keySort('ASC', cmp );
243 m.module.modules.each(addMod);
246 m.finalize.name = m.name + " (clean up) ";
247 mods.push(m.finalize);
251 this.topModule.modules.keySort('ASC', cmp );
252 this.topModule.modules.each(addMod);
256 * Build the registered modules.
257 * @param {Object} parent element.
258 * @param {Function} optional method to call after module has been added.
266 var mods = this.buildOrder();
268 //this.allmods = mods;
271 if (!mods.length) { // should not happen
272 throw "NO modules!!!";
277 // flash it up as modal - so we store the mask!?
278 Roo.MessageBox.show({ title: 'loading' });
279 Roo.MessageBox.show({
280 title: "Please wait...",
281 msg: "Building Interface...",
290 var progressRun = function() {
292 if (n >= mods.length) {
293 Roo.MessageBox.hide();
294 _this.topModule.fireEvent('built', _this.topModule);
301 Roo.MessageBox.updateProgress(
302 (n+1)/mods.length, "Building Interface " + (n+1) +
303 " of " + mods.length +
304 (m.name ? (' - ' + m.name) : '')
307 if (typeof(m) == 'function') {
309 progressRun.defer(10, _this);
312 var disabled = (typeof(m.module.disabled) == 'function') ?
313 m.module.disabled.call(m.module.disabled) : m.module.disabled;
317 if (m.parent.layout && !disabled) {
318 // modules have to support a 'add method'
319 // should we just move that code into here..
320 m.module.add(m.parent.layout, m.region);
326 progressRun.defer(1, _this);