<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
</head>\r
<body onload="prettyPrint();">\r
<pre class="prettyprint lang-js">/*\r
- * Portions of this file are based on pieces of Yahoo User Interface Library\r
- * Copyright (c) 2007, Yahoo! Inc. All rights reserved.\r
- * YUI licensed under the BSD License:\r
- * http://developer.yahoo.net/yui/license.txt\r
- */\r
- Ext.lib.Ajax = function() { \r
- var activeX = ['MSXML2.XMLHTTP.3.0',\r
- 'MSXML2.XMLHTTP',\r
- 'Microsoft.XMLHTTP'],\r
- CONTENTTYPE = 'Content-Type';\r
- \r
- // private\r
- function setHeader(o) {\r
- var conn = o.conn,\r
- prop;\r
- \r
- function setTheHeaders(conn, headers){\r
- for (prop in headers) {\r
- if (headers.hasOwnProperty(prop)) {\r
- conn.setRequestHeader(prop, headers[prop]);\r
- }\r
- } \r
- } \r
- \r
- if (pub.defaultHeaders) {\r
- setTheHeaders(conn, pub.defaultHeaders);\r
- }\r
-\r
- if (pub.headers) {\r
- setTheHeaders(conn, pub.headers);\r
- pub.headers = null; \r
- }\r
- } \r
+* Portions of this file are based on pieces of Yahoo User Interface Library\r
+* Copyright (c) 2007, Yahoo! Inc. All rights reserved.\r
+* YUI licensed under the BSD License:\r
+* http://developer.yahoo.net/yui/license.txt\r
+*/\r
+Ext.lib.Ajax = function() { \r
+ var activeX = ['MSXML2.XMLHTTP.3.0',\r
+ 'MSXML2.XMLHTTP',\r
+ 'Microsoft.XMLHTTP'],\r
+ CONTENTTYPE = 'Content-Type';\r
+ \r
+ // private\r
+ function setHeader(o) {\r
+ var conn = o.conn,\r
+ prop;\r
\r
- // private\r
- function createExceptionObject(tId, callbackArg, isAbort, isTimeout) { \r
- return {\r
- tId : tId,\r
- status : isAbort ? -1 : 0,\r
- statusText : isAbort ? 'transaction aborted' : 'communication failure',\r
- isAbort: true,\r
- isTimeout: true,\r
- argument : callbackArg\r
- };\r
- } \r
+ function setTheHeaders(conn, headers){\r
+ for (prop in headers) {\r
+ if (headers.hasOwnProperty(prop)) {\r
+ conn.setRequestHeader(prop, headers[prop]);\r
+ }\r
+ } \r
+ } \r
\r
- // private \r
- function initHeader(label, value) { \r
- (pub.headers = pub.headers || {})[label] = value; \r
+ if (pub.defaultHeaders) {\r
+ setTheHeaders(conn, pub.defaultHeaders);\r
}\r
- \r
- // private\r
- function createResponseObject(o, callbackArg) {\r
- var headerObj = {},\r
- headerStr, \r
- conn = o.conn,\r
- t,\r
- s;\r
\r
- try {\r
- headerStr = o.conn.getAllResponseHeaders(); \r
- Ext.each(headerStr.replace(/\r\n/g, '\n').split('\n'), function(v){\r
- t = v.indexOf(':');\r
- if(t >= 0){\r
- s = v.substr(0, t).toLowerCase();\r
- if(v.charAt(t + 1) == ' '){\r
- ++t;\r
- }\r
- headerObj[s] = v.substr(t + 1);\r
+ if (pub.headers) {\r
+ setTheHeaders(conn, pub.headers);\r
+ delete pub.headers; \r
+ }\r
+ } \r
+ \r
+ // private\r
+ function createExceptionObject(tId, callbackArg, isAbort, isTimeout) { \r
+ return {\r
+ tId : tId,\r
+ status : isAbort ? -1 : 0,\r
+ statusText : isAbort ? 'transaction aborted' : 'communication failure',\r
+ isAbort: isAbort,\r
+ isTimeout: isTimeout,\r
+ argument : callbackArg\r
+ };\r
+ } \r
+ \r
+ // private \r
+ function initHeader(label, value) { \r
+ (pub.headers = pub.headers || {})[label] = value; \r
+ }\r
+ \r
+ // private\r
+ function createResponseObject(o, callbackArg) {\r
+ var headerObj = {},\r
+ headerStr, \r
+ conn = o.conn,\r
+ t,\r
+ s;\r
+\r
+ try {\r
+ headerStr = o.conn.getAllResponseHeaders(); \r
+ Ext.each(headerStr.replace(/\r\n/g, '\n').split('\n'), function(v){\r
+ t = v.indexOf(':');\r
+ if(t >= 0){\r
+ s = v.substr(0, t).toLowerCase();\r
+ if(v.charAt(t + 1) == ' '){\r
+ ++t;\r
}\r
- });\r
- } catch(e) {}\r
- \r
- return {\r
- tId : o.tId,\r
- status : conn.status,\r
- statusText : conn.statusText,\r
- getResponseHeader : function(header){return headerObj[header.toLowerCase()];},\r
- getAllResponseHeaders : function(){return headerStr},\r
- responseText : conn.responseText,\r
- responseXML : conn.responseXML,\r
- argument : callbackArg\r
- };\r
+ headerObj[s] = v.substr(t + 1);\r
+ }\r
+ });\r
+ } catch(e) {}\r
+ \r
+ return {\r
+ tId : o.tId,\r
+ status : conn.status,\r
+ statusText : conn.statusText,\r
+ getResponseHeader : function(header){return headerObj[header.toLowerCase()];},\r
+ getAllResponseHeaders : function(){return headerStr},\r
+ responseText : conn.responseText,\r
+ responseXML : conn.responseXML,\r
+ argument : callbackArg\r
+ };\r
+ }\r
+ \r
+ // private\r
+ function releaseObject(o) {\r
+ o.conn = null;\r
+ o = null;\r
+ } \r
+ \r
+ // private\r
+ function handleTransactionResponse(o, callback, isAbort, isTimeout) {\r
+ if (!callback) {\r
+ releaseObject(o);\r
+ return;\r
}\r
- \r
- // private\r
- function releaseObject(o) {\r
- o.conn = null;\r
- o = null;\r
- } \r
- \r
- // private\r
- function handleTransactionResponse(o, callback, isAbort, isTimeout) {\r
- if (!callback) {\r
- releaseObject(o);\r
- return;\r
- }\r
\r
- var httpStatus, responseObject;\r
+ var httpStatus, responseObject;\r
\r
- try {\r
- if (o.conn.status !== undefined && o.conn.status != 0) {\r
- httpStatus = o.conn.status;\r
- }\r
- else {\r
- httpStatus = 13030;\r
- }\r
+ try {\r
+ if (o.conn.status !== undefined && o.conn.status != 0) {\r
+ httpStatus = o.conn.status;\r
}\r
- catch(e) {\r
+ else {\r
httpStatus = 13030;\r
}\r
+ }\r
+ catch(e) {\r
+ httpStatus = 13030;\r
+ }\r
\r
- if ((httpStatus >= 200 && httpStatus < 300) || (Ext.isIE && httpStatus == 1223)) {\r
- responseObject = createResponseObject(o, callback.argument);\r
- if (callback.success) {\r
- if (!callback.scope) {\r
- callback.success(responseObject);\r
- }\r
- else {\r
- callback.success.apply(callback.scope, [responseObject]);\r
- }\r
+ if ((httpStatus >= 200 && httpStatus < 300) || (Ext.isIE && httpStatus == 1223)) {\r
+ responseObject = createResponseObject(o, callback.argument);\r
+ if (callback.success) {\r
+ if (!callback.scope) {\r
+ callback.success(responseObject);\r
+ }\r
+ else {\r
+ callback.success.apply(callback.scope, [responseObject]);\r
}\r
}\r
- else {\r
- switch (httpStatus) {\r
- case 12002:\r
- case 12029:\r
- case 12030:\r
- case 12031:\r
- case 12152:\r
- case 13030:\r
- responseObject = createExceptionObject(o.tId, callback.argument, (isAbort ? isAbort : false), isTimeout);\r
- if (callback.failure) {\r
- if (!callback.scope) {\r
- callback.failure(responseObject);\r
- }\r
- else {\r
- callback.failure.apply(callback.scope, [responseObject]);\r
- }\r
+ }\r
+ else {\r
+ switch (httpStatus) {\r
+ case 12002:\r
+ case 12029:\r
+ case 12030:\r
+ case 12031:\r
+ case 12152:\r
+ case 13030:\r
+ responseObject = createExceptionObject(o.tId, callback.argument, (isAbort ? isAbort : false), isTimeout);\r
+ if (callback.failure) {\r
+ if (!callback.scope) {\r
+ callback.failure(responseObject);\r
}\r
- break;\r
- default:\r
- responseObject = createResponseObject(o, callback.argument);\r
- if (callback.failure) {\r
- if (!callback.scope) {\r
- callback.failure(responseObject);\r
- }\r
- else {\r
- callback.failure.apply(callback.scope, [responseObject]);\r
- }\r
+ else {\r
+ callback.failure.apply(callback.scope, [responseObject]);\r
}\r
- }\r
+ }\r
+ break;\r
+ default:\r
+ responseObject = createResponseObject(o, callback.argument);\r
+ if (callback.failure) {\r
+ if (!callback.scope) {\r
+ callback.failure(responseObject);\r
+ }\r
+ else {\r
+ callback.failure.apply(callback.scope, [responseObject]);\r
+ }\r
+ }\r
}\r
+ }\r
\r
- releaseObject(o);\r
- responseObject = null;\r
- } \r
- \r
- // private\r
- function handleReadyState(o, callback){\r
- callback = callback || {};\r
- var conn = o.conn,\r
- tId = o.tId,\r
- poll = pub.poll,\r
- cbTimeout = callback.timeout || null;\r
-\r
- if (cbTimeout) {\r
- pub.timeout[tId] = setTimeout(function() {\r
- pub.abort(o, callback, true);\r
- }, cbTimeout);\r
- }\r
+ releaseObject(o);\r
+ responseObject = null;\r
+ } \r
+ \r
+ // private\r
+ function handleReadyState(o, callback){\r
+ callback = callback || {};\r
+ var conn = o.conn,\r
+ tId = o.tId,\r
+ poll = pub.poll,\r
+ cbTimeout = callback.timeout || null;\r
\r
- poll[tId] = setInterval(\r
- function() {\r
- if (conn && conn.readyState == 4) {\r
- clearInterval(poll[tId]);\r
- poll[tId] = null;\r
+ if (cbTimeout) {\r
+ pub.timeout[tId] = setTimeout(function() {\r
+ pub.abort(o, callback, true);\r
+ }, cbTimeout);\r
+ }\r
\r
- if (cbTimeout) {\r
- clearTimeout(pub.timeout[tId]);\r
- pub.timeout[tId] = null;\r
- }\r
+ poll[tId] = setInterval(\r
+ function() {\r
+ if (conn && conn.readyState == 4) {\r
+ clearInterval(poll[tId]);\r
+ poll[tId] = null;\r
\r
- handleTransactionResponse(o, callback);\r
+ if (cbTimeout) {\r
+ clearTimeout(pub.timeout[tId]);\r
+ pub.timeout[tId] = null;\r
}\r
- },\r
- pub.pollInterval);\r
- }\r
- \r
- // private\r
- function asyncRequest(method, uri, callback, postData) {\r
- var o = getConnectionObject() || null;\r
-\r
- if (o) {\r
- o.conn.open(method, uri, true);\r
\r
- if (pub.useDefaultXhrHeader) { \r
- initHeader('X-Requested-With', pub.defaultXhrHeader);\r
+ handleTransactionResponse(o, callback);\r
}\r
+ },\r
+ pub.pollInterval);\r
+ }\r
+ \r
+ // private\r
+ function asyncRequest(method, uri, callback, postData) {\r
+ var o = getConnectionObject() || null;\r
\r
- if(postData && pub.useDefaultHeader && (!pub.headers || !pub.headers[CONTENTTYPE])){\r
- initHeader(CONTENTTYPE, pub.defaultPostHeader);\r
- }\r
+ if (o) {\r
+ o.conn.open(method, uri, true);\r
\r
- if (pub.defaultHeaders || pub.headers) {\r
- setHeader(o);\r
- }\r
+ if (pub.useDefaultXhrHeader) { \r
+ initHeader('X-Requested-With', pub.defaultXhrHeader);\r
+ }\r
\r
- handleReadyState(o, callback);\r
- o.conn.send(postData || null);\r
+ if(postData && pub.useDefaultHeader && (!pub.headers || !pub.headers[CONTENTTYPE])){\r
+ initHeader(CONTENTTYPE, pub.defaultPostHeader);\r
}\r
- return o;\r
+\r
+ if (pub.defaultHeaders || pub.headers) {\r
+ setHeader(o);\r
+ }\r
+\r
+ handleReadyState(o, callback);\r
+ o.conn.send(postData || null);\r
}\r
- \r
- // private\r
- function getConnectionObject() {\r
- var o; \r
+ return o;\r
+ }\r
+ \r
+ // private\r
+ function getConnectionObject() {\r
+ var o; \r
\r
- try {\r
- if (o = createXhrObject(pub.transactionId)) {\r
- pub.transactionId++;\r
- }\r
- } catch(e) {\r
- } finally {\r
- return o;\r
+ try {\r
+ if (o = createXhrObject(pub.transactionId)) {\r
+ pub.transactionId++;\r
}\r
+ } catch(e) {\r
+ } finally {\r
+ return o;\r
}\r
- \r
- // private\r
- function createXhrObject(transactionId) {\r
- var http;\r
- \r
- try {\r
- http = new XMLHttpRequest(); \r
- } catch(e) {\r
- for (var i = 0; i < activeX.length; ++i) { \r
- try {\r
- http = new ActiveXObject(activeX[i]); \r
- break;\r
- } catch(e) {}\r
- }\r
- } finally {\r
- return {conn : http, tId : transactionId};\r
+ }\r
+ \r
+ // private\r
+ function createXhrObject(transactionId) {\r
+ var http;\r
+ \r
+ try {\r
+ http = new XMLHttpRequest(); \r
+ } catch(e) {\r
+ for (var i = 0; i < activeX.length; ++i) { \r
+ try {\r
+ http = new ActiveXObject(activeX[i]); \r
+ break;\r
+ } catch(e) {}\r
}\r
+ } finally {\r
+ return {conn : http, tId : transactionId};\r
}\r
- \r
- var pub = {\r
- request : function(method, uri, cb, data, options) {\r
- if(options){\r
- var me = this, \r
- xmlData = options.xmlData,\r
- jsonData = options.jsonData,\r
- hs;\r
- \r
- Ext.applyIf(me, options); \r
- \r
- if(xmlData || jsonData){\r
- hs = me.headers;\r
- if(!hs || !hs[CONTENTTYPE]){\r
- initHeader(CONTENTTYPE, xmlData ? 'text/xml' : 'application/json');\r
- }\r
- data = xmlData || (Ext.isObject(jsonData) ? Ext.encode(jsonData) : jsonData);\r
- }\r
- } \r
- return asyncRequest(method || options.method || "POST", uri, cb, data);\r
- },\r
- \r
- serializeForm : function(form) {\r
- var fElements = form.elements || (document.forms[form] || Ext.getDom(form)).elements,\r
- hasSubmit = false,\r
- encoder = encodeURIComponent,\r
- element,\r
- options, \r
- name, \r
- val, \r
- data = '',\r
- type;\r
- \r
- Ext.each(fElements, function(element) { \r
- name = element.name; \r
- type = element.type;\r
- \r
- if (!element.disabled && name){\r
- if(/select-(one|multiple)/i.test(type)){ \r
- Ext.each(element.options, function(opt) {\r
- if (opt.selected) {\r
- data += String.format("{0}={1}&", \r
- encoder(name), \r
- (opt.hasAttribute ? opt.hasAttribute('value') : opt.getAttributeNode('value').specified) ? opt.value : opt.text);\r
- } \r
- });\r
- } else if(!/file|undefined|reset|button/i.test(type)) {\r
- if(!(/radio|checkbox/i.test(type) && !element.checked) && !(type == 'submit' && hasSubmit)){\r
- \r
+ }\r
+ \r
+ var pub = {\r
+ request : function(method, uri, cb, data, options) {\r
+ if(options){\r
+ var me = this, \r
+ xmlData = options.xmlData,\r
+ jsonData = options.jsonData,\r
+ hs;\r
+ \r
+ Ext.applyIf(me, options); \r
+ \r
+ if(xmlData || jsonData){\r
+ hs = me.headers;\r
+ if(!hs || !hs[CONTENTTYPE]){\r
+ initHeader(CONTENTTYPE, xmlData ? 'text/xml' : 'application/json');\r
+ }\r
+ data = xmlData || (!Ext.isPrimitive(jsonData) ? Ext.encode(jsonData) : jsonData);\r
+ }\r
+ } \r
+ return asyncRequest(method || options.method || "POST", uri, cb, data);\r
+ },\r
+\r
+ serializeForm : function(form) {\r
+ var fElements = form.elements || (document.forms[form] || Ext.getDom(form)).elements,\r
+ hasSubmit = false,\r
+ encoder = encodeURIComponent,\r
+ element,\r
+ options, \r
+ name, \r
+ val, \r
+ data = '',\r
+ type;\r
+ \r
+ Ext.each(fElements, function(element) { \r
+ name = element.name; \r
+ type = element.type;\r
+ \r
+ if (!element.disabled && name){\r
+ if(/select-(one|multiple)/i.test(type)) {\r
+ Ext.each(element.options, function(opt) {\r
+ if (opt.selected) {\r
+ data += String.format("{0}={1}&", encoder(name), encoder((opt.hasAttribute ? opt.hasAttribute('value') : opt.getAttribute('value') !== null) ? opt.value : opt.text));\r
+ } \r
+ });\r
+ } else if(!/file|undefined|reset|button/i.test(type)) {\r
+ if(!(/radio|checkbox/i.test(type) && !element.checked) && !(type == 'submit' && hasSubmit)){\r
+ \r
data += encoder(name) + '=' + encoder(element.value) + '&'; \r
hasSubmit = /submit/i.test(type); \r
- } \r
- } \r
- }\r
- }); \r
- return data.substr(0, data.length - 1);\r
- },\r
- \r
- useDefaultHeader : true,\r
- defaultPostHeader : 'application/x-www-form-urlencoded; charset=UTF-8',\r
- useDefaultXhrHeader : true,\r
- defaultXhrHeader : 'XMLHttpRequest', \r
- poll : {},\r
- timeout : {},\r
- pollInterval : 50,\r
- transactionId : 0,\r
- \r
-// This is never called - Is it worth exposing this? \r
-// setProgId : function(id) {\r
-// activeX.unshift(id);\r
-// },\r
+ } \r
+ } \r
+ }\r
+ }); \r
+ return data.substr(0, data.length - 1);\r
+ },\r
+ \r
+ useDefaultHeader : true,\r
+ defaultPostHeader : 'application/x-www-form-urlencoded; charset=UTF-8',\r
+ useDefaultXhrHeader : true,\r
+ defaultXhrHeader : 'XMLHttpRequest', \r
+ poll : {},\r
+ timeout : {},\r
+ pollInterval : 50,\r
+ transactionId : 0,\r
+ \r
+// This is never called - Is it worth exposing this? \r
+// setProgId : function(id) {\r
+// activeX.unshift(id);\r
+// },\r
\r
-// This is never called - Is it worth exposing this? \r
-// setDefaultPostHeader : function(b) {\r
-// this.useDefaultHeader = b;\r
-// },\r
- \r
-// This is never called - Is it worth exposing this? \r
-// setDefaultXhrHeader : function(b) {\r
-// this.useDefaultXhrHeader = b;\r
-// },\r
+// This is never called - Is it worth exposing this? \r
+// setDefaultPostHeader : function(b) {\r
+// this.useDefaultHeader = b;\r
+// },\r
+ \r
+// This is never called - Is it worth exposing this? \r
+// setDefaultXhrHeader : function(b) {\r
+// this.useDefaultXhrHeader = b;\r
+// },\r
\r
-// This is never called - Is it worth exposing this? \r
-// setPollingInterval : function(i) {\r
-// if (typeof i == 'number' && isFinite(i)) {\r
-// this.pollInterval = i;\r
-// }\r
-// },\r
- \r
-// This is never called - Is it worth exposing this?\r
-// resetDefaultHeaders : function() {\r
-// this.defaultHeaders = null;\r
-// },\r
- \r
- abort : function(o, callback, isTimeout) {\r
- var me = this,\r
- tId = o.tId,\r
- isAbort = false;\r
- \r
- if (me.isCallInProgress(o)) {\r
- o.conn.abort();\r
- clearInterval(me.poll[tId]);\r
- me.poll[tId] = null;\r
- if (isTimeout) {\r
- me.timeout[tId] = null;\r
- }\r
- \r
- handleTransactionResponse(o, callback, (isAbort = true), isTimeout); \r
- }\r
- return isAbort;\r
- },\r
- \r
- isCallInProgress : function(o) {\r
- // if there is a connection and readyState is not 0 or 4\r
- return o.conn && !{0:true,4:true}[o.conn.readyState]; \r
- }\r
- };\r
- return pub;\r
+// This is never called - Is it worth exposing this? \r
+// setPollingInterval : function(i) {\r
+// if (typeof i == 'number' && isFinite(i)) {\r
+// this.pollInterval = i;\r
+// }\r
+// },\r
+ \r
+// This is never called - Is it worth exposing this?\r
+// resetDefaultHeaders : function() {\r
+// this.defaultHeaders = null;\r
+// },\r
+ \r
+ abort : function(o, callback, isTimeout) {\r
+ var me = this,\r
+ tId = o.tId,\r
+ isAbort = false;\r
+ \r
+ if (me.isCallInProgress(o)) {\r
+ o.conn.abort();\r
+ clearInterval(me.poll[tId]);\r
+ me.poll[tId] = null;\r
+ clearTimeout(pub.timeout[tId]);\r
+ me.timeout[tId] = null;\r
+ \r
+ handleTransactionResponse(o, callback, (isAbort = true), isTimeout); \r
+ }\r
+ return isAbort;\r
+ },\r
+ \r
+ isCallInProgress : function(o) {\r
+ // if there is a connection and readyState is not 0 or 4\r
+ return o.conn && !{0:true,4:true}[o.conn.readyState]; \r
+ }\r
+ };\r
+ return pub;\r
}();</pre> \r
</body>\r
</html>
\ No newline at end of file