-<div id="cls-Ext.data.ScriptTagProxy"></div>/**\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 <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.apply(this, config);\r
-\r
- Ext.data.ScriptTagProxy.superclass.constructor.call(this, config);\r
-\r
- this.head = document.getElementsByTagName("head")[0];\r
-\r
- <div id="event-Ext.data.ScriptTagProxy-loadexception"></div>/**\r
- * @event loadexception\r
- * <b>Deprecated</b> in favor of 'exception' event.\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 remote request returns 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
- <div id="cfg-Ext.data.ScriptTagProxy-url"></div>/**\r
- * @cfg {String} url The URL from which to request the data object.\r
- */\r
- <div id="cfg-Ext.data.ScriptTagProxy-timeout"></div>/**\r
- * @cfg {Number} timeout (optional) The number of milliseconds to wait for a response. Defaults to 30 seconds.\r
- */\r
- timeout : 30000,\r
- <div id="cfg-Ext.data.ScriptTagProxy-callbackParam"></div>/**\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
- <div id="cfg-Ext.data.ScriptTagProxy-nocache"></div>/**\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
- <div id="method-Ext.data.ScriptTagProxy-doRequest"></div>/**\r
- * HttpProxy implementation of DataProxy#doRequest\r
- * @param {String} action\r
- * @param {Ext.data.Record/Ext.data.Record[]} rs If action is <tt>read</tt>, rs will be null\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
- doRequest : function(action, rs, params, reader, callback, scope, arg) {\r
- var p = Ext.urlEncode(Ext.apply(params, this.extraParams));\r
-\r
- var url = this.buildUrl(action, rs);\r
- if (!url) {\r
- throw new Ext.data.Api.Error('invalid-url', url);\r
- }\r
- url = Ext.urlAppend(url, p);\r
-\r
- if(this.nocache){\r
- url = Ext.urlAppend(url, '_dc=' + (new Date().getTime()));\r
- }\r
- var transId = ++Ext.data.ScriptTagProxy.TRANS_ID;\r
- var trans = {\r
- id : transId,\r
- action: action,\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
- window[trans.cb] = this.createCallback(action, rs, trans);\r
- url += String.format("&{0}={1}", this.callbackParam, trans.cb);\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
- },\r
-\r
- // @private createCallback\r
- createCallback : function(action, rs, trans) {\r
- var self = this;\r
- return function(res) {\r
- self.trans = false;\r
- self.destroyTrans(trans, true);\r
- if (action === Ext.data.Api.actions.read) {\r
- self.onRead.call(self, action, trans, res);\r
- } else {\r
- self.onWrite.call(self, action, trans, res, rs);\r
- }\r
- };\r
- },\r
- /**\r
- * Callback for read actions\r
- * @param {String} action [Ext.data.Api.actions.create|read|update|destroy]\r
- * @param {Object} trans The request transaction object\r
- * @param {Object} res The server response\r
- * @private\r
- */\r
- onRead : function(action, trans, res) {\r
- var result;\r
- try {\r
- result = trans.reader.readRecords(res);\r
- }catch(e){\r
- // @deprecated: fire loadexception\r
- this.fireEvent("loadexception", this, trans, res, e);\r
-\r
- this.fireEvent('exception', this, 'response', action, trans, res, e);\r
- trans.callback.call(trans.scope||window, null, trans.arg, false);\r
- return;\r
- }\r
- if (result.success === false) {\r
- // @deprecated: fire old loadexception for backwards-compat.\r
- this.fireEvent('loadexception', this, trans, res);\r
-\r
- this.fireEvent('exception', this, 'remote', action, trans, res, null);\r
- } else {\r
- this.fireEvent("load", this, res, trans.arg);\r
- }\r
- trans.callback.call(trans.scope||window, result, trans.arg, result.success);\r
- },\r
- /**\r
- * Callback for write actions\r
- * @param {String} action [Ext.data.Api.actions.create|read|update|destroy]\r
- * @param {Object} trans The request transaction object\r
- * @param {Object} res The server response\r
- * @private\r
- */\r
- onWrite : function(action, trans, response, rs) {\r
- var reader = trans.reader;\r
- try {\r
- // though we already have a response object here in STP, run through readResponse to catch any meta-data exceptions.\r
- var res = reader.readResponse(action, response);\r
- } catch (e) {\r
- this.fireEvent('exception', this, 'response', action, trans, res, e);\r
- trans.callback.call(trans.scope||window, null, res, false);\r
- return;\r
- }\r
- if(!res.success === true){\r
- this.fireEvent('exception', this, 'remote', action, trans, res, rs);\r
- trans.callback.call(trans.scope||window, null, res, false);\r
- return;\r
- }\r
- this.fireEvent("write", this, action, res.data, res, rs, trans.arg );\r
- trans.callback.call(trans.scope||window, res.data, res, true);\r
- },\r
-\r
- // private\r
- isLoading : function(){\r
- return this.trans ? true : false;\r
- },\r
-\r
- <div id="method-Ext.data.ScriptTagProxy-abort"></div>/**\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
- handleFailure : function(trans){\r
- this.trans = false;\r
- this.destroyTrans(trans, false);\r
- if (trans.action === Ext.data.Api.actions.read) {\r
- // @deprecated firing loadexception\r
- this.fireEvent("loadexception", this, null, trans.arg);\r
- }\r
-\r
- this.fireEvent('exception', this, 'response', trans.action, {\r
- response: null,\r
- options: trans.arg\r
- });\r
- trans.callback.call(trans.scope||window, null, trans.arg, false);\r
- },\r
-\r
- // inherit docs\r
- destroy: function(){\r
- this.abort();\r
- Ext.data.ScriptTagProxy.superclass.destroy.call(this);\r
- }\r
-});</pre>
+<div id="cls-Ext.data.ScriptTagProxy"></div>/**
+ * @class Ext.data.ScriptTagProxy
+ * @extends Ext.data.DataProxy
+ * An implementation of Ext.data.DataProxy that reads a data object from a URL which may be in a domain
+ * other than the originating domain of the running page.<br>
+ * <p>
+ * <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
+ * of the running page, you must use this class, rather than HttpProxy.</b><br>
+ * <p>
+ * The content passed back from a server resource requested by a ScriptTagProxy <b>must</b> be executable JavaScript
+ * source code because it is used as the source inside a <script> tag.<br>
+ * <p>
+ * In order for the browser to process the returned data, the server must wrap the data object
+ * with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy.
+ * Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy
+ * depending on whether the callback name was passed:
+ * <p>
+ * <pre><code>
+boolean scriptTag = false;
+String cb = request.getParameter("callback");
+if (cb != null) {
+ scriptTag = true;
+ response.setContentType("text/javascript");
+} else {
+ response.setContentType("application/x-json");
+}
+Writer out = response.getWriter();
+if (scriptTag) {
+ out.write(cb + "(");
+}
+out.print(dataBlock.toJsonString());
+if (scriptTag) {
+ out.write(");");
+}
+</code></pre>
+ * <p>Below is a PHP example to do the same thing:</p><pre><code>
+$callback = $_REQUEST['callback'];
+
+// Create the output object.
+$output = array('a' => 'Apple', 'b' => 'Banana');
+
+//start output
+if ($callback) {
+ header('Content-Type: text/javascript');
+ echo $callback . '(' . json_encode($output) . ');';
+} else {
+ header('Content-Type: application/x-json');
+ echo json_encode($output);
+}
+</code></pre>
+ * <p>Below is the ASP.Net code to do the same thing:</p><pre><code>
+String jsonString = "{success: true}";
+String cb = Request.Params.Get("callback");
+String responseString = "";
+if (!String.IsNullOrEmpty(cb)) {
+ responseString = cb + "(" + jsonString + ")";
+} else {
+ responseString = jsonString;
+}
+Response.Write(responseString);
+</code></pre>
+ *
+ * @constructor
+ * @param {Object} config A configuration object.
+ */
+Ext.data.ScriptTagProxy = function(config){
+ Ext.apply(this, config);
+
+ Ext.data.ScriptTagProxy.superclass.constructor.call(this, config);
+
+ this.head = document.getElementsByTagName("head")[0];
+
+ <div id="event-Ext.data.ScriptTagProxy-loadexception"></div>/**
+ * @event loadexception
+ * <b>Deprecated</b> in favor of 'exception' event.
+ * Fires if an exception occurs in the Proxy during data loading. This event can be fired for one of two reasons:
+ * <ul><li><b>The load call timed out.</b> This means the load callback did not execute within the time limit
+ * specified by {@link #timeout}. In this case, this event will be raised and the
+ * fourth parameter (read error) will be null.</li>
+ * <li><b>The load succeeded but the reader could not read the response.</b> This means the server returned
+ * data, but the configured Reader threw an error while reading the data. In this case, this event will be
+ * raised and the caught error will be passed along as the fourth parameter of this event.</li></ul>
+ * Note that this event is also relayed through {@link Ext.data.Store}, so you can listen for it directly
+ * on any Store instance.
+ * @param {Object} this
+ * @param {Object} options The loading options that were specified (see {@link #load} for details). If the load
+ * call timed out, this parameter will be null.
+ * @param {Object} arg The callback's arg object passed to the {@link #load} function
+ * @param {Error} e The JavaScript Error object caught if the configured Reader could not read the data.
+ * If the remote request returns success: false, this parameter will be null.
+ */
+};
+
+Ext.data.ScriptTagProxy.TRANS_ID = 1000;
+
+Ext.extend(Ext.data.ScriptTagProxy, Ext.data.DataProxy, {
+ <div id="cfg-Ext.data.ScriptTagProxy-url"></div>/**
+ * @cfg {String} url The URL from which to request the data object.
+ */
+ <div id="cfg-Ext.data.ScriptTagProxy-timeout"></div>/**
+ * @cfg {Number} timeout (optional) The number of milliseconds to wait for a response. Defaults to 30 seconds.
+ */
+ timeout : 30000,
+ <div id="cfg-Ext.data.ScriptTagProxy-callbackParam"></div>/**
+ * @cfg {String} callbackParam (Optional) The name of the parameter to pass to the server which tells
+ * the server the name of the callback function set up by the load call to process the returned data object.
+ * Defaults to "callback".<p>The server-side processing must read this parameter value, and generate
+ * javascript output which calls this named function passing the data object as its only parameter.
+ */
+ callbackParam : "callback",
+ <div id="cfg-Ext.data.ScriptTagProxy-nocache"></div>/**
+ * @cfg {Boolean} nocache (optional) Defaults to true. Disable caching by adding a unique parameter
+ * name to the request.
+ */
+ nocache : true,
+
+ <div id="method-Ext.data.ScriptTagProxy-doRequest"></div>/**
+ * HttpProxy implementation of DataProxy#doRequest
+ * @param {String} action
+ * @param {Ext.data.Record/Ext.data.Record[]} rs If action is <tt>read</tt>, rs will be null
+ * @param {Object} params An object containing properties which are to be used as HTTP parameters
+ * for the request to the remote server.
+ * @param {Ext.data.DataReader} reader The Reader object which converts the data
+ * object into a block of Ext.data.Records.
+ * @param {Function} callback The function into which to pass the block of Ext.data.Records.
+ * The function must be passed <ul>
+ * <li>The Record block object</li>
+ * <li>The "arg" argument from the load function</li>
+ * <li>A boolean success indicator</li>
+ * </ul>
+ * @param {Object} scope The scope (<code>this</code> reference) in which the callback function is executed. Defaults to the browser window.
+ * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
+ */
+ doRequest : function(action, rs, params, reader, callback, scope, arg) {
+ var p = Ext.urlEncode(Ext.apply(params, this.extraParams));
+
+ var url = this.buildUrl(action, rs);
+ if (!url) {
+ throw new Ext.data.Api.Error('invalid-url', url);
+ }
+ url = Ext.urlAppend(url, p);
+
+ if(this.nocache){
+ url = Ext.urlAppend(url, '_dc=' + (new Date().getTime()));
+ }
+ var transId = ++Ext.data.ScriptTagProxy.TRANS_ID;
+ var trans = {
+ id : transId,
+ action: action,
+ cb : "stcCallback"+transId,
+ scriptId : "stcScript"+transId,
+ params : params,
+ arg : arg,
+ url : url,
+ callback : callback,
+ scope : scope,
+ reader : reader
+ };
+ window[trans.cb] = this.createCallback(action, rs, trans);
+ url += String.format("&{0}={1}", this.callbackParam, trans.cb);
+ if(this.autoAbort !== false){
+ this.abort();
+ }
+
+ trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]);
+
+ var script = document.createElement("script");
+ script.setAttribute("src", url);
+ script.setAttribute("type", "text/javascript");
+ script.setAttribute("id", trans.scriptId);
+ this.head.appendChild(script);
+
+ this.trans = trans;
+ },
+
+ // @private createCallback
+ createCallback : function(action, rs, trans) {
+ var self = this;
+ return function(res) {
+ self.trans = false;
+ self.destroyTrans(trans, true);
+ if (action === Ext.data.Api.actions.read) {
+ self.onRead.call(self, action, trans, res);
+ } else {
+ self.onWrite.call(self, action, trans, res, rs);
+ }
+ };
+ },
+ <div id="method-Ext.data.ScriptTagProxy-onRead"></div>/**
+ * Callback for read actions
+ * @param {String} action [Ext.data.Api.actions.create|read|update|destroy]
+ * @param {Object} trans The request transaction object
+ * @param {Object} res The server response
+ * @protected
+ */
+ onRead : function(action, trans, res) {
+ var result;
+ try {
+ result = trans.reader.readRecords(res);
+ }catch(e){
+ // @deprecated: fire loadexception
+ this.fireEvent("loadexception", this, trans, res, e);
+
+ this.fireEvent('exception', this, 'response', action, trans, res, e);
+ trans.callback.call(trans.scope||window, null, trans.arg, false);
+ return;
+ }
+ if (result.success === false) {
+ // @deprecated: fire old loadexception for backwards-compat.
+ this.fireEvent('loadexception', this, trans, res);
+
+ this.fireEvent('exception', this, 'remote', action, trans, res, null);
+ } else {
+ this.fireEvent("load", this, res, trans.arg);
+ }
+ trans.callback.call(trans.scope||window, result, trans.arg, result.success);
+ },
+ <div id="method-Ext.data.ScriptTagProxy-onWrite"></div>/**
+ * Callback for write actions
+ * @param {String} action [Ext.data.Api.actions.create|read|update|destroy]
+ * @param {Object} trans The request transaction object
+ * @param {Object} res The server response
+ * @protected
+ */
+ onWrite : function(action, trans, response, rs) {
+ var reader = trans.reader;
+ try {
+ // though we already have a response object here in STP, run through readResponse to catch any meta-data exceptions.
+ var res = reader.readResponse(action, response);
+ } catch (e) {
+ this.fireEvent('exception', this, 'response', action, trans, res, e);
+ trans.callback.call(trans.scope||window, null, res, false);
+ return;
+ }
+ if(!res.success === true){
+ this.fireEvent('exception', this, 'remote', action, trans, res, rs);
+ trans.callback.call(trans.scope||window, null, res, false);
+ return;
+ }
+ this.fireEvent("write", this, action, res.data, res, rs, trans.arg );
+ trans.callback.call(trans.scope||window, res.data, res, true);
+ },
+
+ // private
+ isLoading : function(){
+ return this.trans ? true : false;
+ },
+
+ <div id="method-Ext.data.ScriptTagProxy-abort"></div>/**
+ * Abort the current server request.
+ */
+ abort : function(){
+ if(this.isLoading()){
+ this.destroyTrans(this.trans);
+ }
+ },
+
+ // private
+ destroyTrans : function(trans, isLoaded){
+ this.head.removeChild(document.getElementById(trans.scriptId));
+ clearTimeout(trans.timeoutId);
+ if(isLoaded){
+ window[trans.cb] = undefined;
+ try{
+ delete window[trans.cb];
+ }catch(e){}
+ }else{
+ // if hasn't been loaded, wait for load to remove it to prevent script error
+ window[trans.cb] = function(){
+ window[trans.cb] = undefined;
+ try{
+ delete window[trans.cb];
+ }catch(e){}
+ };
+ }
+ },
+
+ // private
+ handleFailure : function(trans){
+ this.trans = false;
+ this.destroyTrans(trans, false);
+ if (trans.action === Ext.data.Api.actions.read) {
+ // @deprecated firing loadexception
+ this.fireEvent("loadexception", this, null, trans.arg);
+ }
+
+ this.fireEvent('exception', this, 'response', trans.action, {
+ response: null,
+ options: trans.arg
+ });
+ trans.callback.call(trans.scope||window, null, trans.arg, false);
+ },
+
+ // inherit docs
+ destroy: function(){
+ this.abort();
+ Ext.data.ScriptTagProxy.superclass.destroy.call(this);
+ }
+});</pre>