[qo-modules-dev] [35] Clean up of RemoteLoader.

[ Thread Index | Date Index | More lists.tuxfamily.org/qo-modules-dev Archives ]


Revision: 35
Author:   mjlecomte
Date:     2008-12-02 18:22:48 +0100 (Tue, 02 Dec 2008)

Log Message:
-----------
Clean up of RemoteLoader.  A little more clean up still needed to be able to handle loading multiple files simultaneously (handling any dependencies, etc.).  At the moment would need to package the response of files required on the server and send them back as one package.

Modified Paths:
--------------
    mickael/trunk/ext/v3.0.0-a1/examples/toolbar/overflow.html
    mickael/trunk/ext/v3.0.0-a1/examples/toolbar/overflow.js
    mickael/trunk/ext/v3.0.0-a1/learn/desktop/controller.js
    mickael/trunk/ext/v3.0.0-a1/learn/desktop/desktop.html
    mickael/trunk/ext/v3.0.0-a1/learn/desktop/js/Desktop.js
    mickael/trunk/ext/v3.0.0-a1/learn/desktop/js/RemoteLoader.js


Modified: mickael/trunk/ext/v3.0.0-a1/examples/toolbar/overflow.html
===================================================================
--- mickael/trunk/ext/v3.0.0-a1/examples/toolbar/overflow.html	2008-12-02 03:50:32 UTC (rev 34)
+++ mickael/trunk/ext/v3.0.0-a1/examples/toolbar/overflow.html	2008-12-02 17:22:48 UTC (rev 35)
@@ -9,7 +9,7 @@
     <script type="text/javascript" src="../../adapter/ext/ext-base.js"></script>
     <!-- ENDLIBS -->
 
-    <script type="text/javascript" src="../../ext-all.js"></script>
+    <script type="text/javascript" src="../../ext-all-detail.js"></script>
 
     <script type="text/javascript" src="overflow.js"></script>
     <link rel="stylesheet" type="text/css" href="toolbars.css"/>

Modified: mickael/trunk/ext/v3.0.0-a1/examples/toolbar/overflow.js
===================================================================
--- mickael/trunk/ext/v3.0.0-a1/examples/toolbar/overflow.js	2008-12-02 03:50:32 UTC (rev 34)
+++ mickael/trunk/ext/v3.0.0-a1/examples/toolbar/overflow.js	2008-12-02 17:22:48 UTC (rev 35)
@@ -29,15 +29,15 @@
             iconCls: 'add16',
             handler: handleAction.createCallback('Copy')
         },{
-            text: 'Paste',
+//            text: 'Paste',
             iconCls: 'add16',
             menu: [{text: 'Paste menu', handler: handleAction.createCallback('Paste menu')}]
         },'-',{
-            text: 'Format',
+//            text: 'Format',
             iconCls: 'add16',
             handler: handleAction.createCallback('Format')
         },'->',{
-            text: 'Right',
+//            text: 'Right',
             iconCls: 'add16',
             handler: handleAction.createCallback('Right')
         }]

Modified: mickael/trunk/ext/v3.0.0-a1/learn/desktop/controller.js
===================================================================
--- mickael/trunk/ext/v3.0.0-a1/learn/desktop/controller.js	2008-12-02 03:50:32 UTC (rev 34)
+++ mickael/trunk/ext/v3.0.0-a1/learn/desktop/controller.js	2008-12-02 17:22:48 UTC (rev 35)
@@ -38,12 +38,12 @@
     remoteLoad: true,
     
     /**
-     * @cfg {String} onFileLoad
+     * @cfg {String} processRemoteFile
      * the method used to include remotely loaded javascript resources ('eval' or 'head').
      * 'eval' will eval the remote resource upon retrieval, 'head' will include that
      * source into the head element of the page.
      */        
-    onFileLoad: 'head',//'head' or 'eval'
+    processRemoteFile: 'head',//'head' or 'eval'
     
     urlConnect: 'connect.php',
 
