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 {
62 * @cfg {Function|boolean} disabled
63 * If this module is disabled by some rule, return true from the funtion
67 * @cfg {String} parent
68 * Name of parent element which it get xtype added to..
73 * Used to set the order in which elements are created (usefull for multiple tabs)
79 * String to display while loading.
84 Roo.apply(Roo.XComponent,
86 * @property buildCompleted
87 * True when the builder has completed building the interface.
90 buildCompleted : false,
94 * the upper most module - uses document.element as it's constructor.
102 * array of modules to be created by registration system.
103 * @type Roo.XComponent
110 * Register components to be built later.
111 * @param {Object} details about module
113 * This solves the following issues
114 * - Building is not done on page load, but after an authentication process has occured.
115 * - Interface elements are registered on page load
116 * - Parent Interface elements may not be loaded before child, so this handles that..
123 module : 'Pman.Tab.projectMgr',
125 parent : 'Pman.layout',
126 disabled : false, // or use a function..
130 register : function(obj) {
131 this.modules.push(obj);
135 * convert a string to an object..
139 toObject : function(str)
141 if (typeof(str) == 'object') {
144 var ar = str.split('.');
148 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
150 throw "Module not found : " + str;
152 Roo.each(ar, function(e) {
153 if (typeof(o[e]) == 'undefined') {
154 throw "Module not found : " + str;
164 * move modules into their correct place in the tree..
167 preBuild : function ()
169 var modules = this.modules;
170 this.modules = false;
172 Roo.each(modules , function (obj)
174 obj.parent = this.toObject(obj.parent);
177 this.topModule = obj;
180 obj.parent = toObject(obj.parent);
181 if (!obj.parent.modules) {
182 obj.parent.modules = new Roo.util.MixedCollection(false,
183 function(o) { return o.order + '' }
187 obj.parent.modules.add(obj);
192 * make a list of modules to build.
193 * @return {Array} list of modules.
196 buildOrder : function()
199 var cmp = function(a,b) {
200 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
203 if (!this.topModule || !this.topModule.modules) {
204 throw "No top level modules to build";
207 // make a flat list in order of modules to build.
208 var mods = [ this.topModule ];
211 // add modules to their parents..
212 var addMod = function(m) {
213 // console.log(m.modKey);
216 if (m.module.modules) {
217 m.module.modules.keySort('ASC', cmp );
218 m.module.modules.each(addMod);
221 m.finalize.name = m.name + " (clean up) ";
222 mods.push(m.finalize);
226 this.topModule.modules.keySort('ASC', cmp );
227 this.topModule.modules.each(addMod);
231 * Build the registered modules.
232 * @param {Object} parent element.
233 * @param {Function} optional method to call after module has been added.
241 var mods = this.buildOrder();
243 //this.allmods = mods;
246 if (!mods.length) { // should not happen
247 throw "NO modules!!!";
252 // flash it up as modal - so we store the mask!?
253 Roo.MessageBox.show({ title: 'loading' });
254 Roo.MessageBox.show({
255 title: "Please wait...",
256 msg: "Building Interface...",
265 var progressRun = function() {
267 if (n >= mods.length) {
268 Roo.MessageBox.hide();
269 _this.topModule.fireEvent('built', _this.topModule);
276 Roo.MessageBox.updateProgress(
277 (n+1)/mods.length, "Building Interface " + (n+1) +
278 " of " + mods.length +
279 (m.name ? (' - ' + m.name) : '')
282 if (typeof(m) == 'function') {
284 progressRun.defer(10, _this);
287 var disabled = (typeof(m.module.disabled) == 'function') ?
288 m.module.disabled.call(m.module.disabled) : m.module.disabled;
292 if (m.parent.layout && !disabled) {
293 // modules have to support a 'add method'
294 // should we just move that code into here..
295 m.module.add(m.parent.layout, m.region);
301 progressRun.defer(1, _this);