<html>\r
<head>\r
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> \r
<title>The source code</title>\r
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
POST = 'POST',\r
GET = 'GET',\r
WINDOW = window;\r
- \r
+\r
<div id="cls-Ext.data.Connection"></div>/**\r
* @class Ext.data.Connection\r
* @extends Ext.util.Observable\r
* @constructor\r
* @param {Object} config a configuration object.\r
*/\r
- Ext.data.Connection = function(config){ \r
+ Ext.data.Connection = function(config){\r
Ext.apply(this, config);\r
this.addEvents(\r
<div id="event-Ext.data.Connection-beforerequest"></div>/**\r
Ext.data.Connection.superclass.constructor.call(this);\r
};\r
\r
- // private\r
- function handleResponse(response){\r
- this.transId = false;\r
- var options = response.argument.options;\r
- response.argument = options ? options.argument : null;\r
- this.fireEvent(REQUESTCOMPLETE, this, response, options);\r
- if(options.success){\r
- options.success.call(options.scope, response, options);\r
- }\r
- if(options.callback){\r
- options.callback.call(options.scope, options, true, response);\r
- }\r
- }\r
-\r
- // private\r
- function handleFailure(response, e){\r
- this.transId = false;\r
- var options = response.argument.options;\r
- response.argument = options ? options.argument : null;\r
- this.fireEvent(REQUESTEXCEPTION, this, response, options, e);\r
- if(options.failure){\r
- options.failure.call(options.scope, response, options);\r
- }\r
- if(options.callback){\r
- options.callback.call(options.scope, options, false, response);\r
- }\r
- }\r
-\r
- // private\r
- function doFormUpload(o, ps, url){\r
- var id = Ext.id(),\r
- doc = document,\r
- frame = doc.createElement('iframe'),\r
- form = Ext.getDom(o.form),\r
- hiddens = [],\r
- hd,\r
- encoding = 'multipart/form-data',\r
- buf = {\r
- target: form.target,\r
- method: form.method,\r
- encoding: form.encoding,\r
- enctype: form.enctype,\r
- action: form.action\r
- };\r
- \r
- Ext.apply(frame, {\r
- id: id,\r
- name: id,\r
- className: 'x-hidden',\r
- src: Ext.SSL_SECURE_URL // for IE\r
- }); \r
- doc.body.appendChild(frame);\r
- \r
- // This is required so that IE doesn't pop the response up in a new window.\r
- if(Ext.isIE){\r
- document.frames[id].name = id;\r
- }\r
- \r
- Ext.apply(form, {\r
- target: id,\r
- method: POST,\r
- enctype: encoding,\r
- encoding: encoding,\r
- action: url || buf.action\r
- });\r
- \r
- // add dynamic params \r
- ps = Ext.urlDecode(ps, false);\r
- for(var k in ps){\r
- if(ps.hasOwnProperty(k)){\r
- hd = doc.createElement('input');\r
- hd.type = 'hidden'; \r
- hd.value = ps[hd.name = k];\r
- form.appendChild(hd);\r
- hiddens.push(hd);\r
- }\r
- } \r
-\r
- function cb(){\r
- var me = this,\r
- // bogus response object\r
- r = {responseText : '',\r
- responseXML : null,\r
- argument : o.argument},\r
- doc,\r
- firstChild;\r
-\r
- try{ \r
- doc = frame.contentWindow.document || frame.contentDocument || WINDOW.frames[id].document;\r
- if(doc){\r
- if(doc.body){\r
- if(/textarea/i.test((firstChild = doc.body.firstChild || {}).tagName)){ // json response wrapped in textarea \r
- r.responseText = firstChild.value;\r
- }else{\r
- r.responseText = doc.body.innerHTML;\r
- }\r
- }\r
- //in IE the document may still have a body even if returns XML.\r
- r.responseXML = doc.XMLDocument || doc;\r
- }\r
- }\r
- catch(e) {}\r
-\r
- Ext.EventManager.removeListener(frame, LOAD, cb, me);\r
-\r
- me.fireEvent(REQUESTCOMPLETE, me, r, o);\r
- \r
- function runCallback(fn, scope, args){\r
- if(Ext.isFunction(fn)){\r
- fn.apply(scope, args);\r
- }\r
- }\r
-\r
- runCallback(o.success, o.scope, [r, o]);\r
- runCallback(o.callback, o.scope, [o, true, r]);\r
-\r
- if(!me.debugUploads){\r
- setTimeout(function(){Ext.removeNode(frame);}, 100);\r
- }\r
- }\r
-\r
- Ext.EventManager.on(frame, LOAD, cb, this);\r
- form.submit();\r
- \r
- Ext.apply(form, buf);\r
- Ext.each(hiddens, function(h) {\r
- Ext.removeNode(h);\r
- });\r
- }\r
-\r
Ext.extend(Ext.data.Connection, Ext.util.Observable, {\r
<div id="cfg-Ext.data.Connection-url"></div>/**\r
* @cfg {String} url (Optional) <p>The default URL to be used for requests to the server. Defaults to undefined.</p>\r
* @type Boolean\r
*/\r
autoAbort:false,\r
- \r
+\r
<div id="cfg-Ext.data.Connection-disableCaching"></div>/**\r
* @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)\r
* @type Boolean\r
*/\r
disableCaching: true,\r
- \r
+\r
<div id="cfg-Ext.data.Connection-disableCachingParam"></div>/**\r
* @cfg {String} disableCachingParam (Optional) Change the parameter which is sent went disabling caching\r
* through a cache buster. Defaults to '_dc'\r
* @type String\r
*/\r
disableCachingParam: '_dc',\r
- \r
+\r
<div id="method-Ext.data.Connection-request"></div>/**\r
* <p>Sends an HTTP request to a remote server.</p>\r
* <p><b>Important:</b> Ajax server requests are asynchronous, and this call will\r
* parameters:<ul>\r
* <li><b>options</b> : Object<div class="sub-desc">The parameter to the request call.</div></li>\r
* <li><b>success</b> : Boolean<div class="sub-desc">True if the request succeeded.</div></li>\r
- * <li><b>response</b> : Object<div class="sub-desc">The XMLHttpRequest object containing the response data. \r
- * See <a href="http://www.w3.org/TR/XMLHttpRequest/">http://www.w3.org/TR/XMLHttpRequest/</a> for details about \r
+ * <li><b>response</b> : Object<div class="sub-desc">The XMLHttpRequest object containing the response data.\r
+ * See <a href="http://www.w3.org/TR/XMLHttpRequest/">http://www.w3.org/TR/XMLHttpRequest/</a> for details about\r
* accessing elements of the response.</div></li>\r
* </ul></div></li>\r
* <li><a id="request-option-success"></a><b>success</b> : Function (Optional)<div class="sub-desc">The function\r
* <li><b>timeout</b> : Number (Optional)<div class="sub-desc">The timeout in milliseconds to be used for this request. Defaults to 30 seconds.</div></li>\r
* <li><b>form</b> : Element/HTMLElement/String (Optional)<div class="sub-desc">The <tt><form></tt>\r
* Element or the id of the <tt><form></tt> to pull parameters from.</div></li>\r
- * <li><a id="request-option-isUpload"></a><b>isUpload</b> : Boolean (Optional)<div class="sub-desc"><b>Only meaningful when used \r
+ * <li><a id="request-option-isUpload"></a><b>isUpload</b> : Boolean (Optional)<div class="sub-desc"><b>Only meaningful when used\r
* with the <tt>form</tt> option</b>.\r
* <p>True if the form object is a file upload (will be set automatically if the form was\r
* configured with <b><tt>enctype</tt></b> "multipart/form-data").</p>\r
me.indicatorText = '<div class="loading-indicator">'+o.indicatorText+"</div>";\r
}\r
if(me.indicatorText) {\r
- Ext.getDom(o.el).innerHTML = me.indicatorText; \r
+ Ext.getDom(o.el).innerHTML = me.indicatorText;\r
}\r
o.success = (Ext.isFunction(o.success) ? o.success : function(){}).createInterceptor(function(response) {\r
Ext.getDom(o.el).innerHTML = response.responseText;\r
});\r
}\r
- \r
+\r
var p = o.params,\r
- url = o.url || me.url, \r
+ url = o.url || me.url,\r
method,\r
- cb = {success: handleResponse,\r
- failure: handleFailure,\r
+ cb = {success: me.handleResponse,\r
+ failure: me.handleFailure,\r
scope: me,\r
argument: {options: o},\r
timeout : o.timeout || me.timeout\r
},\r
- form, \r
- serForm; \r
- \r
- \r
+ form,\r
+ serForm;\r
+\r
+\r
if (Ext.isFunction(p)) {\r
p = p.call(o.scope||WINDOW, o);\r
}\r
- \r
- p = Ext.urlEncode(me.extraParams, Ext.isObject(p) ? Ext.urlEncode(p) : p); \r
- \r
+\r
+ p = Ext.urlEncode(me.extraParams, Ext.isObject(p) ? Ext.urlEncode(p) : p);\r
+\r
if (Ext.isFunction(url)) {\r
url = url.call(o.scope || WINDOW, o);\r
}\r
- \r
+\r
if((form = Ext.getDom(o.form))){\r
url = url || form.action;\r
- if(o.isUpload || /multipart\/form-data/i.test(form.getAttribute("enctype"))) { \r
- return doFormUpload.call(me, o, p, url);\r
+ if(o.isUpload || /multipart\/form-data/i.test(form.getAttribute("enctype"))) {\r
+ return me.doFormUpload.call(me, o, p, url);\r
}\r
- serForm = Ext.lib.Ajax.serializeForm(form); \r
+ serForm = Ext.lib.Ajax.serializeForm(form);\r
p = p ? (p + '&' + serForm) : serForm;\r
}\r
- \r
+\r
method = o.method || me.method || ((p || o.xmlData || o.jsonData) ? POST : GET);\r
- \r
+\r
if(method === GET && (me.disableCaching && o.disableCaching !== false) || o.disableCaching === true){\r
var dcp = o.disableCachingParam || me.disableCachingParam;\r
url = Ext.urlAppend(url, dcp + '=' + (new Date().getTime()));\r
}\r
- \r
+\r
o.headers = Ext.apply(o.headers || {}, me.defaultHeaders || {});\r
- \r
+\r
if(o.autoAbort === true || me.autoAbort) {\r
me.abort();\r
}\r
- \r
+\r
if((method == GET || o.xmlData || o.jsonData) && p){\r
- url = Ext.urlAppend(url, p); \r
+ url = Ext.urlAppend(url, p);\r
p = '';\r
}\r
return (me.transId = Ext.lib.Ajax.request(method, url, cb, p, o));\r
- }else{ \r
+ }else{\r
return o.callback ? o.callback.apply(o.scope, [o,UNDEFINED,UNDEFINED]) : null;\r
}\r
},\r
- \r
+\r
<div id="method-Ext.data.Connection-isLoading"></div>/**\r
* Determine whether this object has a request outstanding.\r
* @param {Number} transactionId (Optional) defaults to the last transaction\r
* @return {Boolean} True if there is an outstanding request.\r
*/\r
isLoading : function(transId){\r
- return transId ? Ext.lib.Ajax.isCallInProgress(transId) : !! this.transId; \r
+ return transId ? Ext.lib.Ajax.isCallInProgress(transId) : !! this.transId;\r
},\r
- \r
+\r
<div id="method-Ext.data.Connection-abort"></div>/**\r
* Aborts any outstanding request.\r
* @param {Number} transactionId (Optional) defaults to the last transaction\r
if(transId || this.isLoading()){\r
Ext.lib.Ajax.abort(transId || this.transId);\r
}\r
+ },\r
+\r
+ // private\r
+ handleResponse : function(response){\r
+ this.transId = false;\r
+ var options = response.argument.options;\r
+ response.argument = options ? options.argument : null;\r
+ this.fireEvent(REQUESTCOMPLETE, this, response, options);\r
+ if(options.success){\r
+ options.success.call(options.scope, response, options);\r
+ }\r
+ if(options.callback){\r
+ options.callback.call(options.scope, options, true, response);\r
+ }\r
+ },\r
+\r
+ // private\r
+ handleFailure : function(response, e){\r
+ this.transId = false;\r
+ var options = response.argument.options;\r
+ response.argument = options ? options.argument : null;\r
+ this.fireEvent(REQUESTEXCEPTION, this, response, options, e);\r
+ if(options.failure){\r
+ options.failure.call(options.scope, response, options);\r
+ }\r
+ if(options.callback){\r
+ options.callback.call(options.scope, options, false, response);\r
+ }\r
+ },\r
+\r
+ // private\r
+ doFormUpload : function(o, ps, url){\r
+ var id = Ext.id(),\r
+ doc = document,\r
+ frame = doc.createElement('iframe'),\r
+ form = Ext.getDom(o.form),\r
+ hiddens = [],\r
+ hd,\r
+ encoding = 'multipart/form-data',\r
+ buf = {\r
+ target: form.target,\r
+ method: form.method,\r
+ encoding: form.encoding,\r
+ enctype: form.enctype,\r
+ action: form.action\r
+ };\r
+\r
+ Ext.fly(frame).set({\r
+ id: id,\r
+ name: id,\r
+ cls: 'x-hidden'\r
+\r
+ });\r
+\r
+ doc.body.appendChild(frame);\r
+\r
+ //Reset the Frame to neutral domain\r
+ Ext.fly(frame).set({\r
+ src : Ext.SSL_SECURE_URL\r
+ });\r
+\r
+ // This is required so that IE doesn't pop the response up in a new window.\r
+ if(Ext.isIE){\r
+ document.frames[id].name = id;\r
+ }\r
+\r
+\r
+ Ext.fly(form).set({\r
+ target: id,\r
+ method: POST,\r
+ enctype: encoding,\r
+ encoding: encoding,\r
+ action: url || buf.action\r
+ });\r
+\r
+ // add dynamic params\r
+ Ext.iterate(Ext.urlDecode(ps, false), function(k, v){\r
+ hd = doc.createElement('input');\r
+ Ext.fly(hd).set({\r
+ type: 'hidden',\r
+ value: v,\r
+ name: k\r
+ });\r
+ form.appendChild(hd);\r
+ hiddens.push(hd);\r
+ });\r
+\r
+ function cb(){\r
+ var me = this,\r
+ // bogus response object\r
+ r = {responseText : '',\r
+ responseXML : null,\r
+ argument : o.argument},\r
+ doc,\r
+ firstChild;\r
+\r
+ try{\r
+ doc = frame.contentWindow.document || frame.contentDocument || WINDOW.frames[id].document;\r
+ if(doc){\r
+ if(doc.body){\r
+ if(/textarea/i.test((firstChild = doc.body.firstChild || {}).tagName)){ // json response wrapped in textarea\r
+ r.responseText = firstChild.value;\r
+ }else{\r
+ r.responseText = doc.body.innerHTML;\r
+ }\r
+ }\r
+ //in IE the document may still have a body even if returns XML.\r
+ r.responseXML = doc.XMLDocument || doc;\r
+ }\r
+ }\r
+ catch(e) {}\r
+\r
+ Ext.EventManager.removeListener(frame, LOAD, cb, me);\r
+\r
+ me.fireEvent(REQUESTCOMPLETE, me, r, o);\r
+\r
+ function runCallback(fn, scope, args){\r
+ if(Ext.isFunction(fn)){\r
+ fn.apply(scope, args);\r
+ }\r
+ }\r
+\r
+ runCallback(o.success, o.scope, [r, o]);\r
+ runCallback(o.callback, o.scope, [o, true, r]);\r
+\r
+ if(!me.debugUploads){\r
+ setTimeout(function(){Ext.removeNode(frame);}, 100);\r
+ }\r
+ }\r
+\r
+ Ext.EventManager.on(frame, LOAD, cb, this);\r
+ form.submit();\r
+\r
+ Ext.fly(form).set(buf);\r
+ Ext.each(hiddens, function(h) {\r
+ Ext.removeNode(h);\r
+ });\r
}\r
});\r
})();\r
Ext.Ajax.defaultHeaders = {\r
'Powered-By': 'Ext'\r
};\r
- * </code></pre> \r
+ * </code></pre>\r
* </p>\r
* <p>Common <b>Events</b> you may want to set are:<div class="mdetail-params"><ul>\r
* <li><b><tt>{@link Ext.data.Connection#beforerequest beforerequest}</tt></b><p class="sub-desc"></p></li>\r
Ext.Ajax.on('beforerequest', this.showSpinner, this);\r
Ext.Ajax.on('requestcomplete', this.hideSpinner, this);\r
Ext.Ajax.on('requestexception', this.hideSpinner, this);\r
- * </code></pre> \r
+ * </code></pre>\r
* </p>\r
* <p>An example request:</p>\r
* <pre><code>\r
form: 'some-form',\r
params: 'foo=bar'\r
});\r
- * </code></pre> \r
+ * </code></pre>\r
* </p>\r
* @singleton\r
*/\r