Ext.define('Ext.ux.multiupload.Upload', {
    extend: 'Ext.flash.Component',
    requires: [
        'Ext.ux.multiupload.UploadManager'
    ],
    alias: 'widget.uploader',
    width: 78,
    height: 22,
    wmode: 'transparent',
    url: '/Common/DMZ/JS/Extjs/4.2.1/ux/multiupload/Upload.swf',
    statics: {
        instanceId: 0
    },
    constructor: function (config) {
        config = config || {};
        config.instanceId = Ext.String.format('upload-{0}', ++Ext.ux.multiupload.Upload.instanceId);
        config.flashVars = config.flashVars || {};
        config.flashVars = Ext.apply({
            instanceId: config.instanceId,
            buttonImagePath: '/Common/DMZ/JS/Extjs/4.2.1/ux/multiupload/button.png',
            buttonImageHoverPath: '/Common/DMZ/JS/Extjs/4.2.1/ux/multiupload/button_hover.png',
            fileFilters: 'Images (*.jpg)|*.jpg',
            uploadUrl: '/upload/url',
            maxFileSize: 0,
            maxQueueLength: 0,
            maxQueueSize: 0,
            tempPath: "c:\\temp",
            callback: 'Ext.ux.multiupload.UploadManager.uploadCallback'
        }, config.uploadConfig);

        //config.flashVars.uploadUrl = config.flashVars.Url + "?vars={'panelId':'" + config.uploadConfig.panelId + "','instanceId':'" + config.instanceId + "','tempPath':'" + config.flashVars.tempPath + "'}";
        config.flashVars.uploadUrl = config.flashVars.Url + "?vars={'panelId':'" + config.uploadConfig.panelId + "','instanceId':'" + config.instanceId + "','tempPath':'" + config.flashVars.tempPath + "'}";

        this.addEvents(
            'fileadded',
            'uploadstart',
            'uploadprogress',
            'uploadcomplete',
            'uploaddatacomplete',
            'queuecomplete',
            'queuedatacomplete',
            'uploaderror'
        );

        this.callParent([config]);
    },
    initComponent: function () {
        Ext.ux.multiupload.UploadManager.register(this);
        this.callParent(arguments);
    },
    onDestroy: function () {
        Ext.ux.multiupload.UploadManager.unregister(this);
        this.callParent(arguments);
    }
});
