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);
56 Roo.extend(Roo.XComponent, Roo.util.Observable {
62 Roo.apply(Roo.XComponent,
64 * @property buildCompleted
65 * True when the builder has completed building the interface.
68 buildCompleted : false,
72 * the upper most module - uses document.element as it's constructor.
80 * array of modules to be created by registration system.
81 * @type Roo.XComponent
88 * Register components to be built later.
89 * @param {Object} details about module
91 * This solves the following issues
92 * - Building is not done on page load, but after an authentication process has occured.
93 * - Interface elements are registered on page load
94 * - Parent Interface elements may not be loaded before child, so this handles that..
101 module : 'Pman.Tab.projectMgr',
103 parent : 'Pman.layout',
104 disabled : false, // or use a function..
108 register : function(obj) {
109 this.modules.push(obj);
113 * convert a string to an object..
117 toObject : function(str)
119 if (typeof(str) == 'object') {
122 var ar = str.split('.');
126 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
128 throw "Module not found : " + str;
130 Roo.each(ar, function(e) {
131 if (typeof(o[e]) == 'undefined') {
132 throw "Module not found : " + str;
142 * move modules into their correct place in the tree..
145 preBuild : function ()
147 var modules = this.modules;
148 this.modules = false;
150 Roo.each(modules , function (obj)
152 obj.parent = this.toObject(obj.parent);
155 this.topModule = obj;
158 obj.parent = toObject(obj.parent);
159 if (!obj.parent.modules) {
160 obj.parent.modules = new Roo.util.MixedCollection(false,
161 function(o) { return o.order + '' }
165 obj.parent.modules.add(obj);
170 * make a list of modules to build.
171 * @return {Array} list of modules.
174 buildOrder : function()
177 var cmp = function(a,b) {
178 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
181 if (!this.topModule || !this.topModule.modules) {
182 throw "No top level modules to build";
185 // make a flat list in order of modules to build.
186 var mods = [ this.topModule ];
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 this.topModule.modules.keySort('ASC', cmp );
205 this.topModule.modules.each(addMod);
209 * Build the registered modules.
210 * @param {Object} parent element.
211 * @param {Function} optional method to call after module has been added.
219 mods = this.buildOrder();
221 //this.allmods = mods;
224 if (!mods.length) { // should not happen
225 throw "NO modules!!!";
227 // flash it up as modal - so we store the mask!?
228 Roo.MessageBox.show({ title: 'loading' });
229 Roo.MessageBox.show({
230 title: "Please wait...",
231 msg: "Building Interface...",
240 var progressRun = function() {
242 if (n >= mods.length) {
243 Roo.MessageBox.hide();
244 _this.topModule.fireEvent('built', _this.topModule);
251 Roo.MessageBox.updateProgress(
252 (n+1)/mods.length, "Building Interface " + (n+1) +
253 " of " + mods.length +
254 (m.name ? (' - ' + m.name) : '')
257 if (typeof(m) == 'function') {
259 progressRun.defer(10, _this);
262 var disabled = (typeof(m.module.disabled) == 'function') ?
263 m.module.disabled.call(m.module.disabled) : m.module.disabled;
267 if (m.parent.layout && !disabled) {
268 // modules have to support a 'add method'
269 // should we just move that code into here..
270 m.module.add(m.parent.layout, m.region);
276 progressRun.defer(1, _this);