uploader-flash.js revision 9b1ad7c4722db362bee7d39c851c94ba95f118b8
/**
* This module provides a UI for file selection and multiple file upload capability using
* Flash as a transport engine.
* The supported features include: automatic upload queue management, upload progress
* tracking, server response retrieval and error reporting.
*
* @module uploader-flash
*/
var substitute = Y.substitute,
/**
* This module provides a UI for file selection and multiple file upload capability
* using Flash as a transport engine.
* @class UploaderFlash
* @extends Widget
* @constructor
*/
function UploaderFlash(config) {
}
/**
* Stored reference to the instance of SWF used to host the
* Flash uploader.
*
* @property _swfReference
* @type {SWF}
* @protected
*/
_swfReference: null,
/**
* Stored reference to the instance of Uploader.Queue used to manage
* the upload process.
*
* @property _uploaderQueue
* @type {Y.Uploader.Queue}
* @protected
*/
_uploaderQueue: null,
/**
* Stored value of the unique id for the container that holds the
* Flash uploader.
*
* @property _swfContainerId
* @type {String}
* @protected
*/
_swfContainerId: null,
// Y.UploaderFlash prototype
/**
* Construction logic executed during UploaderFlash instantiation.
*
* @method initializer
* @protected
*/
initializer : function () {
// Assign a unique id for the SWF container
// Publish available events
this.publish("fileselect");
this.publish("uploadstart");
this.publish("fileuploadstart");
this.publish("uploadprogress");
this.publish("totaluploadprogress");
this.publish("uploadcomplete");
this.publish("alluploadscomplete");
this.publish("uploaderror");
},
/**
* Handles and retransmits events fired by `Y.File` and `Y.Uploader.Queue`.
*
* @method _uploadEventHandler
* @param event The event dispatched during the upload process.
* @private
*/
_uploadEventHandler : function (event) {
case "file:uploadstart":
break;
case "file:uploadprogress":
break;
case "uploaderqueue:totaluploadprogress":
break;
case "file:uploadcomplete":
break;
case "uploaderqueue:alluploadscomplete":
break;
case "uploaderqueue:uploaderror":
}
},
/**
* Syncs the state of the `multipleFiles` attribute between this class
* and the Flash uploader.
*
* @method _setMultipleFiles
* @private
*/
_setMultipleFiles : function () {
if (this._swfReference) {
}
},
/**
* Syncs the state of the `fileFilters` attribute between this class
* and the Flash uploader.
*
* @method _setFileFilters
* @private
*/
_setFileFilters : function () {
}
},
/**
* Adjusts the content of the `fileList` based on the results of file selection
* and the `appendNewFiles` attribute. If the `appendNewFiles` attribute is true,
* then selected files are appended to the existing list; otherwise, the list is
* cleared and populated with the newly selected files.
*
* @method _updateFileList
* @param ev {Event} The file selection event received from the uploader.
* @private
*/
_updateFileList : function (ev) {
fileConfObjects = [],
parsedFiles = [],
swfRef = this._swfReference;
var newFileConf = {};
});
});
this.set("fileList",
},
/**
* Create the DOM structure for the UploaderFlash.
* UploaderFlash's DOM structure consists of two layers: the base "Select Files"
* button that can be replaced by the developer's widget of choice; and a transparent
* Flash overlay positoned above the button that captures all input events.
*
* @method renderUI
* @protected
*/
renderUI : function () {
{swfContainerId: this._swfContainerId})));
allowScriptAccess:"always",
allowNetworking:"all",
scale: "noscale"},
};
},
/**
* Binds to the UploaderFlash UI and subscribes to the necessary events.
* The binding is set to occur once the Flash player instance is ready
* (as indicated by the `swfReady` event.)
*
* @method bindUI
* @protected
*/
bindUI : function () {
this._setMultipleFiles();
this._setFileFilters();
}, this);
},
/**
* Starts the upload of a specific file.
*
* @method upload
* @param file {Y.File} Reference to the instance of the file to be uploaded.
* @param url {String} The URL to upload the file to.
* @param postVars {Object} (optional) A set of key-value pairs to send as variables along with the file upload HTTP request.
* If not specified, the values from the attribute `postVarsPerFile` are used instead.
*/
}
},
/**
* Starts the upload of all files on the file list, using an automated queue.
*
* @method uploadAll
* @param url {String} The URL to upload the files to.
* @param postVars {Object} (optional) A set of key-value pairs to send as variables along with the file upload HTTP request.
* If not specified, the values from the attribute `postVarsPerFile` are used instead.
*/
},
/**
* Starts the upload of the files specified in the first argument, using an automated queue.
*
* @method uploadThese
* @param files {Array} The list of files to upload.
* @param url {String} The URL to upload the files to.
* @param postVars {Object} (optional) A set of key-value pairs to send as variables along with the file upload HTTP request.
* If not specified, the values from the attribute `postVarsPerFile` are used instead.
*/
});
this._uploaderQueue.startUpload();
this.fire("uploadstart");
}
},
{
/**
* The template for the Flash player container. Since the Flash player container needs
* to completely overlay the &lquot;Select Files&rqot; control, it's positioned absolutely,
* with width and height set to 100% of the parent.
*
* @property FLASH_CONTAINER
* @type {String}
* @static
*/
FLASH_CONTAINER: "<div id='{swfContainerId}' style='position:absolute; top:0px; left: 0px; width:100%; height:100%'></div>",
/**
* The identity of the widget.
*
* @property NAME
* @type String
* @default 'uploaderflash'
* @readOnly
* @protected
* @static
*/
NAME: "uploader",
/**
* Static property used to define the default attribute configuration of
* the Widget.
*
* @property ATTRS
* @type {Object}
* @protected
* @static
*/
ATTRS: {
errorAction: {
value: "continue",
return (val === UploaderQueue.CONTINUE || val === UploaderQueue.STOP || val === UploaderQueue.RESTART_ASAP || val === UploaderQueue.RESTART_AFTER); }
},
/**
* The widget that serves as the &lquot;Select Files&rquot; control for the file uploader
*
*
* @attribute selectFilesButton
* @type {Node | Widget}
* @default A standard HTML button.
*/
},
/**
* A Boolean indicating whether multiple file selection is enabled.
*
* @attribute multipleFiles
* @type {Boolean}
* @default false
*/
value: false
},
/**
* An array indicating what fileFilters should be applied to the file
* selection dialog. Each element in the array should be an object with
* the following key-value pairs:
* {
* description : String
extensions: String of the form &lquot;*.ext1;*.ext2;*.ext3;...&rquot;
* }
* @attribute fileFilters
* @type {Array}
* @default null
*/
fileFilters: {
value: null
},
/**
* A String specifying what should be the POST field name for the file
* content in the upload request.
*
* @attribute fileFieldName
* @type {String}
* @default Filedata
*/
value: "Filedata"
},
/**
* A Boolean indicating whether newly selected files should be appended
* to the existing file list, or whether they should replace it.
*
* @attribute appendNewFiles
* @type {Boolean}
* @default true
*/
appendNewFiles : {
value: true
},
/**
* The number of files that can be uploaded
* simultaneously if the automatic queue management
* is used. This value can be in the range between 2
* and 5.
*
* @attribute simLimit
* @type {Number}
* @default 2
*/
simLimit: {
value: 2,
}
},
/**
* The array of files to be uploaded. All elements in the array
* must be instances of `Y.File` and be instantiated with a `fileId`
* retrieved from an instance of the uploader.
*
* @attribute fileList
* @type {Array}
* @default []
*/
fileList: {
value: []
},
/**
* An object, keyed by `fileId`, containing sets of key-value pairs
* that should be passed as POST variables along with each corresponding
* file. This attribute is only used if no POST variables are specifed
* in the upload request (only possible when calling the `upload()` method.
*
* @attribute postVarsPerFile
* @type {Object}
* @default {}
*/
value: {}
},
/**
* The URL to POST the file upload requests to.
*
* @attribute uploadURL
* @type {String}
* @default ""
*/
uploadURL: {
value: ""
},
/**
* The URL to the SWF file of the flash uploader. A copy local to
* the server that hosts the page on which the uploader appears is
* recommended.
*
* @attribute swfURL
* @type {String}
* @default "CDN Prefix + assets/flashuploader.swf"
*/
swfURL: {
}
}
});