/* * Based on: * Ext JS Library 1.1.1 * Copyright(c) 2006-2007, Ext JS, LLC. * * Originally Released Under LGPL - original licence link has changed is not relivant. * * Fork - LGPL * <script type="text/javascript"> */ /** * @class Roo.data.HttpProxy * @extends Roo.data.DataProxy * An implementation of {@link Roo.data.DataProxy} that reads a data object from an {@link Roo.data.Connection} object * configured to reference a certain URL.<br><br> * <p> * <em>Note that this class cannot be used to retrieve data from a domain other than the domain * from which the running page was served.<br><br> * <p> * For cross-domain access to remote data, use an {@link Roo.data.ScriptTagProxy}.</em><br><br> * <p> * Be aware that to enable the browser to parse an XML document, the server must set * the Content-Type header in the HTTP response to "text/xml". * @constructor * @param {Object} conn Connection config options to add to each request (e.g. {url: 'foo.php'} or * an {@link Roo.data.Connection} object. If a Connection config is passed, the singleton {@link Roo.Ajax} object * will be used to make the request. */ Roo.data.HttpProxy = function(conn){ Roo.data.HttpProxy.superclass.constructor.call(this); // is conn a conn config or a real conn? this.conn = conn; this.useAjax = !conn || !conn.events; }; Roo.extend(Roo.data.HttpProxy, Roo.data.DataProxy, { // thse are take from connection... /** * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined) */ /** * @cfg {Object} extraParams (Optional) An object containing properties which are used as * extra parameters to each request made by this object. (defaults to undefined) */ /** * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added * to each request made by this object. (defaults to undefined) */ /** * @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) */ /** * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000) */ /** * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false) * @type Boolean */ /** * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true) * @type Boolean */ /** * Return the {@link Roo.data.Connection} object being used by this Proxy. * @return {Connection} The Connection object. This object may be used to subscribe to events on * a finer-grained basis than the DataProxy events. */ getConnection : function(){ return this.useAjax ? Roo.Ajax : this.conn; }, /** * Load data from the configured {@link Roo.data.Connection}, read the data object into * a block of Roo.data.Records using the passed {@link Roo.data.DataReader} implementation, and * process that block using the passed callback. * @param {Object} params An object containing properties which are to be used as HTTP parameters * for the request to the remote server. * @param {Roo.data.DataReader} reader The Reader object which converts the data * object into a block of Roo.data.Records. * @param {Function} callback The function into which to pass the block of Roo.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 in which to call the callback * @param {Object} arg An optional argument which is passed to the callback as its second parameter. */ load : function(params, reader, callback, scope, arg){ if(this.fireEvent("beforeload", this, params) !== false){ var o = { params : params || {}, request: { callback : callback, scope : scope, arg : arg }, reader: reader, callback : this.loadResponse, scope: this }; if(this.useAjax){ Roo.applyIf(o, this.conn); if(this.activeRequest){ Roo.Ajax.abort(this.activeRequest); } this.activeRequest = Roo.Ajax.request(o); }else{ this.conn.request(o); } }else{ callback.call(scope||this, null, arg, false); } }, // private loadResponse : function(o, success, response){ delete this.activeRequest; if(!success){ this.fireEvent("loadexception", this, o, response); o.request.callback.call(o.request.scope, null, o.request.arg, false); return; } var result; try { result = o.reader.read(response); }catch(e){ this.fireEvent("loadexception", this, o, response, e); o.request.callback.call(o.request.scope, null, o.request.arg, false); return; } this.fireEvent("load", this, o, o.request.arg); o.request.callback.call(o.request.scope, result, o.request.arg, true); }, // private update : function(dataSet){ }, // private updateResponse : function(dataSet){ } });