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 {
65 Roo.apply(Roo.XComponent,
67 * @property buildCompleted
68 * True when the builder has completed building the interface.
71 buildCompleted : false,
75 * the upper most module - uses document.element as it's constructor.
83 * array of modules to be created by registration system.
84 * @type Roo.XComponent
91 * Register components to be built later.
92 * @param {Object} details about module
94 * This solves the following issues
95 * - Building is not done on page load, but after an authentication process has occured.
96 * - Interface elements are registered on page load
97 * - Parent Interface elements may not be loaded before child, so this handles that..
104 module : 'Pman.Tab.projectMgr',
106 parent : 'Pman.layout',
107 disabled : false, // or use a function..
111 register : function(obj) {
112 this.modules.push(obj);
116 * convert a string to an object..
120 toObject : function(str)
122 if (typeof(str) == 'object') {
125 var ar = str.split('.');
129 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
131 throw "Module not found : " + str;
133 Roo.each(ar, function(e) {
134 if (typeof(o[e]) == 'undefined') {
135 throw "Module not found : " + str;
145 * move modules into their correct place in the tree..
148 preBuild : function ()
150 var modules = this.modules;
151 this.modules = false;
153 Roo.each(modules , function (obj)
155 obj.parent = this.toObject(obj.parent);
158 this.topModule = obj;
161 obj.parent = toObject(obj.parent);
162 if (!obj.parent.modules) {
163 obj.parent.modules = new Roo.util.MixedCollection(false,
164 function(o) { return o.order + '' }
168 obj.parent.modules.add(obj);
173 * make a list of modules to build.
174 * @return {Array} list of modules.
177 buildOrder : function()
180 var cmp = function(a,b) {
181 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
184 if (!this.topModule || !this.topModule.modules) {
185 throw "No top level modules to build";
188 // make a flat list in order of modules to build.
189 var mods = [ this.topModule ];
192 // add modules to their parents..
193 var addMod = function(m) {
194 // console.log(m.modKey);
197 if (m.module.modules) {
198 m.module.modules.keySort('ASC', cmp );
199 m.module.modules.each(addMod);
202 m.finalize.name = m.name + " (clean up) ";
203 mods.push(m.finalize);
207 this.topModule.modules.keySort('ASC', cmp );
208 this.topModule.modules.each(addMod);
212 * Build the registered modules.
213 * @param {Object} parent element.
214 * @param {Function} optional method to call after module has been added.
222 var mods = this.buildOrder();
224 //this.allmods = mods;
227 if (!mods.length) { // should not happen
228 throw "NO modules!!!";
233 // flash it up as modal - so we store the mask!?
234 Roo.MessageBox.show({ title: 'loading' });
235 Roo.MessageBox.show({
236 title: "Please wait...",
237 msg: "Building Interface...",
246 var progressRun = function() {
248 if (n >= mods.length) {
249 Roo.MessageBox.hide();
250 _this.topModule.fireEvent('built', _this.topModule);
257 Roo.MessageBox.updateProgress(
258 (n+1)/mods.length, "Building Interface " + (n+1) +
259 " of " + mods.length +
260 (m.name ? (' - ' + m.name) : '')
263 if (typeof(m) == 'function') {
265 progressRun.defer(10, _this);
268 var disabled = (typeof(m.module.disabled) == 'function') ?
269 m.module.disabled.call(m.module.disabled) : m.module.disabled;
273 if (m.parent.layout && !disabled) {
274 // modules have to support a 'add method'
275 // should we just move that code into here..
276 m.module.add(m.parent.layout, m.region);
282 progressRun.defer(1, _this);