io-upload-iframe-debug.js revision 4f97e98455707a2c69c49b2134d474e6d72f07aa
/**
Extends the IO to enable file uploads, with HTML forms
using an iframe as the transport medium.
@module io-base
@submodule io-upload-iframe
@for IO
**/
/**
* Creates the iframe transported used in file upload
* transactions, and binds the response event handler.
*
* @method _cFrame
* @private
* @param {Object} o Transaction object generated by _create().
* @param {Object} c Configuration object passed to YUI.io().
* @param {Object} io
*/
var i = Y.Node.create('<iframe src="#" id="io_iframe' + o.id + '" name="io_iframe' + o.id + '" />');
// Bind the onload handler to the iframe to detect the file upload response.
}
/**
* Removes the iframe transport used in the file upload
* transaction.
*
* @method _dFrame
* @private
* @param {Number} id The transaction ID used in the iframe's creation.
*/
}
/**
* Parses the POST data object and creates hidden form elements
* for each key-value, and appends them to the HTML form object.
* @method appendData
* @private
* @static
* @param {Object} f HTML form object.
* @param {String} s The key-value POST data.
* @return {Array} o Array of created fields.
*/
_addData: function(f, s) {
// Serialize an object into a key-value string using
// querystring-stringify-simple.
s = Y.QueryString.stringify(s);
}
var o = [],
m = s.split('='),
i, l;
o[i] = d.createElement('input');
o[i].type = 'hidden';
f.appendChild(o[i]);
}
return o;
},
/**
* Removes the custom fields created to pass additional POST
* data, along with the HTML form fields.
* @method _removeData
* @private
* @static
* @param {Object} f HTML form object.
* @param {Object} o HTML form fields created from configuration.data.
*/
_removeData: function(f, o) {
var i, l;
for (i = 0, l = o.length; i < l; i++) {
f.removeChild(o[i]);
}
},
/**
* Sets the appropriate attributes and values to the HTML
* form, in preparation of a file upload transaction.
* @method _setAttrs
* @private
* @static
* @param {Object} f HTML form object.
* @param {Object} id The Transaction ID.
* @param {Object} uri Qualified path to transaction resource.
*/
},
/**
* Reset the HTML form attributes to their original values.
* @method _resetAttrs
* @private
* @static
* @param {Object} f HTML form object.
* @param {Object} a Object of original attributes.
*/
_resetAttrs: function(f, a) {
Y.Object.each(a, function(v, p) {
if (v) {
f.setAttribute(p, v);
}
else {
f.removeAttribute(p);
}
});
},
/**
* Starts timeout count if the configuration object
* has a defined timeout property.
*
* @method _startUploadTimeout
* @private
* @static
* @param {Object} o Transaction object generated by _create().
* @param {Object} c Configuration object passed to YUI.io().
*/
_startUploadTimeout: function(o, c) {
var io = this;
function() {
o.status = 0;
o.statusText = 'timeout';
}, c.timeout);
},
/**
* Clears the timeout interval started by _startUploadTimeout().
* @method _clearUploadTimeout
* @private
* @static
* @param {Number} id - Transaction ID.
*/
_clearUploadTimeout: function(id) {
var io = this;
},
/**
* Bound to the iframe's Load event and processes
* the response data.
* @method _uploadComplete
* @private
* @static
* @param {Object} o The transaction object
* @param {Object} c Configuration object for the transaction.
*/
_uploadComplete: function(o, c) {
var io = this,
b = d.one('body'),
p;
if (c.timeout) {
}
try {
if (b) {
// will wrap the response string with <pre></pre>.
p = b.one('pre:first-child');
Y.log('The responseText value for transaction ' + o.id + ' is: ' + o.c.responseText + '.', 'info', 'io');
}
else {
o.c.responseXML = d._node;
}
}
catch (e) {
o.e = "upload failure";
}
// The transaction is complete, so call _dFrame to remove
// the event listener bound to the iframe transport, and then
// destroy the iframe.
},
/**
* Uploads HTML form data, inclusive of files/attachments,
* using the iframe created in _create to facilitate the transaction.
* @method _upload
* @private
* @static
* @param {Object} o The transaction object
* @param {Object} uri Qualified path to transaction resource.
* @param {Object} c Configuration object for the transaction.
*/
var io = this,
// Track original HTML form attribute values.
attr = {
},
// Initialize the HTML form properties in case they are
// not defined in the HTML form.
if (c.data) {
}
// Start polling if a callback is present and the timeout
// property has been defined.
if (c.timeout) {
io._startUploadTimeout(o, c);
}
// Start file upload.
f.submit();
if (c.data) {
}
// Restore HTML form attributes to their original values.
return {
abort: function() {
o.status = 0;
o.statusText = 'abort';
}
else {
return false;
}
},
isInProgress: function() {
},
};
},
_cFrame(o, c, this);
}
});