1. 程式人生 > >EXT.JS2.2表單上傳檔案

EXT.JS2.2表單上傳檔案

var uploadFile = new Ext.form.TextField({
            fieldLabel: '上傳檔案',
            id:'file',
            name: 'uploadFile',
            height : 25,
            width : 860,
            blankText: '請上傳檔案',
            itemCls:'float-left',
            clearCls : 'allow-float',
            inputType: 'file',
            validator:function (v) {
                if(!/\.xls$/.test(v)){
                    return false;
                }
                hasFile = v;
                return true;
            }
        });

        var form_q = new Ext.form.FormPanel({
            title : '批量匯入',
            region : 'center',
            frame : true,
            method : 'post',
            labelWidth:70,
            autoHeight : true,
            autoScroll : true,
            layout: 'column',
            fileUpload: true,
            items : [
                {
                    columnWidth:.95,
                    layout: 'form',
                    items: [comboBox,uploadFile]
                }
            ],
            buttons: [{
                id:'btn',
                text: "上傳",
                iconCls: "btn_ico_save",
                handler: saveHandler,
            }]
        });

        function saveHandler(){
            if(!dataPath){
                Ext.MessageBox.alert('錯誤',"請選擇一個掛載路徑!");
                return false;
            }
            if(!hasFile){
                Ext.MessageBox.alert('錯誤',"請選擇上傳檔案!");
                return false;
            }
            form_q.getForm().doAction('submit',{
                method:"post",
                url:'tHarvestTableSdep.do?invoke=upload&dataPath='+dataPath,
                success: function(f, a){
                    Ext.MessageBox.alert('提示',a.result.msg);
                    Ext.getCmp('btn').setVisible (false);
                },
                failure: function(f, a){
                    Ext.MessageBox.alert('錯誤',a.result.msg);
                }
            });
        }

        var viewport = new Ext.Viewport({
            layout : 'border',
            border: false,
            items : [form_q]
        });