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 {
59 * The created element (with Roo.factory())
70 * for BC - use el in new code
76 * @cfg {Function|boolean} disabled
77 * If this module is disabled by some rule, return true from the funtion
81 * @cfg {String} parent
82 * Name of parent element which it get xtype added to..
87 * Used to set the order in which elements are created (usefull for multiple tabs)
93 * String to display while loading.
98 * A single item array - the first element is the root of the tree..
99 * It's done this way to stay compatible with the Xtype system...
104 Roo.apply(Roo.XComponent,
106 * @property buildCompleted
107 * True when the builder has completed building the interface.
110 buildCompleted : false,
113 * @property topModule
114 * the upper most module - uses document.element as it's constructor.
122 * array of modules to be created by registration system.
123 * @type Roo.XComponent
130 * Register components to be built later.
131 * @param {Object} details about module
133 * This solves the following issues
134 * - Building is not done on page load, but after an authentication process has occured.
135 * - Interface elements are registered on page load
136 * - Parent Interface elements may not be loaded before child, so this handles that..
143 module : 'Pman.Tab.projectMgr',
145 parent : 'Pman.layout',
146 disabled : false, // or use a function..
150 register : function(obj) {
151 this.modules.push(obj);
155 * convert a string to an object..
159 toObject : function(str)
161 if (typeof(str) == 'object') {
164 var ar = str.split('.');
168 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
170 throw "Module not found : " + str;
172 Roo.each(ar, function(e) {
173 if (typeof(o[e]) == 'undefined') {
174 throw "Module not found : " + str;
184 * move modules into their correct place in the tree..
187 preBuild : function ()
189 var modules = this.modules;
190 this.modules = false;
192 Roo.each(modules , function (obj)
194 obj.parent = this.toObject(obj.parent);
197 this.topModule = obj;
200 obj.parent = toObject(obj.parent);
201 if (!obj.parent.modules) {
202 obj.parent.modules = new Roo.util.MixedCollection(false,
203 function(o) { return o.order + '' }
207 obj.parent.modules.add(obj);
212 * make a list of modules to build.
213 * @return {Array} list of modules.
216 buildOrder : function()
219 var cmp = function(a,b) {
220 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
223 if (!this.topModule || !this.topModule.modules) {
224 throw "No top level modules to build";
227 // make a flat list in order of modules to build.
228 var mods = [ this.topModule ];
231 // add modules to their parents..
232 var addMod = function(m) {
233 // console.log(m.modKey);
236 if (m.module.modules) {
237 m.module.modules.keySort('ASC', cmp );
238 m.module.modules.each(addMod);
241 m.finalize.name = m.name + " (clean up) ";
242 mods.push(m.finalize);
246 this.topModule.modules.keySort('ASC', cmp );
247 this.topModule.modules.each(addMod);
251 * Build the registered modules.
252 * @param {Object} parent element.
253 * @param {Function} optional method to call after module has been added.
261 var mods = this.buildOrder();
263 //this.allmods = mods;
266 if (!mods.length) { // should not happen
267 throw "NO modules!!!";
272 // flash it up as modal - so we store the mask!?
273 Roo.MessageBox.show({ title: 'loading' });
274 Roo.MessageBox.show({
275 title: "Please wait...",
276 msg: "Building Interface...",
285 var progressRun = function() {
287 if (n >= mods.length) {
288 Roo.MessageBox.hide();
289 _this.topModule.fireEvent('built', _this.topModule);
296 Roo.MessageBox.updateProgress(
297 (n+1)/mods.length, "Building Interface " + (n+1) +
298 " of " + mods.length +
299 (m.name ? (' - ' + m.name) : '')
302 if (typeof(m) == 'function') {
304 progressRun.defer(10, _this);
307 var disabled = (typeof(m.module.disabled) == 'function') ?
308 m.module.disabled.call(m.module.disabled) : m.module.disabled;
312 if (m.parent.layout && !disabled) {
313 // modules have to support a 'add method'
314 // should we just move that code into here..
315 m.module.add(m.parent.layout, m.region);
321 progressRun.defer(1, _this);