| 1 |
define([ |
| 2 |
"dojo/dom-form", |
| 3 |
"dojo/dom-style", |
| 4 |
"dojo/dom-construct", |
| 5 |
"dojo/dom-attr", |
| 6 |
"dojo/_base/declare", |
| 7 |
"dojo/_base/config", |
| 8 |
"dojo/_base/connect", |
| 9 |
"dojo/_base/lang", |
| 10 |
"dojo/_base/array", |
| 11 |
"dojox/embed/Flash" |
| 12 |
],function(domForm, domStyle, domConstruct, domAttr, declare, config, connect, lang, arrayUtil, embedFlash){ |
| 13 |
|
| 14 |
|
| 15 |
return declare("dojox.form.uploader._Flash", [], { |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
swfPath:config.uploaderPath || require.toUrl("dojox/form/resources/uploader.swf"), |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
preventCache: true, |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
skipServerCheck:true, |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
serverTimeout: 2000, |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
isDebug:false, |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
devMode:false, |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
deferredUploading:0, |
| 67 |
|
| 68 |
postMixInProperties: function(){ |
| 69 |
if(this.uploadType === 'flash'){ |
| 70 |
this._files = []; |
| 71 |
this._fileMap = {}; |
| 72 |
this._createInput = this._createFlashUploader; |
| 73 |
this.getFileList = this.getFlashFileList; |
| 74 |
this.reset = this.flashReset; |
| 75 |
this.upload = this.uploadFlash; |
| 76 |
this.fieldname = "flashUploadFiles"; |
| 77 |
} |
| 78 |
this.inherited(arguments); |
| 79 |
}, |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
onReady: function( uploader){ |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
}, |
| 91 |
|
| 92 |
onLoad: function( uploader){ |
| 93 |
|
| 94 |
|
| 95 |
}, |
| 96 |
|
| 97 |
onFileChange: function(fileArray){ |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
}, |
| 103 |
|
| 104 |
onFileProgress: function(fileArray){ |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
}, |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
getFlashFileList: function(){ |
| 116 |
|
| 117 |
|
| 118 |
return this._files; |
| 119 |
}, |
| 120 |
|
| 121 |
flashReset: function(){ |
| 122 |
this.flashMovie.reset(); |
| 123 |
this._files = []; |
| 124 |
this._fileMap = {}; |
| 125 |
}, |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
uploadFlash: function( formData){ |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
this.onBegin(this.getFileList()); |
| 137 |
formData = formData || {}; |
| 138 |
formData.returnType = "F"; |
| 139 |
formData.uploadType = this.uploadType; |
| 140 |
console.log('flas upload', formData); |
| 141 |
this.flashMovie.doUpload(formData); |
| 142 |
}, |
| 143 |
|
| 144 |
_change: function(fileArray){ |
| 145 |
this._files = this._files.concat(fileArray); |
| 146 |
arrayUtil.forEach(fileArray, function(f){ |
| 147 |
f.bytesLoaded = 0; |
| 148 |
f.bytesTotal = f.size; |
| 149 |
this._fileMap[f.name+"_"+f.size] = f; |
| 150 |
}, this); |
| 151 |
this.onChange(this._files); |
| 152 |
this.onFileChange(fileArray); |
| 153 |
}, |
| 154 |
_complete: function(fileArray){ |
| 155 |
var o = this._getCustomEvent(); |
| 156 |
o.type = "load"; |
| 157 |
this.onComplete(fileArray); |
| 158 |
}, |
| 159 |
_progress: function(f){ |
| 160 |
this._fileMap[f.name+"_"+f.bytesTotal].bytesLoaded = f.bytesLoaded; |
| 161 |
var o = this._getCustomEvent(); |
| 162 |
this.onFileProgress(f); |
| 163 |
this.onProgress(o); |
| 164 |
}, |
| 165 |
_error: function(err){ |
| 166 |
this.onError(err); |
| 167 |
}, |
| 168 |
_onFlashBlur: function(fileArray){ |
| 169 |
|
| 170 |
}, |
| 171 |
|
| 172 |
_getCustomEvent: function(){ |
| 173 |
var o = { |
| 174 |
bytesLoaded:0, |
| 175 |
bytesTotal:0, |
| 176 |
type:"progress", |
| 177 |
timeStamp:new Date().getTime() |
| 178 |
}; |
| 179 |
|
| 180 |
|
| 181 |
for(var nm in this._fileMap){ |
| 182 |
o.bytesTotal += this._fileMap[nm].bytesTotal; |
| 183 |
o.bytesLoaded += this._fileMap[nm].bytesLoaded; |
| 184 |
} |
| 185 |
o.decimal = o.bytesLoaded / o.bytesTotal; |
| 186 |
o.percent = Math.ceil((o.bytesLoaded / o.bytesTotal)*100)+"%"; |
| 187 |
return o; |
| 188 |
}, |
| 189 |
|
| 190 |
_connectFlash: function(){ |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
this._subs = []; |
| 200 |
this._cons = []; |
| 201 |
|
| 202 |
var doSub = lang.hitch(this, function(s, funcStr){ |
| 203 |
this._subs.push(connect.subscribe(this.id + s, this, funcStr)); |
| 204 |
}); |
| 205 |
|
| 206 |
doSub("/filesSelected", "_change"); |
| 207 |
doSub("/filesUploaded", "_complete"); |
| 208 |
doSub("/filesProgress", "_progress"); |
| 209 |
doSub("/filesError", "_error"); |
| 210 |
doSub("/filesCanceled", "onCancel"); |
| 211 |
doSub("/stageBlur", "_onFlashBlur"); |
| 212 |
|
| 213 |
this.connect(this.domNode, "focus", function(){ |
| 214 |
|
| 215 |
this.flashMovie.focus(); |
| 216 |
this.flashMovie.doFocus(); |
| 217 |
}); |
| 218 |
if(this.tabIndex>=0){ |
| 219 |
domAttr.set(this.domNode, "tabIndex", this.tabIndex); |
| 220 |
} |
| 221 |
}, |
| 222 |
_createFlashUploader: function(){ |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
var w = this.btnSize.w; |
| 227 |
var h = this.btnSize.h; |
| 228 |
if(!w){ |
| 229 |
|
| 230 |
setTimeout(dojo.hitch(this, function(){ |
| 231 |
this._getButtonStyle(this.domNode); |
| 232 |
this._createFlashUploader(); |
| 233 |
}), 200); |
| 234 |
return; |
| 235 |
} |
| 236 |
var url = this.getUrl(); |
| 237 |
if(url){ |
| 238 |
if(url.toLowerCase().indexOf("http")<0 && url.indexOf("/")!=0){ |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
var loc = window.location.href.split("/"); |
| 243 |
loc.pop(); |
| 244 |
loc = loc.join("/")+"/"; |
| 245 |
url = loc+url; |
| 246 |
} |
| 247 |
}else{ |
| 248 |
console.warn("Warning: no uploadUrl provided."); |
| 249 |
} |
| 250 |
|
| 251 |
this.inputNode = domConstruct.create("div", {className:"dojoxFlashNode"}, this.domNode, "first"); |
| 252 |
domStyle.set(this.inputNode, { |
| 253 |
position:"absolute", |
| 254 |
top:"-2px", |
| 255 |
width:w+"px", |
| 256 |
height:h+"px", |
| 257 |
opacity:0 |
| 258 |
}); |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
var args = { |
| 263 |
expressInstall:true, |
| 264 |
path: (this.swfPath.uri || this.swfPath) + ((this.preventCache)?("?cb_" + (new Date().getTime())):""), |
| 265 |
width: w, |
| 266 |
height: h, |
| 267 |
allowScriptAccess:"always", |
| 268 |
allowNetworking:"all", |
| 269 |
vars: { |
| 270 |
uploadDataFieldName: this.flashFieldName || this.name+"Flash", |
| 271 |
uploadUrl: url, |
| 272 |
uploadOnSelect: this.uploadOnSelect, |
| 273 |
deferredUploading:this.deferredUploading || 0, |
| 274 |
selectMultipleFiles: this.multiple, |
| 275 |
id: this.id, |
| 276 |
isDebug: this.isDebug, |
| 277 |
noReturnCheck: this.skipServerCheck, |
| 278 |
serverTimeout:this.serverTimeout |
| 279 |
}, |
| 280 |
params: { |
| 281 |
scale:"noscale", |
| 282 |
|
| 283 |
wmode:"opaque", |
| 284 |
allowScriptAccess:"always", |
| 285 |
allowNetworking:"all" |
| 286 |
} |
| 287 |
|
| 288 |
}; |
| 289 |
|
| 290 |
this.flashObject = new embedFlash(args, this.inputNode); |
| 291 |
this.flashObject.onError = lang.hitch(function(msg){ |
| 292 |
console.error("Flash Error: " + msg); |
| 293 |
}); |
| 294 |
this.flashObject.onReady = lang.hitch(this, function(){ |
| 295 |
this.onReady(this); |
| 296 |
}); |
| 297 |
this.flashObject.onLoad = lang.hitch(this, function(mov){ |
| 298 |
this.flashMovie = mov; |
| 299 |
this.flashReady = true; |
| 300 |
|
| 301 |
this.onLoad(this); |
| 302 |
}); |
| 303 |
this._connectFlash(); |
| 304 |
} |
| 305 |
}); |
| 306 |
}); |