4 * Copyright(c) 2006-2007, Ext JS, LLC.
6 * Originally Released Under LGPL - original licence link has changed is not relivant.
9 * <script type="text/javascript">
12 * @class Roo.data.HttpProxy
13 * @extends Roo.data.DataProxy
14 * An implementation of {@link Roo.data.DataProxy} that reads a data object from an {@link Roo.data.Connection} object
15 * configured to reference a certain URL.<br><br>
17 * <em>Note that this class cannot be used to retrieve data from a domain other than the domain
18 * from which the running page was served.<br><br>
20 * For cross-domain access to remote data, use an {@link Roo.data.ScriptTagProxy}.</em><br><br>
22 * Be aware that to enable the browser to parse an XML document, the server must set
23 * the Content-Type header in the HTTP response to "text/xml".
25 * @param {Object} conn Connection config options to add to each request (e.g. {url: 'foo.php'} or
26 * an {@link Roo.data.Connection} object. If a Connection config is passed, the singleton {@link Roo.Ajax} object
27 * will be used to make the request.
29 Roo.data.HttpProxy = function(conn){
30 Roo.data.HttpProxy.superclass.constructor.call(this);
31 // is conn a conn config or a real conn?
33 this.useAjax = !conn || !conn.events;
37 Roo.extend(Roo.data.HttpProxy, Roo.data.DataProxy, {
38 // thse are take from connection...
41 * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
44 * @cfg {Object} extraParams (Optional) An object containing properties which are used as
45 * extra parameters to each request made by this object. (defaults to undefined)
48 * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
49 * to each request made by this object. (defaults to undefined)
52 * @cfg {String} method (Optional) The default HTTP method to be used for requests. (defaults to undefined; if not set but parms are present will use POST, otherwise GET)
55 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
58 * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
64 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
68 * Return the {@link Roo.data.Connection} object being used by this Proxy.
69 * @return {Connection} The Connection object. This object may be used to subscribe to events on
70 * a finer-grained basis than the DataProxy events.
72 getConnection : function(){
73 return this.useAjax ? Roo.Ajax : this.conn;
77 * Load data from the configured {@link Roo.data.Connection}, read the data object into
78 * a block of Roo.data.Records using the passed {@link Roo.data.DataReader} implementation, and
79 * process that block using the passed callback.
80 * @param {Object} params An object containing properties which are to be used as HTTP parameters
81 * for the request to the remote server.
82 * @param {Roo.data.DataReader} reader The Reader object which converts the data
83 * object into a block of Roo.data.Records.
84 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
85 * The function must be passed <ul>
86 * <li>The Record block object</li>
87 * <li>The "arg" argument from the load function</li>
88 * <li>A boolean success indicator</li>
90 * @param {Object} scope The scope in which to call the callback
91 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
93 load : function(params, reader, callback, scope, arg){
94 if(this.fireEvent("beforeload", this, params) !== false){
96 params : params || {},
103 callback : this.loadResponse,
107 Roo.applyIf(o, this.conn);
108 if(this.activeRequest){
109 Roo.Ajax.abort(this.activeRequest);
111 this.activeRequest = Roo.Ajax.request(o);
113 this.conn.request(o);
116 callback.call(scope||this, null, arg, false);
121 loadResponse : function(o, success, response){
122 delete this.activeRequest;
124 this.fireEvent("loadexception", this, o, response);
125 o.request.callback.call(o.request.scope, null, o.request.arg, false);
130 result = o.reader.read(response);
133 o.raw = { errorMsg : response.responseText };
134 this.fireEvent("loadexception", this, o, response, e);
135 o.request.callback.call(o.request.scope, o, o.request.arg, false);
139 this.fireEvent("load", this, o, o.request.arg);
140 o.request.callback.call(o.request.scope, result, o.request.arg, true);
144 update : function(dataSet){
149 updateResponse : function(dataSet){