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.
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);
111 * convert a string to an object..
115 toObject : function(str)
117 if (typeof(str) == 'object') {
120 var ar = str.split('.');
124 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
126 throw "Module not found : " + str;
128 Roo.each(ar, function(e) {
129 if (typeof(o[e]) == 'undefined') {
130 throw "Module not found : " + str;
140 * move modules into their correct place in the tree..
143 preBuild : function ()
145 var modules = this.modules;
146 this.modules = false;
148 Roo.each(modules , function (obj)
150 obj.parent = this.toObject(obj.parent);
153 this.topModule = obj;
156 obj.parent = toObject(obj.parent);
157 if (!obj.parent.modules) {
158 obj.parent.modules = new Roo.util.MixedCollection(false, function(o) { return o.order + '' });
161 obj.parent.modules.add(obj);
167 * Build the registered modules.
168 * @param {Object} parent element.
169 * @param {Function} optional method to call after module has been added.
173 build : function(onCompleteFn)
175 var onComplete = function () {
177 onCompleteFn.call(this);
179 Roo.MessageBox.hide();
185 var cmp = function(a,b) {
186 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
189 if (!parent.modules) {
193 // make a flat list in order of modules to build.
197 // add modules to their parents..
198 var addMod = function(m) {
199 // console.log(m.modKey);
202 if (m.module.modules) {
203 m.module.modules.keySort('ASC', cmp );
204 m.module.modules.each(addMod);
207 m.finalize.name = m.name + " (clean up) ";
208 mods.push(m.finalize);
212 parent.modules.keySort('ASC', cmp );
213 parent.modules.each(addMod);
214 //this.allmods = mods;
218 return onComplete.call(this);
220 // flash it up as modal - so we store the mask!?
221 Roo.MessageBox.show({ title: 'loading' });
222 Roo.MessageBox.show({
223 title: "Please wait...",
224 msg: "Building Interface...",
233 var progressRun = function() {
235 if (n >= mods.length) {
236 return onComplete.call(this);
242 Roo.MessageBox.updateProgress(
243 (n+1)/mods.length, "Building Interface " + (n+1) +
244 " of " + mods.length +
245 (m.name ? (' - ' + m.name) : '')
248 if (typeof(m) == 'function') {
250 progressRun.defer(10, _this);
253 var disabled = (typeof(m.module.disabled) == 'function') ?
254 m.module.disabled.call(m.module.disabled) : m.module.disabled;
258 if (m.parent.layout && !disabled) {
259 // modules have to support a 'add method'
260 // should we just move that code into here..
261 m.module.add(m.parent.layout, m.region);
267 progressRun.defer(1, _this);