3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
16 * Portions of this file are based on pieces of Yahoo User Interface Library
17 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
18 * YUI licensed under the BSD License:
19 * http://developer.yahoo.net/yui/license.txt
21 Ext.lib.Ajax = function() {
22 var activeX = ['Msxml2.XMLHTTP.6.0',
25 CONTENTTYPE = 'Content-Type';
28 function setHeader(o) {
33 function setTheHeaders(conn, headers){
34 for (prop in headers) {
35 if (headers.hasOwnProperty(prop)) {
36 conn.setRequestHeader(prop, headers[prop]);
41 Ext.apply(headers, pub.headers, pub.defaultHeaders);
42 setTheHeaders(conn, headers);
47 function createExceptionObject(tId, callbackArg, isAbort, isTimeout) {
50 status : isAbort ? -1 : 0,
51 statusText : isAbort ? 'transaction aborted' : 'communication failure',
54 argument : callbackArg
59 function initHeader(label, value) {
60 (pub.headers = pub.headers || {})[label] = value;
64 function createResponseObject(o, callbackArg) {
70 // see: https://prototype.lighthouseapp.com/projects/8886/tickets/129-ie-mangles-http-response-status-code-204-to-1223
71 isBrokenStatus = conn.status == 1223;
74 headerStr = o.conn.getAllResponseHeaders();
75 Ext.each(headerStr.replace(/\r\n/g, '\n').split('\n'), function(v){
78 s = v.substr(0, t).toLowerCase();
79 if(v.charAt(t + 1) == ' '){
82 headerObj[s] = v.substr(t + 1);
89 // Normalize the status and statusText when IE returns 1223, see the above link.
90 status : isBrokenStatus ? 204 : conn.status,
91 statusText : isBrokenStatus ? 'No Content' : conn.statusText,
92 getResponseHeader : function(header){return headerObj[header.toLowerCase()];},
93 getAllResponseHeaders : function(){return headerStr;},
94 responseText : conn.responseText,
95 responseXML : conn.responseXML,
96 argument : callbackArg
101 function releaseObject(o) {
103 pub.conn[o.tId] = null;
110 function handleTransactionResponse(o, callback, isAbort, isTimeout) {
116 var httpStatus, responseObject;
119 if (o.conn.status !== undefined && o.conn.status != 0) {
120 httpStatus = o.conn.status;
130 if ((httpStatus >= 200 && httpStatus < 300) || (Ext.isIE && httpStatus == 1223)) {
131 responseObject = createResponseObject(o, callback.argument);
132 if (callback.success) {
133 if (!callback.scope) {
134 callback.success(responseObject);
137 callback.success.apply(callback.scope, [responseObject]);
142 switch (httpStatus) {
149 responseObject = createExceptionObject(o.tId, callback.argument, (isAbort ? isAbort : false), isTimeout);
150 if (callback.failure) {
151 if (!callback.scope) {
152 callback.failure(responseObject);
155 callback.failure.apply(callback.scope, [responseObject]);
160 responseObject = createResponseObject(o, callback.argument);
161 if (callback.failure) {
162 if (!callback.scope) {
163 callback.failure(responseObject);
166 callback.failure.apply(callback.scope, [responseObject]);
173 responseObject = null;
176 function checkResponse(o, callback, conn, tId, poll, cbTimeout){
177 if (conn && conn.readyState == 4) {
178 clearInterval(poll[tId]);
182 clearTimeout(pub.timeout[tId]);
183 pub.timeout[tId] = null;
185 handleTransactionResponse(o, callback);
189 function checkTimeout(o, callback){
190 pub.abort(o, callback, true);
195 function handleReadyState(o, callback){
196 callback = callback || {};
200 cbTimeout = callback.timeout || null;
203 pub.conn[tId] = conn;
204 pub.timeout[tId] = setTimeout(checkTimeout.createCallback(o, callback), cbTimeout);
206 poll[tId] = setInterval(checkResponse.createCallback(o, callback, conn, tId, poll, cbTimeout), pub.pollInterval);
210 function asyncRequest(method, uri, callback, postData) {
211 var o = getConnectionObject() || null;
214 o.conn.open(method, uri, true);
216 if (pub.useDefaultXhrHeader) {
217 initHeader('X-Requested-With', pub.defaultXhrHeader);
220 if(postData && pub.useDefaultHeader && (!pub.headers || !pub.headers[CONTENTTYPE])){
221 initHeader(CONTENTTYPE, pub.defaultPostHeader);
224 if (pub.defaultHeaders || pub.headers) {
228 handleReadyState(o, callback);
229 o.conn.send(postData || null);
235 function getConnectionObject() {
239 if (o = createXhrObject(pub.transactionId)) {
249 function createXhrObject(transactionId) {
253 http = new XMLHttpRequest();
255 for (var i = 0; i < activeX.length; ++i) {
257 http = new ActiveXObject(activeX[i]);
262 return {conn : http, tId : transactionId};
267 request : function(method, uri, cb, data, options) {
270 xmlData = options.xmlData,
271 jsonData = options.jsonData,
274 Ext.applyIf(me, options);
276 if(xmlData || jsonData){
278 if(!hs || !hs[CONTENTTYPE]){
279 initHeader(CONTENTTYPE, xmlData ? 'text/xml' : 'application/json');
281 data = xmlData || (!Ext.isPrimitive(jsonData) ? Ext.encode(jsonData) : jsonData);
284 return asyncRequest(method || options.method || "POST", uri, cb, data);
287 serializeForm : function(form) {
288 var fElements = form.elements || (document.forms[form] || Ext.getDom(form)).elements,
290 encoder = encodeURIComponent,
296 Ext.each(fElements, function(element){
300 if (!element.disabled && name) {
301 if (/select-(one|multiple)/i.test(type)) {
302 Ext.each(element.options, function(opt){
304 hasValue = opt.hasAttribute ? opt.hasAttribute('value') : opt.getAttributeNode('value').specified;
305 data += String.format("{0}={1}&", encoder(name), encoder(hasValue ? opt.value : opt.text));
308 } else if (!(/file|undefined|reset|button/i.test(type))) {
309 if (!(/radio|checkbox/i.test(type) && !element.checked) && !(type == 'submit' && hasSubmit)) {
310 data += encoder(name) + '=' + encoder(element.value) + '&';
311 hasSubmit = /submit/i.test(type);
316 return data.substr(0, data.length - 1);
319 useDefaultHeader : true,
320 defaultPostHeader : 'application/x-www-form-urlencoded; charset=UTF-8',
321 useDefaultXhrHeader : true,
322 defaultXhrHeader : 'XMLHttpRequest',
329 // This is never called - Is it worth exposing this?
330 // setProgId : function(id) {
331 // activeX.unshift(id);
334 // This is never called - Is it worth exposing this?
335 // setDefaultPostHeader : function(b) {
336 // this.useDefaultHeader = b;
339 // This is never called - Is it worth exposing this?
340 // setDefaultXhrHeader : function(b) {
341 // this.useDefaultXhrHeader = b;
344 // This is never called - Is it worth exposing this?
345 // setPollingInterval : function(i) {
346 // if (typeof i == 'number' && isFinite(i)) {
347 // this.pollInterval = i;
351 // This is never called - Is it worth exposing this?
352 // resetDefaultHeaders : function() {
353 // this.defaultHeaders = null;
356 abort : function(o, callback, isTimeout) {
361 if (me.isCallInProgress(o)) {
363 clearInterval(me.poll[tId]);
365 clearTimeout(pub.timeout[tId]);
366 me.timeout[tId] = null;
368 handleTransactionResponse(o, callback, (isAbort = true), isTimeout);
373 isCallInProgress : function(o) {
374 // if there is a connection and readyState is not 0 or 4
375 return o.conn && !{0:true,4:true}[o.conn.readyState];