Index: openacs-4/packages/ajaxhelper/www/resources/yui/connection/connection.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajaxhelper/www/resources/yui/connection/connection.js,v diff -u -r1.1 -r1.2 --- openacs-4/packages/ajaxhelper/www/resources/yui/connection/connection.js 21 Oct 2006 06:14:56 -0000 1.1 +++ openacs-4/packages/ajaxhelper/www/resources/yui/connection/connection.js 25 Dec 2006 16:40:01 -0000 1.2 @@ -2,21 +2,27 @@ Copyright (c) 2006, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.net/yui/license.txt -Version: 0.11.3 +version: 0.12.1 */ /** + * @description * The Connection Manager provides a simplified interface to the XMLHttpRequest * object. It handles cross-browser instantiantion of XMLHttpRequest, negotiates the * interactive states and server response, returning the results to a pre-defined * callback you create. - * @ class + * + * @namespace YAHOO.util + * @module Connection + * @Class Connect */ YAHOO.util.Connect = { -/** - * Array of MSFT ActiveX ids for XMLHttpRequest. + /** + * @description Array of MSFT ActiveX ids for XMLHttpRequest. + * @property _msxml_progid * @private + * @static * @type array */ _msxml_progid:[ @@ -26,107 +32,133 @@ ], /** - * Object literal of HTTP header(s) + * @description Object literal of HTTP header(s) + * @property _http_header * @private + * @static * @type object */ _http_header:{}, /** - * Determines if HTTP headers are set. + * @description Determines if HTTP headers are set. + * @property _has_http_headers * @private + * @static * @type boolean */ _has_http_headers:false, /** - * Determines if a default header of + * @description Determines if a default header of * Content-Type of 'application/x-www-form-urlencoded' * will be added to any client HTTP headers sent for POST * transactions. + * @property _use_default_post_header * @private + * @static * @type boolean */ _use_default_post_header:true, /** - * Determines if a default header of + * @description Determines if a default header of * Content-Type of 'application/x-www-form-urlencoded' * will be added to any client HTTP headers sent for POST * transactions. + * @property _default_post_header * @private + * @static * @type boolean */ _default_post_header:'application/x-www-form-urlencoded', /** - * Property modified by setForm() to determine if the data + * @description Property modified by setForm() to determine if the data * should be submitted as an HTML form. + * @property _isFormSubmit * @private + * @static * @type boolean */ _isFormSubmit:false, /** - * Property modified by setForm() to determine if a file(s) + * @description Property modified by setForm() to determine if a file(s) * upload is expected. + * @property _isFileUpload * @private + * @static * @type boolean */ _isFileUpload:false, /** - * Property modified by setForm() to set a reference to the HTML + * @description Property modified by setForm() to set a reference to the HTML * form node if the desired action is file upload. + * @property _formNode * @private + * @static * @type object */ _formNode:null, /** - * Property modified by setForm() to set the HTML form data + * @description Property modified by setForm() to set the HTML form data * for each transaction. + * @property _sFormData * @private + * @static * @type string */ _sFormData:null, /** - * Collection of polling references to the polling mechanism in handleReadyState. + * @description Collection of polling references to the polling mechanism in handleReadyState. + * @property _poll * @private + * @static * @type object */ _poll:{}, /** - * Queue of timeout values for each transaction callback with a defined timeout value. + * @description Queue of timeout values for each transaction callback with a defined timeout value. + * @property _timeOut * @private + * @static * @type object */ _timeOut:{}, /** - * The polling frequency, in milliseconds, for HandleReadyState. + * @description The polling frequency, in milliseconds, for HandleReadyState. * when attempting to determine a transaction's XHR readyState. * The default is 50 milliseconds. + * @property _polling_interval * @private + * @static * @type int */ _polling_interval:50, /** - * A transaction counter that increments the transaction id for each transaction. + * @description A transaction counter that increments the transaction id for each transaction. + * @property _transaction_id * @private + * @static * @type int */ _transaction_id:0, /** - * Member to add an ActiveX id to the existing xml_progid array. + * @description Member to add an ActiveX id to the existing xml_progid array. * In the event(unlikely) a new ActiveX id is introduced, it can be added * without internal code modifications. + * @method setProgId * @public - * @param string id The ActiveX id to be added to initialize the XHR object. + * @static + * @param {string} id The ActiveX id to be added to initialize the XHR object. * @return void */ setProgId:function(id) @@ -135,9 +167,11 @@ }, /** - * Member to enable or disable the default POST header. + * @description Member to enable or disable the default POST header. + * @method setDefaultPostHeader * @public - * @param boolean b Set and use default header - true or false . + * @static + * @param {boolean} b Set and use default header - true or false . * @return void */ setDefaultPostHeader:function(b) @@ -146,8 +180,10 @@ }, /** - * Member to modify the default polling interval. + * @description Member to modify the default polling interval. + * @method setPollingInterval * @public + * @static * @param {int} i The polling interval in milliseconds. * @return void */ @@ -159,11 +195,13 @@ }, /** - * Instantiates a XMLHttpRequest object and returns an object with two properties: + * @description Instantiates a XMLHttpRequest object and returns an object with two properties: * the XMLHttpRequest instance and the transaction id. + * @method createXhrObject * @private + * @static * @param {int} transactionId Property containing the transaction id for this transaction. - * @return connection object + * @return object */ createXhrObject:function(transactionId) { @@ -182,7 +220,7 @@ { // Instantiates XMLHttpRequest for IE and assign to http. http = new ActiveXObject(this._msxml_progid[i]); - // Object literal with http and tId properties + // Object literal with conn and tId properties obj = { conn:http, tId:transactionId }; break; } @@ -196,11 +234,13 @@ }, /** - * This method is called by asyncRequest to create a + * @description This method is called by asyncRequest to create a * valid connection object for the transaction. It also passes a * transaction id and increments the transaction id counter. + * @method getConnectionObject * @private - * @return object + * @static + * @return {object} */ getConnectionObject:function() { @@ -222,11 +262,13 @@ }, /** - * Method for initiating an asynchronous request via the XHR object. + * @description Method for initiating an asynchronous request via the XHR object. + * @method asyncRequest * @public + * @static * @param {string} method HTTP transaction method * @param {string} uri Fully qualified path of resource - * @param callback User-defined callback function or object + * @param {callback} callback User-defined callback function or object * @param {string} postData POST body * @return {object} Returns the connection object */ @@ -240,31 +282,38 @@ else{ if(this._isFormSubmit){ if(this._isFileUpload){ - this.uploadFile(o.tId, callback, uri); + this.uploadFile(o.tId, callback, uri, postData); this.releaseObject(o); + return; } //If the specified HTTP method is GET, setForm() will return an //encoded string that is concatenated to the uri to //create a querystring. if(method == 'GET'){ - uri += "?" + this._sFormData; + if(this._sFormData.length != 0){ + // If the URI already contains a querystring, append an ampersand + // and then concatenate _sFormData to the URI. + uri += ((uri.indexOf('?') == -1)?'?':'&') + this._sFormData; + } + else{ + uri += "?" + this._sFormData; + } } else if(method == 'POST'){ - //If POST data exists in addition to the HTML form data, + //If POST data exist in addition to the HTML form data, //it will be concatenated to the form data. - postData = (postData?this._sFormData + "&" + postData:this._sFormData); + postData = postData?this._sFormData + "&" + postData:this._sFormData; } - this._sFormData = ''; } o.conn.open(method, uri, true); if(this._isFormSubmit || (postData && this._use_default_post_header)){ this.initHeader('Content-Type', this._default_post_header); if(this._isFormSubmit){ - this._isFormSubmit = false; + this.resetFormState(); } } @@ -273,26 +322,26 @@ } this.handleReadyState(o, callback); - o.conn.send(postData?postData:null); + o.conn.send(postData || null); return o; } }, /** - * This method serves as a timer that polls the XHR object's readyState + * @description This method serves as a timer that polls the XHR object's readyState * property during a transaction, instead of binding a callback to the * onreadystatechange event. Upon readyState 4, handleTransactionResponse * will process the response, and the timer will be cleared. - * + * @method handleReadyState * @private + * @static * @param {object} o The connection object - * @param callback User-defined callback object - * @return void + * @param {callback} callback The user-defined callback object + * @return {void} */ handleReadyState:function(o, callback) { - var oConn = this; if(callback && callback.timeout){ @@ -316,15 +365,16 @@ }, /** - * This method attempts to interpret the server response and + * @description This method attempts to interpret the server response and * determine whether the transaction was successful, or if an error or * exception was encountered. - * + * @method handleTransactionResponse * @private + * @static * @param {object} o The connection object - * @param {object} callback - User-defined callback object - * @param {boolean} determines if the transaction was aborted. - * @return void + * @param {object} callback The sser-defined callback object + * @param {boolean} isAbort Determines if the transaction was aborted. + * @return {void} */ handleTransactionResponse:function(o, callback, isAbort) { @@ -373,7 +423,7 @@ try { switch(httpStatus){ - // The following case labels are wininet.dll error codes that may be encountered. + // The following cases are wininet.dll error codes that may be encountered. case 12002: // Server timeout case 12029: // 12029 to 12031 correspond to dropped connections. case 12030: @@ -410,13 +460,15 @@ }, /** - * This method evaluates the server response, creates and returns the results via + * @description This method evaluates the server response, creates and returns the results via * its properties. Success and failure cases will differ in the response * object's property values. + * @method createResponseObject * @private + * @static * @param {object} o The connection object - * @param {} callbackArg User-defined argument or arguments to be passed to the callback - * @return object + * @param {callbackArg} callbackArg The user-defined argument or arguments to be passed to the callback + * @return {object} */ createResponseObject:function(o, callbackArg) { @@ -427,10 +479,10 @@ { var headerStr = o.conn.getAllResponseHeaders(); var header = headerStr.split('\n'); - for(var i=0; i < header.length; i++){ + for(var i=0; i'); + var io = document.createElement('