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())
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..
91 * Used to set the order in which elements are created (usefull for multiple tabs)
97 * String to display while loading.
102 * A single item array - the first element is the root of the tree..
103 * It's done this way to stay compatible with the Xtype system...
108 Roo.apply(Roo.XComponent,
110 * @property buildCompleted
111 * True when the builder has completed building the interface.
114 buildCompleted : false,
117 * @property topModule
118 * the upper most module - uses document.element as it's constructor.
126 * array of modules to be created by registration system.
127 * @type Roo.XComponent
134 * Register components to be built later.
135 * @param {Object} details about module
137 * This solves the following issues
138 * - Building is not done on page load, but after an authentication process has occured.
139 * - Interface elements are registered on page load
140 * - Parent Interface elements may not be loaded before child, so this handles that..
147 module : 'Pman.Tab.projectMgr',
149 parent : 'Pman.layout',
150 disabled : false, // or use a function..
154 register : function(obj) {
155 this.modules.push(obj);
159 * convert a string to an object..
163 toObject : function(str)
165 if (typeof(str) == 'object') {
168 var ar = str.split('.');
172 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
174 throw "Module not found : " + str;
176 Roo.each(ar, function(e) {
177 if (typeof(o[e]) == 'undefined') {
178 throw "Module not found : " + str;
188 * move modules into their correct place in the tree..
191 preBuild : function ()
193 var modules = this.modules;
194 this.modules = false;
196 Roo.each(modules , function (obj)
198 obj.parent = this.toObject(obj.parent);
201 this.topModule = obj;
204 obj.parent = toObject(obj.parent);
205 if (!obj.parent.modules) {
206 obj.parent.modules = new Roo.util.MixedCollection(false,
207 function(o) { return o.order + '' }
211 obj.parent.modules.add(obj);
216 * make a list of modules to build.
217 * @return {Array} list of modules.
220 buildOrder : function()
223 var cmp = function(a,b) {
224 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
227 if (!this.topModule || !this.topModule.modules) {
228 throw "No top level modules to build";
231 // make a flat list in order of modules to build.
232 var mods = [ this.topModule ];
235 // add modules to their parents..
236 var addMod = function(m) {
237 // console.log(m.modKey);
240 if (m.module.modules) {
241 m.module.modules.keySort('ASC', cmp );
242 m.module.modules.each(addMod);
245 m.finalize.name = m.name + " (clean up) ";
246 mods.push(m.finalize);
250 this.topModule.modules.keySort('ASC', cmp );
251 this.topModule.modules.each(addMod);
255 * Build the registered modules.
256 * @param {Object} parent element.
257 * @param {Function} optional method to call after module has been added.
265 var mods = this.buildOrder();
267 //this.allmods = mods;
270 if (!mods.length) { // should not happen
271 throw "NO modules!!!";
276 // flash it up as modal - so we store the mask!?
277 Roo.MessageBox.show({ title: 'loading' });
278 Roo.MessageBox.show({
279 title: "Please wait...",
280 msg: "Building Interface...",
289 var progressRun = function() {
291 if (n >= mods.length) {
292 Roo.MessageBox.hide();
293 _this.topModule.fireEvent('built', _this.topModule);
300 Roo.MessageBox.updateProgress(
301 (n+1)/mods.length, "Building Interface " + (n+1) +
302 " of " + mods.length +
303 (m.name ? (' - ' + m.name) : '')
306 if (typeof(m) == 'function') {
308 progressRun.defer(10, _this);
311 var disabled = (typeof(m.module.disabled) == 'function') ?
312 m.module.disabled.call(m.module.disabled) : m.module.disabled;
316 if (m.parent.layout && !disabled) {
317 // modules have to support a 'add method'
318 // should we just move that code into here..
319 m.module.add(m.parent.layout, m.region);
325 progressRun.defer(1, _this);