Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / source / data / ScriptTagProxy.js
diff --git a/source/data/ScriptTagProxy.js b/source/data/ScriptTagProxy.js
deleted file mode 100644 (file)
index 6fe4c9e..0000000
+++ /dev/null
@@ -1,218 +0,0 @@
-/*\r
- * Ext JS Library 2.2.1\r
- * Copyright(c) 2006-2009, Ext JS, LLC.\r
- * licensing@extjs.com\r
- * \r
- * http://extjs.com/license\r
- */\r
-\r
-/**\r
- * @class Ext.data.ScriptTagProxy\r
- * @extends Ext.data.DataProxy\r
- * An implementation of Ext.data.DataProxy that reads a data object from a URL which may be in a domain\r
- * other than the originating domain of the running page.<br>\r
- * <p>\r
- * <b>Note that if you are retrieving data from a page that is in a domain that is NOT the same as the originating domain\r
- * of the running page, you must use this class, rather than HttpProxy.</b><br>\r
- * <p>\r
- * The content passed back from a server resource requested by a ScriptTagProxy <b>must</b> be executable JavaScript\r
- * source code because it is used as the source inside a &lt;script> tag.<br>\r
- * <p>\r
- * In order for the browser to process the returned data, the server must wrap the data object\r
- * with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy.\r
- * Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy\r
- * depending on whether the callback name was passed:\r
- * <p>\r
- * <pre><code>\r
-boolean scriptTag = false;\r
-String cb = request.getParameter("callback");\r
-if (cb != null) {\r
-    scriptTag = true;\r
-    response.setContentType("text/javascript");\r
-} else {\r
-    response.setContentType("application/x-json");\r
-}\r
-Writer out = response.getWriter();\r
-if (scriptTag) {\r
-    out.write(cb + "(");\r
-}\r
-out.print(dataBlock.toJsonString());\r
-if (scriptTag) {\r
-    out.write(");");\r
-}\r
-</code></pre>\r
- *\r
- * @constructor\r
- * @param {Object} config A configuration object.\r
- */\r
-Ext.data.ScriptTagProxy = function(config){\r
-    Ext.data.ScriptTagProxy.superclass.constructor.call(this);\r
-    Ext.apply(this, config);\r
-    this.head = document.getElementsByTagName("head")[0];\r
-    \r
-    /**\r
-     * @event loadexception\r
-     * Fires if an exception occurs in the Proxy during data loading.  This event can be fired for one of two reasons:\r
-     * <ul><li><b>The load call timed out.</b>  This means the load callback did not execute within the time limit\r
-     * specified by {@link #timeout}.  In this case, this event will be raised and the\r
-     * fourth parameter (read error) will be null.</li>\r
-     * <li><b>The load succeeded but the reader could not read the response.</b>  This means the server returned\r
-     * data, but the configured Reader threw an error while reading the data.  In this case, this event will be \r
-     * raised and the caught error will be passed along as the fourth parameter of this event.</li></ul>\r
-     * Note that this event is also relayed through {@link Ext.data.Store}, so you can listen for it directly\r
-     * on any Store instance.\r
-     * @param {Object} this\r
-     * @param {Object} options The loading options that were specified (see {@link #load} for details).  If the load\r
-     * call timed out, this parameter will be null.\r
-     * @param {Object} arg The callback's arg object passed to the {@link #load} function\r
-     * @param {Error} e The JavaScript Error object caught if the configured Reader could not read the data.\r
-     * If the load call returned success: false, this parameter will be null.\r
-     */\r
-};\r
-\r
-Ext.data.ScriptTagProxy.TRANS_ID = 1000;\r
-\r
-Ext.extend(Ext.data.ScriptTagProxy, Ext.data.DataProxy, {\r
-    /**\r
-     * @cfg {String} url The URL from which to request the data object.\r
-     */\r
-    /**\r
-     * @cfg {Number} timeout (optional) The number of milliseconds to wait for a response. Defaults to 30 seconds.\r
-     */\r
-    timeout : 30000,\r
-    /**\r
-     * @cfg {String} callbackParam (Optional) The name of the parameter to pass to the server which tells\r
-     * the server the name of the callback function set up by the load call to process the returned data object.\r
-     * Defaults to "callback".<p>The server-side processing must read this parameter value, and generate\r
-     * javascript output which calls this named function passing the data object as its only parameter.\r
-     */\r
-    callbackParam : "callback",\r
-    /**\r
-     *  @cfg {Boolean} nocache (optional) Defaults to true. Disable caching by adding a unique parameter\r
-     * name to the request.\r
-     */\r
-    nocache : true,\r
-\r
-    /**\r
-     * Load data from the configured URL, read the data object into\r
-     * a block of Ext.data.Records using the passed Ext.data.DataReader implementation, and\r
-     * process that block using the passed callback.\r
-     * @param {Object} params An object containing properties which are to be used as HTTP parameters\r
-     * for the request to the remote server.\r
-     * @param {Ext.data.DataReader} reader The Reader object which converts the data\r
-     * object into a block of Ext.data.Records.\r
-     * @param {Function} callback The function into which to pass the block of Ext.data.Records.\r
-     * The function must be passed <ul>\r
-     * <li>The Record block object</li>\r
-     * <li>The "arg" argument from the load function</li>\r
-     * <li>A boolean success indicator</li>\r
-     * </ul>\r
-     * @param {Object} scope The scope in which to call the callback\r
-     * @param {Object} arg An optional argument which is passed to the callback as its second parameter.\r
-     */\r
-    load : function(params, reader, callback, scope, arg){\r
-        if(this.fireEvent("beforeload", this, params) !== false){\r
-\r
-            var p = Ext.urlEncode(Ext.apply(params, this.extraParams));\r
-\r
-            var url = this.url;\r
-            url += (url.indexOf("?") != -1 ? "&" : "?") + p;\r
-            if(this.nocache){\r
-                url += "&_dc=" + (new Date().getTime());\r
-            }\r
-            var transId = ++Ext.data.ScriptTagProxy.TRANS_ID;\r
-            var trans = {\r
-                id : transId,\r
-                cb : "stcCallback"+transId,\r
-                scriptId : "stcScript"+transId,\r
-                params : params,\r
-                arg : arg,\r
-                url : url,\r
-                callback : callback,\r
-                scope : scope,\r
-                reader : reader\r
-            };\r
-            var conn = this;\r
-\r
-            window[trans.cb] = function(o){\r
-                conn.handleResponse(o, trans);\r
-            };\r
-\r
-            url += String.format("&{0}={1}", this.callbackParam, trans.cb);\r
-\r
-            if(this.autoAbort !== false){\r
-                this.abort();\r
-            }\r
-\r
-            trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]);\r
-\r
-            var script = document.createElement("script");\r
-            script.setAttribute("src", url);\r
-            script.setAttribute("type", "text/javascript");\r
-            script.setAttribute("id", trans.scriptId);\r
-            this.head.appendChild(script);\r
-\r
-            this.trans = trans;\r
-        }else{\r
-            callback.call(scope||this, null, arg, false);\r
-        }\r
-    },\r
-\r
-    // private\r
-    isLoading : function(){\r
-        return this.trans ? true : false;\r
-    },\r
-\r
-    /**\r
-     * Abort the current server request.\r
-     */\r
-    abort : function(){\r
-        if(this.isLoading()){\r
-            this.destroyTrans(this.trans);\r
-        }\r
-    },\r
-\r
-    // private\r
-    destroyTrans : function(trans, isLoaded){\r
-        this.head.removeChild(document.getElementById(trans.scriptId));\r
-        clearTimeout(trans.timeoutId);\r
-        if(isLoaded){\r
-            window[trans.cb] = undefined;\r
-            try{\r
-                delete window[trans.cb];\r
-            }catch(e){}\r
-        }else{\r
-            // if hasn't been loaded, wait for load to remove it to prevent script error\r
-            window[trans.cb] = function(){\r
-                window[trans.cb] = undefined;\r
-                try{\r
-                    delete window[trans.cb];\r
-                }catch(e){}\r
-            };\r
-        }\r
-    },\r
-\r
-    // private\r
-    handleResponse : function(o, trans){\r
-        this.trans = false;\r
-        this.destroyTrans(trans, true);\r
-        var result;\r
-        try {\r
-            result = trans.reader.readRecords(o);\r
-        }catch(e){\r
-            this.fireEvent("loadexception", this, o, trans.arg, e);\r
-            trans.callback.call(trans.scope||window, null, trans.arg, false);\r
-            return;\r
-        }\r
-        this.fireEvent("load", this, o, trans.arg);\r
-        trans.callback.call(trans.scope||window, result, trans.arg, true);\r
-    },\r
-\r
-    // private\r
-    handleFailure : function(trans){\r
-        this.trans = false;\r
-        this.destroyTrans(trans, false);\r
-        this.fireEvent("loadexception", this, null, trans.arg);\r
-        trans.callback.call(trans.scope||window, null, trans.arg, false);\r
-    }\r
-});
\ No newline at end of file