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);
53 Roo.extend(Roo.XComponent, Roo.util.Observable {
59 Roo.apply(Roo.XComponent,
61 * @property buildCompleted
62 * True when the builder has completed building the interface.
65 buildCompleted : false,
69 * the upper most module - uses document.element as it's constructor.
77 * array of modules to be created by registration system.
78 * @type Roo.XComponent
85 * Register components to be built later.
86 * @param {Object} details about module
88 * This solves the following issues
89 * - Building is not done on page load, but after an authentication process has occured.
90 * - Interface elements are registered on page load
91 * - Parent Interface elements may not be loaded before child, so this handles that..
98 module : 'Pman.Tab.projectMgr',
100 parent : 'Pman.layout',
101 disabled : false, // or use a function..
105 register : function(obj) {
106 this.modules.push(obj);
110 * convert a string to an object..
114 toObject : function(str)
116 if (typeof(str) == 'object') {
119 var ar = str.split('.');
123 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
125 throw "Module not found : " + str;
127 Roo.each(ar, function(e) {
128 if (typeof(o[e]) == 'undefined') {
129 throw "Module not found : " + str;
139 * move modules into their correct place in the tree..
142 preBuild : function ()
144 var modules = this.modules;
145 this.modules = false;
147 Roo.each(modules , function (obj)
149 obj.parent = this.toObject(obj.parent);
152 this.topModule = obj;
155 obj.parent = toObject(obj.parent);
156 if (!obj.parent.modules) {
157 obj.parent.modules = new Roo.util.MixedCollection(false, function(o) { return o.order + '' });
160 obj.parent.modules.add(obj);
166 * Build the registered modules.
167 * @param {Object} parent element.
168 * @param {Function} optional method to call after module has been added.
172 build : function(onCompleteFn)
176 var onComplete = function () {
178 onCompleteFn.call(this);
180 Roo.MessageBox.hide();
186 var cmp = function(a,b) {
187 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
190 if (!parent.modules) {
194 // make a flat list in order of modules to build.
198 // add modules to their parents..
199 var addMod = function(m) {
200 // console.log(m.modKey);
203 if (m.module.modules) {
204 m.module.modules.keySort('ASC', cmp );
205 m.module.modules.each(addMod);
208 m.finalize.name = m.name + " (clean up) ";
209 mods.push(m.finalize);
213 parent.modules.keySort('ASC', cmp );
214 parent.modules.each(addMod);
215 //this.allmods = mods;
218 if (!mods.length) { // should not happen
219 throw "NO modules!!!";
221 // flash it up as modal - so we store the mask!?
222 Roo.MessageBox.show({ title: 'loading' });
223 Roo.MessageBox.show({
224 title: "Please wait...",
225 msg: "Building Interface...",
234 var progressRun = function() {
236 if (n >= mods.length) {
237 _this.topModule.fireEvent('built', _this.topModule);
244 Roo.MessageBox.updateProgress(
245 (n+1)/mods.length, "Building Interface " + (n+1) +
246 " of " + mods.length +
247 (m.name ? (' - ' + m.name) : '')
250 if (typeof(m) == 'function') {
252 progressRun.defer(10, _this);
255 var disabled = (typeof(m.module.disabled) == 'function') ?
256 m.module.disabled.call(m.module.disabled) : m.module.disabled;
260 if (m.parent.layout && !disabled) {
261 // modules have to support a 'add method'
262 // should we just move that code into here..
263 m.module.add(m.parent.layout, m.region);
269 progressRun.defer(1, _this);