-
Notifications
You must be signed in to change notification settings - Fork 0
/
AbstractAdapter.js
161 lines (131 loc) · 4.28 KB
/
AbstractAdapter.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
Ext.namespace('Ext.ux.uploader');
Ext.ux.uploader.AbstractAdapter = function(config){
this._initialConfig = config;
Ext.apply(this,config);
this.addEvents({
/* upload events for the entire upload process */
'uploadstart' :true,
'uploadstop' :true,
'uploadprogress' :true,
'uploadsuccess' :true,
'uploadfailure' :true,
'queueerror' :true,
'queueempty' :true,
'filequeued' :true,
'fileremoved' :true,
'queuecomplete' :true
});
this._features = {
/* These are the features for the basic HTML upload */
'queue' :true,
'progress' :false,
'pausequeue' :true,
'pauseupload' :false,
'filesize' :false
};
if( this.imagesOnly ){
this.filters = ['.jpg','.gif','.png','.bmp'];
}
Ext.ux.uploader.AbstractAdapter.superclass.constructor.call(this);
this._init();
};
Ext.extend(Ext.ux.uploader.AbstractAdapter, Ext.util.Observable,{
lang : {
INVALID_FILETYPE :'Invalid File Type',
EXCEEDS_MAXSIZE :'File exceeds maximum size of {0}'
},
_validFileName : function(filename){
// check extensions etc..
var ret=true;
if( filename==''){
return false;
}
if(this.filter && Ext.type(this.filter)=='regexp'){
ret=this.filter.test(filename);
if(!ret){return false;}
}else if(this.filter && Ext.type(this.filter)=='string'){
if( !this.filters ){
this.filters = [this.filter];
}else if(Ext.type(this.filters)=='array'){
this.filters[this.filters.length] = this.filter;
}
}
if(this.filters && Ext.type(this.filters)=='array'){
var re = new RegExp(("("+this.filters.join('|')+")$").replace(/\./,'\.'),'i');
ret = re.test(filename);
}
return ret;
},
_basename : function(path){
var b = path.replace(/^.*[\/\\]/g, '');
if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
b = b.substr(0, b.length-suffix.length);
}
return b;
},
_init : function(){
},
hasFeature : function(featureName){
return this._features[featureName];
},
browse : function(){
// implement browse if possible.
},
upload : function(params){
// start an upload with an additional parameters
},
clearQueue : function(){
// empty the queue.
},
stop : function(force){
// stop the queued uploads
},
remove : function(fileUpload){
},
isUploading : function(){
return this._uploading;
},
isQueueEmpty : function(){
return this._queue.getCount() == 0;
},
removeAt : function(index){
// remove a file from the queue
},
clearQueue : function(){
},
reset : function(){
this.clearQueue();
},
getQueue : function(){
// return queue
},
getCompleted : function(){
},
get : function(key,defaultValue){
var privateKey = '_'+key;
if( this[privateKey] ){
return this[privateKey];
}
return Ext.type(defaultValue) == 'undefined' ? false : defaultValue;
}
});
Ext.ux.uploader.AdapterFactory= (function(){
var registry = {};
return {
register : function(type,obj){
registry[type] = obj;
},
reg : function(type,obj){
this.register(type,obj);
},
create : function(type, config){
if( !registry[type] ){
throw 'Uploader Type "'+type+'" is not registered';
}else{
var obj = new registry[type](config);
obj.type = type;
return obj;
}
}
};
})();