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 * array of modules to be created by registration system.
79 * Register components to be built later.
80 * @param {Object} details about module
82 * This solves the following issues
83 * - Building is not done on page load, but after an authentication process has occured.
84 * - Interface elements are registered on page load
85 * - Parent Interface elements may not be loaded before child, so this handles that..
92 module : 'Pman.Tab.projectMgr',
94 parent : 'Pman.layout',
95 disabled : false, // or use a function..
99 register : function(obj) {
100 this.modules.push(obj);
105 * convert a string to an object..
109 toObject : function(str)
111 if (typeof(str) == 'object') {
114 var ar = str.split('.');
118 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
120 throw "Module not found : " + str;
122 Roo.each(ar, function(e) {
123 if (typeof(o[e]) == 'undefined') {
124 throw "Module not found : " + str;
134 * move modules into their correct place in the tree..
137 preBuild : function ()
139 var modules = this.modules;
140 this.modules = false;
142 Roo.each(modules , function (obj)
145 this.topModule = obj;
148 obj.parent = toObject(obj.parent);
149 if (!obj.parent.modules) {
150 obj.parent.modules = new Roo.util.MixedCollection(false, function(o) { return o.order + '' });
153 obj.parent.modules.add(obj);
159 * Build the registered modules.
160 * @param {Object} parent element.
161 * @param {Function} optional method to call after module has been added.
165 build : function(onCompleteFn)
167 var onComplete = function () {
169 onCompleteFn.call(this);
171 Roo.MessageBox.hide();
177 var cmp = function(a,b) {
178 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
181 if (!parent.modules) {
185 // make a flat list in order of modules to build.
189 // add modules to their parents..
190 var addMod = function(m) {
191 // console.log(m.modKey);
194 if (m.module.modules) {
195 m.module.modules.keySort('ASC', cmp );
196 m.module.modules.each(addMod);
199 m.finalize.name = m.name + " (clean up) ";
200 mods.push(m.finalize);
204 parent.modules.keySort('ASC', cmp );
205 parent.modules.each(addMod);
206 //this.allmods = mods;
210 return onComplete.call(this);
212 // flash it up as modal - so we store the mask!?
213 Roo.MessageBox.show({ title: 'loading' });
214 Roo.MessageBox.show({
215 title: "Please wait...",
216 msg: "Building Interface...",
225 var progressRun = function() {
227 if (n >= mods.length) {
228 return onComplete.call(this);
234 Roo.MessageBox.updateProgress(
235 (n+1)/mods.length, "Building Interface " + (n+1) +
236 " of " + mods.length +
237 (m.name ? (' - ' + m.name) : '')
240 if (typeof(m) == 'function') {
242 progressRun.defer(10, _this);
245 var disabled = (typeof(m.module.disabled) == 'function') ?
246 m.module.disabled.call(m.module.disabled) : m.module.disabled;
250 if (m.parent.layout && !disabled) {
251 // modules have to support a 'add method'
252 // should we just move that code into here..
253 m.module.add(m.parent.layout, m.region);
259 progressRun.defer(1, _this);