国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

一個Ext2 SWFUpload做的圖片上傳對話框

2024-07-21 02:14:03
字體:
供稿:網(wǎng)友
一個Ext2 SWFUpload做的圖片上傳對話框的例程

我們先看看對話框的布局:

布局就是在一個窗口里內(nèi)嵌一個表格控件,窗口的底部工具條帶一個進(jìn)度條,表格的頂部工具條帶幾個操作按鈕和一個下來選擇框,底部工具條作為一個信息顯示區(qū)域顯示文件的總數(shù)和總的上傳大小。

我們來分析一下uploadDialog.js文件:

var Application = {};
Application.uploadDialog = {
    progressBarText: '正在上傳:{0},{1}%完成',
    statuBarText: '文件總數(shù):{0}個 ,大小:{1}',
    show: function(data) {
        if (!this.dialog) this.initDialog(); //this.uploadGrid.store.removeAll();
        if (data) this.classStore.loadData(data);
        this.uploadAction[0].enable();
        this.uploadAction[1].disable();
        this.uploadAction[2].disable();
        this.uploadAction[3].disable();
        this.uploadAction[4].enable(); //this.uploadProgressBar.updateProgress(0,'');
        this.dialog.show();
    },
    hide: function() {
        this.dialog.hide();
    },
    classStore: new Ext.data.SimpleStore({
        fields: ["id", "text"],
        data: []
    }),
    uploadAction: [new Ext.Action({
        text: '增加',
        handler: function() {
            Application.uploadDialog.swfu.selectFiles();
        }
    }), new Ext.Action({
        text: '刪除',
        disabled: true,
        handler: function() {
            var obj = Application.uploadDialog;
            var grid = obj.uploadGrid;
            var store = grid.store;
            var selection = grid.getSelectionModel().getSelections();
            for (var i = 0; i < selection.length; i) {
                var rec = store.getAt(store.indexOfId(selection[i].id));
                obj.swfu.cancelUpload(rec.data.id);
                store.remove(rec);
            }
            obj.stateInfo.getEl().innerHTML = String.format(obj.statuBarText, obj.uploadGrid.store.getCount(), Ext.util.Format.fileSize(obj.uploadGrid.store.sum('size')));
            if (obj.uploadGrid.store.getCount() == 0) {
                obj.uploadGrid.store.removeAll();
                obj.uploadAction[1].disable();
                obj.uploadAction[2].disable();
                obj.uploadAction[3].disable();
            }
        }
    }), new Ext.Action({
        text: '清空',
        disabled: true,
        handler: function() {
            var obj = Application.uploadDialog;
            var store = obj.uploadGrid.store;
            var len = store.getCount();
            for (var i = 0; i < len; i) {
                var rec = store.getAt(i);
                obj.swfu.cancelUpload(rec.data.id);
            }
            store.removeAll();
            obj.classCombo.clearValue();
            obj.stateInfo.getEl().innerHTML = String.format(obj.statuBarText, 0, Ext.util.Format.fileSize(0));
            obj.uploadProgressBar.updateProgress(0, '');
            obj.uploadProgressBar.updateText("");
            obj.uploadAction[0].enable();
            obj.uploadAction[1].disable();
            obj.uploadAction[2].disable();
            obj.uploadAction[3].disable();
        }
    }), new Ext.Action({
        text: '上傳',
        disabled: true,
        handler: function() {
            var obj = Application.uploadDialog;
            obj.uploadAction[0].disable();
            obj.uploadAction[1].disable();
            obj.uploadAction[2].disable();
            obj.uploadAction[3].disable();
            obj.uploadAction[4].disable();
            var store = obj.uploadGrid.store;
            var len = store.getCount();
            var classid = obj.classCombo.getValue();
            obj.swfu.setPostParams({
                'classid': classid
            });
            obj.swfu.startUpload();
        }
    }), new Ext.Action({
        text: '關(guān)閉',
        handler: function() {
            Application.uploadDialog.hide();
        }
    }), ],
    initDialog: function() {
        this.classCombo = new Ext.form.ComboBox({
            hiddenName: 'classid',
            name: 'classid_name',
            valueField: "id",
            displayField: "text",
            mode: 'local',
            store: this.classStore,
            blankText: '請選擇類別',
            emptyText: '請選擇類別',
            editable: true,
            anchor: '90%'
        }) this.swfu = new SWFUpload({
            upload_url: "upload.asp",
            file_size_limit: "102400",
            file_types: "*.jpg;*.gif",
            file_types_description: "圖片文件(*.jpg,*.gif)",
            file_upload_limit: "30",
            file_dialog_start_handler: this.fileDialogStart,
            file_queued_handler: this.fileQueued,
            file_queue_error_handler: this.uploadError,
            file_dialog_complete_handler: this.fileDialogComplete,
            upload_start_handler: this.uploadFileStar,
            upload_progress_handler: this.uploadProgress,
            upload_error_handler: this.uploadError,
            upload_complete_handler: this.uploadQueueComplete,
            file_complete_handler: this.uploadFileComplete,
            flash_url: "swfupload.swf",
            ui_container_id: "SWFUploadTarget",
            degraded_container_id: "divDegraded",
            debug: false
        }) this.dialog = new Ext.Window({
            layout: 'fit',
            width: 600,
            height: 500,
            title: '上傳圖片',
            closeAction: 'hide',
            border: false,
            modal: true,
            plain: true,
            closable: false,
            resizable: false,
            bbar: [this.uploadProgressBar = new Ext.ProgressBar({
                width: 586
            })],
            items: [Application.uploadDialog.uploadGrid = new Ext.grid.GridPanel({
                autoExpandColumn: 2,
                enableHdMenu: false,
                tbar: [Application.uploadDialog.uploadAction[0], Application.uploadDialog.uploadAction[1], Application.uploadDialog.uploadAction[2], '-', Application.uploadDialog.uploadAction[3], "-", Application.uploadDialog.classCombo, "->", Application.uploadDialog.uploadAction[4]],
                bbar: [Application.uploadDialog.stateInfo = new Ext.Toolbar.TextItem(String.format(Application.uploadDialog.statuBarText, 0, Ext.util.Format.fileSize(0)))],
                store: new Ext.data.SimpleStore({
                    fields: ["id", "state", "file", "size", "type"],
                    data: []
                }),
                columns: [new Ext.grid.RowNumberer(), {
                    id: 'id',
                    header: "id",
                    hidden: true,
                    width: 150,
                    dataIndex: 'id',
                    resizable: false,
                    sortable: false
                },
                {
                    header: "文件名",
                    width: Ext.grid.GridView.autoFill,
                    dataIndex: 'file',
                    sortable: true
                },
                {
                    header: "大小",
                    width: 80,
                    renderer: Ext.util.Format.fileSize,
                    dataIndex: 'size',
                    sortable: true,
                    align: 'right'
                },
                {
                    header: "類型",
                    width: 80,
                    dataIndex: 'type',
                    align: 'center',
                    sortable: true
                },
                {
                    header: "狀態(tài)",
                    width: 100,
                    dataIndex: 'state',
                    align: 'center',
                    sortable: true
                }]
            })]
        })
    },
    fileQueued: function(file) {
        var obj = Application.uploadDialog;
        var filetype = (file.type.substr(1)).toUpperCase();
        if (filetype == 'JPG' | filetype == 'GIF') {
            var data = [];
            data.push([file.id, '未上傳', file.name, file.size, filetype]);
            obj.uploadGrid.store.loadData(data, true);
            obj.uploadAction[1].enable();
            obj.uploadAction[2].enable();
            obj.uploadAction[3].enable();
            obj.stateInfo.getEl().innerHTML = String.format(obj.statuBarText, obj.uploadGrid.store.getCount(), Ext.util.Format.fileSize(obj.uploadGrid.store.sum('size')));
        }
    },
    uploadFileStar: function(file) {
        var obj = Application.uploadDialog;
        var index = obj.findData(file.id);
        if (index >= 0) {
            obj.uploadGrid.store.getAt(index).set('state', '正在上傳……');
        }
        obj.uploadProgressBar.updateProgress(0, String.format(obj.progressBarText, file.name, 0));
        return true;
    },
    uploadProgress: function(file, bytesloaded) {
        var obj = Application.uploadDialog
        var percent = Math.ceil((bytesloaded / file.size) * 100);
        obj.uploadProgressBar.updateProgress(percent / 100, String.format(obj.progressBarText, file.name, percent));
    },
    uploadFileComplete: function(file) {
        var obj = Application.uploadDialog;
        var index = obj.findData(file.id);
        if (index >= 0) {
            obj.uploadGrid.store.getAt(index).set('state', '已上傳');
        }
        if (obj.swfu.getStats().files_queued > 0) obj.swfu.startUpload();
    },
    uploadFileCancelled: function(file, queuelength) {},
    uploadQueueComplete: function(file, server_data) {
        console.log(server_data);
        if (server_data == 'ok') {
            var obj = Application.uploadDialog;
            obj.uploadProgressBar.updateProgress(1, '完成上傳');
            obj.uploadAction[2].enable();
            obj.uploadAction[4].enable();
        } else {
            alert(server_data);
        }
    },
    uploadError: function(file, errcode, msg) {
        var index = Application.uploadDialog.findData(file.id);
        if (index >= 0) Application.uploadDialog.uploadGrid.store.getAt(index).set('state', '上傳失敗'); //alert(errcode ',' file.name ',' msg)
    },
    uploadCancel: function(file, queuelength) {
        var index = Application.uploadDialog.findData(file.id);
        if (index >= 0) Application.uploadDialog.uploadGrid.store.getAt(index).set('state', '取消上傳');
    },
    fileDialogStart: function() {},
    fileDialogComplete: function(num_files_queued) {},
    findData: function(id) {
        var rowindex = Application.uploadDialog.uploadGrid.store.find('id', id);
        return rowindex;
    }
} //Application.uploadDialog

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 黎平县| 万源市| 敦化市| 隆林| 维西| 黑龙江省| 晴隆县| 若羌县| 高邑县| 青冈县| 湖口县| 和顺县| 嘉义市| 海兴县| 错那县| 南乐县| 卢龙县| 三门县| 嵩明县| 阿尔山市| 北安市| 池州市| 永定县| 清丰县| 霍邱县| 虞城县| 铁力市| 长岭县| 怀仁县| 西宁市| 陆丰市| 上杭县| 荥经县| 南涧| 瓦房店市| 东兰县| 蓝山县| 青神县| 天水市| 阆中市| 宿迁市|