roojs-core.js
[roojs1] / Roo / Document.js
index 9975928..c1122ec 100644 (file)
 /*
- * Original code for Roojs - LGPL
- * <script type="text/javascript">
+ * RooJS Library 
+ * Copyright(c) 2007-2017, Roo J Solutions Ltd
+ *
+ * Licence LGPL 
+ *
  */
  
 /**
+ * @class Roo.Document
+ * @extends Roo.util.Observable
+ * This is a convience class to wrap up the main document loading code.. , rather than adding Roo.onReady(......)
  * 
- * This needs some more thought..
- * 
- * compontent is taken..
- * 
- *
- * 
- * 
- * 
+ * @param {Object} config the methods and properties of the 'base' class for the application.
  * 
- * @class Roo.XComponent
- * @extends Roo.data.Observable
+ *  Generic Page handler - implement this to start your app..
  * 
- * A delayed Element creator...
- * 
- * Mypart.xyx = new Roo.XComponent({
-
-    parent : 'Mypart.xyz', // empty == document.element.!!
-    order : '001',
-    name : 'xxxx'
-    region : 'xxxx'
-    disabled : function() {} 
-     
-    items : [  // technically only one component..
-        {
-            xtype : 'NestedLayoutPanel',
-            // technicall
+ * eg.
+ *  MyProject = new Roo.Document({
+        events : {
+            'load' : true // your events..
+        },
+        listeners : {
+            'ready' : function() {
+                // fired on Roo.onReady()
+            }
         }
-     ]
- *})
- * 
- * 
  * 
  */
-Roo.XComponent = function(cfg) {
-    Roo.apply(this, cfg);
-    Roo.XComponent.register(this);
-    
-}
-Roo.extend(Roo.XComponent, Roo.util.Observable);
-
-Roo.apply(Roo.XComponent, 
-    /**
-     * @property  buildCompleted
-     * True when the builder has completed building the interface.
-     * @type Boolean
-     */
-    buildCompleted : false,
+Roo.Document = function(cfg) {
      
-    /**
-     * @property  modules
-     * array of modules to be created by registration system.
-     * @type Array
-     */
+    this.addEvents({ 
+        'ready' : true
+    });
+    Roo.util.Observable.call(this,cfg);
     
-    modules : [],
-      
-   
+    var _this = this;
     
-    
-    /**
-     * Register components to be built later.
-     * @param {Object} details about module
-     *
-     * This solves the following issues
-     * - Building is not done on page load, but after an authentication process has occured.
-     * - Interface elements are registered on page load
-     * - Parent Interface elements may not be loaded before child, so this handles that..
-     * 
-     *
-     * example:
-     * 
-     * MyApp.register({
-          order : '000001',
-          module : 'Pman.Tab.projectMgr',
-          region : 'center',
-          parent : 'Pman.layout',
-          disabled : false,  // or use a function..
-        })
-     * 
-     */
-    register : function(obj) {
-        this.modules.push(obj);
-        
-        
-    },
-    /**
-     * convert a string to an object..
-     * 
-     */
-    
-    toObject : function(str)
-    {
-        if (typeof(str) == 'object') {
-            return str;
-        }
-        var ar = str.split('.');
-        var rt, o;
-        rt = ar.unshift();
-            /** eval:var:o */
-        eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
-        if (o === false) {
-            throw "Module not found : " + str;
-        }
-        Roo.each(ar, function(e) {
-            if (typeof(o[e]) == 'undefined') {
-                throw "Module not found : " + str;
-            }
-            o = o[e];
-        });
-        return o;
-        
-    }
+    Roo.onReady(function() {
+        _this.fireEvent('ready');
+    },null,false);
     
     
-    /**
-     * move modules into their correct place in the tree..
-     * 
-     */
-    preBuild : function ()
-    {
-        var modules = this.modules;
-        this.modules = false;
-        
-     
-        Roo.each(modules , function (obj)
-        {
-            
-            obj.parent = toObject(obj.parent);
-             
-            if (!obj.parent.modules) {
-                obj.parent.modules = new Roo.util.MixedCollection(false, function(o) { return o.order + '' });
-            }
-            
-            obj.parent.modules.add(obj);
-        }
-    }
-    
-    
-     /**
-     * Build the registered modules.
-     * @param {Object} parent element.
-     * @param {Function} optional method to call after module has been added.
-     * 
-     */ 
-   
-    build : function(parent, onCompleteFn) 
-    {
-        var onComplete = function () {
-            if (onCompleteFn) {
-                onCompleteFn.call(this);
-            }
-            Roo.MessageBox.hide();
-            
-        
-            
-        }
-        var _this = this;
-        var cmp = function(a,b) {   
-            return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
-        };
-        
-        if (!parent.modules) {
-            return;
-        }
-       
-        // make a flat list in order of modules to build.
-        var mods = [];
-        
-        
-        // add modules to their parents..
-        var addMod = function(m) {
-           // console.log(m.modKey);
-            
-            mods.push(m);
-            if (m.module.modules) {
-                m.module.modules.keySort('ASC',  cmp );
-                m.module.modules.each(addMod);
-            }
-            if (m.finalize) {
-                m.finalize.name = m.name + " (clean up) ";
-                mods.push(m.finalize);
-            }
-            
-        }
-        parent.modules.keySort('ASC',  cmp );
-        parent.modules.each(addMod);
-        //this.allmods = mods;
-        //console.log(mods);
-        //return;
-        if (!mods.length) {
-            return onComplete.call(this);
-        }
-        // flash it up as modal - so we store the mask!?
-        Roo.MessageBox.show({ title: 'loading' });
-        Roo.MessageBox.show({
-           title: "Please wait...",
-           msg: "Building Interface...",
-           width:450,
-           progress:true,
-           closable:false,
-           modal: false
-          
-        });
-        var n = -1;
-        var _this = this;
-        var progressRun = function() {
-            n++;
-            if (n >= mods.length) {
-                return onComplete.call(this);
-            }
-            
-            var m = mods[n];
-            
-            
-            Roo.MessageBox.updateProgress(
-                (n+1)/mods.length,  "Building Interface " + (n+1) + 
-                    " of " + mods.length + 
-                    (m.name ? (' - ' + m.name) : '')
-                    );
-            
-            if (typeof(m) == 'function') {
-                m.call(this);
-                progressRun.defer(10, _this);    
-                return;
-            } 
-            var disabled = (typeof(m.module.disabled) == 'function') ?
-                m.module.disabled.call(m.module.disabled) : m.module.disabled;
-                
-            }
-            
-            if (m.parent.layout && !disabled) {
-                // modules have to support a  'add method'
-                // should we just move that code into here..
-                m.module.add(m.parent.layout, m.region);    
-            }
-                 
-             
-            
-        }
-        progressRun.defer(1, _this);
-     
-        
-        
-    }
-     
-   
-    
-    
-});
\ No newline at end of file
+}
+
+Roo.extend(Roo.Document, Roo.util.Observable, {});
\ No newline at end of file