@@ -68,33 +68,50 @@
     },
 
     /**
-     * getPlatform is an interface method that has two requirements:
+     * getPlatform is an interface method that has one requirement:
      * 1. set this.platformLoaded = true;
-     * 2. set this.modules (an array of module config objects)
      * Can optionally specify additional platform configs, but the
-     * app will not do anything without the above 2 requirements satisfied.
+     * app will not do anything without the above requirement satisfied.
+     * 
+     * getPlatform implementation Example 1:
+     * Illustrates loading resources from backend
      */
     getPlatform: function () {
-        this.loadPlatform();
-    },
-
-    /**
-     * loadPlatform implementation example 1.
-     */
-    loadPlatform: function () {
         Ext.ux.RemoteLoader.load({
+            callback: this.handlePlatform,
             url:    this.urlLoad,
             root:   'platform',
             params: this.paramsLoad,
             scope:  this
         });
-    }
+    },
 
     /**
-     * loadPlatform implementation example 2.
+     * Handle the response from the server from the load platform request
+     * @param {Object} o The decoded response object
+     * @param {Object} conn Parameters from the connection request
      */
+    handlePlatform: function (o, conn) {
+        // TODO: refactor to use events so can more easily
+        // do things like notification messages, etc.
+        this.platformLoaded = o.success;
+
+        if (true !== o.success) {
+            //Ext.Msg.alert('Load failure.');
+        } else {
+            //Apply the platform configs to the platform
+            var root = conn[0].root;
+            Ext.apply(this, o[root]);
+            this.initPlatform();
+        }
+    },
+
+    /**
+     * getPlatform implementation Example 2:
+     * Illustrates loading local resources
+     */
 /*
-    loadPlatform: function() {
+    getPlatform: function() {
         this.platformLoaded = true;
         
         //send back an array of module config objects:

Modified: mickael/trunk/ext/v3.0.0-a1/learn/desktop/desktop.html
===================================================================
--- mickael/trunk/ext/v3.0.0-a1/learn/desktop/desktop.html	2008-12-02 03:50:32 UTC (rev 34)
+++ mickael/trunk/ext/v3.0.0-a1/learn/desktop/desktop.html	2008-12-02 17:22:48 UTC (rev 35)
@@ -17,7 +17,7 @@
 <!--
     <script type="text/javascript" src="../../ext-all.js"></script>
 -->    
-    <script type="text/javascript" src="../../ext-all.js"></script>
+    <script type="text/javascript" src="../../ext-all-debug.js"></script>
 
  	<!-- OVERRIDES -->       <!-- Destroy context menus -->
     <script type="text/javascript" src="override.js"></script>

Modified: mickael/trunk/ext/v3.0.0-a1/learn/desktop/js/Desktop.js
===================================================================
--- mickael/trunk/ext/v3.0.0-a1/learn/desktop/js/Desktop.js	2008-12-02 03:50:32 UTC (rev 34)
+++ mickael/trunk/ext/v3.0.0-a1/learn/desktop/js/Desktop.js	2008-12-02 17:22:48 UTC (rev 35)
@@ -18,7 +18,7 @@
             region: 'center',
             id: 'x-desktop',
             xtype: 'panel',
-            bodyStyle: "background-image:url(eos.jpg) !important",
+            //bodyStyle: "background-image:url(eos.jpg) !important",
             autoEl: {}
         };
 

Modified: mickael/trunk/ext/v3.0.0-a1/learn/desktop/js/RemoteLoader.js
===================================================================
--- mickael/trunk/ext/v3.0.0-a1/learn/desktop/js/RemoteLoader.js	2008-12-02 03:50:32 UTC (rev 34)
+++ mickael/trunk/ext/v3.0.0-a1/learn/desktop/js/RemoteLoader.js	2008-12-02 17:22:48 UTC (rev 35)
@@ -13,73 +13,50 @@
     conn = new Ext.data.Connection(),
     method = 'POST';
     return {
-        /*
-         * default root (read only) 
-         */
-        root: 'platform',
-        /*
+        /**
          * Dynamically load components from a server resource
          * config options include anything available in @link Ext.data.Connection#request
+         * @param {Object} config
          */
         load : function (config) {
             this.root = config.root || this.root;
-            // append the config.callback to the default parameters
-            var cb = config.callback || this.onLoad.createDelegate(this, [config.callback], true);
-            Ext.apply(config, {
+            // append the connection configuration for later use
+            var cb = this.onLoad.createDelegate(this, [config], true);
+            var r = Ext.apply({}, config);
+            Ext.apply(r, {
                 method: method,
-                callback: cb,
-                scope: this
+                callback: cb
             });	
-            if (config.container) {
-                Ext.apply(config.params, {
-                    container: config.container
-                });
-            }
             // submit ajax request to server
             // save id of the server transaction in case we want to cancel the request
-            this.transId = conn.request(config);
+            this.transId = conn.request(r);
         },
         
-        /* @private */
-        onLoad : function (opts, success, response, ct) {			
+        /**
+         * Callback method for the load request.
+         * @param {Object} opts
+         * @param {Object} success
+         * @param {Object} response
+         * @param {Object} c data connection config object
+         */
+        onLoad : function (opts, success, response, c) {			
             try {
                 // use Ext.util.JSON.decode to decode the responseText
                 var o = Ext.decode(response.responseText);
             }
             catch (e) {
-                this.onFailure(opts, success, response, ct);
+                this.onFailure(opts, success, response, c);
                 return;
             }
-            
-            if (o.platform) {
-                this.handlePlatform(o);
-                return;
-
-            } else {
-                this.onFailure();
-            }
+            Ext.callback(c.callback, c.scope, [o, arguments]);
         },
 
         /* @private */
-        onFailure: function (opts, success, response, ct) {
+/*
+        onFailure: function (opts, success, response, c) {
             Ext.Msg.alert('Load failure.');
         },
-
-        /* @private */
-        handlePlatform: function (o) {
-            // TODO: refactor to use events so can more easily
-            // do things like notification messages, etc.
-            Ext.app.controller.platformLoaded = o.success;
-    
-            if (true !== o.success) {
-                this.onFailure();
-            } else {
-                //Apply the platform configs to the platform
-                Ext.apply(Ext.app.controller, o[this.root]);
-                //Ext.app.controller.initPlatform();
-            }
-        },
-
+*/
         /**
          * Requests the module's javascript code and loads it according to the
          * configured onFileLoad method ('eval' or 'head').
@@ -90,7 +67,7 @@
         requestModule: function (m, scope) {
             var cb, url = m.loader.url;
     
-            cb = this.onModuleLoad.createDelegate(scope, [m, this], true);
+            cb = this.onFileLoad.createDelegate(scope, [m, this], true);
             if (this.onFileLoad === 'eval') {
                 this.loadLocalFile(url, m, cb, scope);
             } else {
@@ -100,12 +77,11 @@
             
         /**
          * Use this method to load a file from your own site (same domain).
-         * This method usese AJAX ( responseText ) to retrieve JSON formated data
+         * This method uses AJAX ( responseText ) to retrieve JSON formated data
          * or Javascript off your own site instead of dynamic <script> attachment.
-         * After retrieving the object via ajax, it is pass through the eval
+         * After retrieving the object via ajax, it is passed through the eval
          * command (which is basically just the javascript compiler). After this
-         * is done the functions and variables will be available to the other
-         * functions in your web page. 
+         * is done the functions and variables will be available to use. 
          * @param {Object} filename
          * @param {Object} filetype
          * @param {Object} cb
@@ -122,9 +98,10 @@
     
         /**
          * This method makes it possible to load a remote file from another domain.
-         * Importing cross-domain javascript in this manner with caution as you are
-         * giving the site you are connecting to, total, perfect control over your
-         * web page. Use caution when deciding to cross-connect domains in this fashion. 
+         * Importing cross-domain javascript in this manner should be approached
+         * with caution in this fashion as you are cross-connecting these domains,
+         * which potentially gives the site you are connecting to control over your
+         * web page. Use caution!  
          * @param {Object} filename name (and path) of resource to include)
          * @param {Object} filetype type of file to load ('js', 'css')
          * @param {Object} cb callback function
@@ -152,10 +129,10 @@
             //get a reference to the head element and append the new element to the very end of the HEAD section
             document.getElementsByTagName("head")[0].appendChild(fileref);
         },
-    
+
         /* @private */
-        onModuleLoad: function (opts, success, response, m, scope) {
-            if (this.onFileLoad === 'eval') {
+        onFileLoad: function (opts, success, response, m, scope) {
+            if (this.processRemoteFile === 'eval') {
                 //eval() the response (safe for same domain ajax requests?)
                 try {
                     eval(response.responseText);


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/