/
master_import.js
84 lines (78 loc) · 2.68 KB
/
master_import.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
Pf.util.ImportXlsBtn = Ext.extend(Ext.Button,{
constructor : function(config){
Ext.applyIf(config,{
text : '导入',
icon : Pf.Icon.Upload
});
this.importWin = this.createUploadWin(); /*导入窗口*/
this.handler = function() {this.importWin.show();};
Pf.util.ImportXlsBtn.superclass.constructor.call(this,config);
},
createUploadWin : function(){
var form = new Ext.FormPanel({
height : 80,
frame : true,
labelWidth : 1,
fileUpload : true, /*important!!*/
defaults : {
anchor: '95%',
allowBlank: false,
msgTarget: 'side'
},
items : [{
xtype : 'fileuploadfield',
emptyText : 'select an excel',
name : 'master[attachment]',
buttonText : 'Browse',
listeners : { 'fileselected' : {fn: this.onFileSelect, scope: this} }
}],
buttons: [{
text : 'Save',
listeners : {
'click' : { fn : this.submitFile, scope : this }
}
}]
});
var win = new Ext.Window({
width : 500,
modal : true,
closeAction : 'hide',
items : form
});
return win;
},
onFileSelect : function(field) {
var value = field.getValue();
var pattern = /\.xls$|\.xls&/i;
if (!pattern.test(value)){
Ext.Msg.show({
title :"警告",
msg :"请选择一个xls格式文件.",
buttons : Ext.MessageBox.OK ,
icon : Ext.MessageBox.INFO
});
field.setValue(null);
};
},
submitFile : function () {
var form = this.importWin.getComponent(0);
var scope = this;
if(form.getForm().isValid()){
form.getForm().submit({
url : '/master/import?' + String.format("model_name={0}", this.actionName),
standardSubmit : false,
method : 'post',
waitMsg: '正在上传文件...',
success: function(fp, action){
if(action.result == true) {
scope.importWin.hide();
if (scope.store) {scope.store.reload();};
}
},
failure : function(fp, action){
Ext.Msg.alert("Error", action.result.error_msg);
}
});
}
}
});