root / trunk / web / dojo / dojox / form / FileUploader.js @ 13
History | View | Annotate | Download (22.4 KB)
| 1 |
/*
|
|---|---|
| 2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
| 3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
| 4 |
see: http://dojotoolkit.org/license for details
|
| 5 |
*/
|
| 6 |
|
| 7 |
|
| 8 |
if(!dojo._hasResource["dojox.form.FileUploader"]){ |
| 9 |
dojo._hasResource["dojox.form.FileUploader"]=true; |
| 10 |
dojo.provide("dojox.form.FileUploader");
|
| 11 |
dojo.require("dojox.embed.Flash");
|
| 12 |
dojo.require("dojo.io.iframe");
|
| 13 |
dojo.require("dojox.html.styles");
|
| 14 |
dojo.require("dijit._Widget");
|
| 15 |
dojo.require("dijit._Templated");
|
| 16 |
dojo.require("dojox.embed.flashVars");
|
| 17 |
dojo.require("dijit._Contained");
|
| 18 |
dojo.experimental("dojox.form.FileUploader");
|
| 19 |
dojo.declare("dojox.form.FileUploader",[dijit._Widget,dijit._Templated,dijit._Contained],{swfPath:dojo.config.uploaderPath||dojo.moduleUrl("dojox.form","resources/uploader.swf"),templateString:"<div><div dojoAttachPoint=\"progNode\"><div dojoAttachPoint=\"progTextNode\"></div></div><div dojoAttachPoint=\"insideNode\" class=\"uploaderInsideNode\"></div></div>",uploadUrl:"",isDebug:false,devMode:false,baseClass:"dojoxUploaderNorm",hoverClass:"dojoxUploaderHover",activeClass:"dojoxUploaderActive",disabledClass:"dojoxUploaderDisabled",force:"",uploaderType:"",flashObject:null,flashMovie:null,flashDiv:null,insideNode:null,deferredUploading:1,fileListId:"",uploadOnChange:false,selectMultipleFiles:true,htmlFieldName:"uploadedfile",flashFieldName:"flashUploadFiles",fileMask:null,minFlashVersion:9,tabIndex:-1,showProgress:false,progressMessage:"Loading",progressBackgroundUrl:dojo.moduleUrl("dijit","themes/tundra/images/buttonActive.png"),progressBackgroundColor:"#ededed",progressWidgetId:"",skipServerCheck:false,serverTimeout:5000,log:function(){ |
| 20 |
if(this.isDebug){ |
| 21 |
console["log"](Array.prototype.slice.call(arguments).join(" ")); |
| 22 |
} |
| 23 |
},constructor:function(){ |
| 24 |
this._subs=[];
|
| 25 |
},postMixInProperties:function(){ |
| 26 |
this.fileList=[];
|
| 27 |
this._cons=[];
|
| 28 |
this.fileMask=this.fileMask||[]; |
| 29 |
this.fileInputs=[];
|
| 30 |
this.fileCount=0; |
| 31 |
this.flashReady=false; |
| 32 |
this._disabled=false; |
| 33 |
this.force=this.force.toLowerCase(); |
| 34 |
this.uploaderType=((dojox.embed.Flash.available>=this.minFlashVersion||this.force=="flash")&&this.force!="html")?"flash":"html"; |
| 35 |
this.deferredUploading=this.deferredUploading===true?1:this.deferredUploading; |
| 36 |
this._refNode=this.srcNodeRef; |
| 37 |
this.getButtonStyle();
|
| 38 |
},startup:function(){ |
| 39 |
},postCreate:function(){ |
| 40 |
this.inherited(arguments); |
| 41 |
this.setButtonStyle();
|
| 42 |
var _1;
|
| 43 |
if(this.uploaderType=="flash"){ |
| 44 |
_1="createFlashUploader";
|
| 45 |
}else{
|
| 46 |
this.uploaderType="html"; |
| 47 |
_1="createHtmlUploader";
|
| 48 |
} |
| 49 |
var w=this.getHiddenWidget(); |
| 50 |
if(w){
|
| 51 |
var _2=dojo.connect(w,"onShow",this,function(){ |
| 52 |
dojo.disconnect(_2); |
| 53 |
this[_1]();
|
| 54 |
}); |
| 55 |
}else{
|
| 56 |
this[_1]();
|
| 57 |
} |
| 58 |
if(this.fileListId){ |
| 59 |
this.connect(dojo.byId(this.fileListId),"click",function(_3){ |
| 60 |
var p=_3.target.parentNode.parentNode.parentNode;
|
| 61 |
if(p.id&&p.id.indexOf("file_")>-1){ |
| 62 |
this.removeFile(p.id.split("file_")[1]); |
| 63 |
} |
| 64 |
}); |
| 65 |
} |
| 66 |
dojo.addOnUnload(this,this.destroy); |
| 67 |
},getHiddenWidget:function(){ |
| 68 |
var _4=this.domNode.parentNode; |
| 69 |
while(_4){
|
| 70 |
var id=_4.getAttribute&&_4.getAttribute("widgetId"); |
| 71 |
if(id&&dijit.byId(id).onShow){
|
| 72 |
return dijit.byId(id);
|
| 73 |
} |
| 74 |
_4=_4.parentNode; |
| 75 |
} |
| 76 |
return null; |
| 77 |
},getHiddenNode:function(_5){ |
| 78 |
if(!_5){
|
| 79 |
return null; |
| 80 |
} |
| 81 |
var _6=null; |
| 82 |
var p=_5.parentNode;
|
| 83 |
while(p.tagName.toLowerCase()!="body"){ |
| 84 |
var d=dojo.style(p,"display"); |
| 85 |
if(d=="none"){ |
| 86 |
_6=p; |
| 87 |
break;
|
| 88 |
} |
| 89 |
p=p.parentNode; |
| 90 |
} |
| 91 |
return _6;
|
| 92 |
},getButtonStyle:function(){ |
| 93 |
var _7=this.srcNodeRef; |
| 94 |
this._hiddenNode=this.getHiddenNode(_7); |
| 95 |
if(this._hiddenNode){ |
| 96 |
dojo.style(this._hiddenNode,"display","block"); |
| 97 |
} |
| 98 |
if(this.button){ |
| 99 |
console.warn("DEPRECATED: FileUploader.button - will be removed in 1.5. FileUploader should be created as widget.");
|
| 100 |
} |
| 101 |
if(!_7&&this.button&&this.button.domNode){ |
| 102 |
var _8=true; |
| 103 |
var _9=this.button.domNode.className+" dijitButtonNode"; |
| 104 |
var _a=this.getText(dojo.query(".dijitButtonText",this.button.domNode)[0]); |
| 105 |
var _b="<button id=\""+this.button.id+"\" class=\""+_9+"\">"+_a+"</button>"; |
| 106 |
_7=dojo.place(_b,this.button.domNode,"after"); |
| 107 |
this.srcNodeRef=_7;
|
| 108 |
this.button.destroy();
|
| 109 |
this.baseClass="dijitButton"; |
| 110 |
this.hoverClass="dijitButtonHover"; |
| 111 |
this.pressClass="dijitButtonActive"; |
| 112 |
this.disabledClass="dijitButtonDisabled"; |
| 113 |
}else{
|
| 114 |
if(!this.srcNodeRef&&this.button){ |
| 115 |
_7=this.button;
|
| 116 |
} |
| 117 |
} |
| 118 |
if(dojo.attr(_7,"class")){ |
| 119 |
this.baseClass+=" "+dojo.attr(_7,"class"); |
| 120 |
} |
| 121 |
dojo.attr(_7,"class",this.baseClass); |
| 122 |
this.norm=this.getStyle(_7); |
| 123 |
this.width=this.norm.w; |
| 124 |
this.height=this.norm.h; |
| 125 |
if(this.uploaderType=="flash"){ |
| 126 |
this.over=this.getTempNodeStyle(_7,this.baseClass+" "+this.hoverClass,_8); |
| 127 |
this.down=this.getTempNodeStyle(_7,this.baseClass+" "+this.activeClass,_8); |
| 128 |
this.dsbl=this.getTempNodeStyle(_7,this.baseClass+" "+this.disabledClass,_8); |
| 129 |
this.fhtml={cn:this.getText(_7),nr:this.norm,ov:this.over,dn:this.down,ds:this.dsbl}; |
| 130 |
}else{
|
| 131 |
this.fhtml={cn:this.getText(_7),nr:this.norm}; |
| 132 |
if(this.norm.va=="middle"){ |
| 133 |
this.norm.lh=this.norm.h; |
| 134 |
} |
| 135 |
} |
| 136 |
if(this.devMode){ |
| 137 |
this.log("classes - base:",this.baseClass," hover:",this.hoverClass,"active:",this.activeClass); |
| 138 |
this.log("fhtml:",this.fhtml); |
| 139 |
this.log("norm:",this.norm); |
| 140 |
this.log("over:",this.over); |
| 141 |
this.log("down:",this.down); |
| 142 |
} |
| 143 |
},setButtonStyle:function(){ |
| 144 |
dojo.style(this.domNode,{width:this.fhtml.nr.w+"px",height:(this.fhtml.nr.h)+"px",padding:"0px",lineHeight:"normal",position:"relative"}); |
| 145 |
if(this.uploaderType=="html"&&this.norm.va=="middle"){ |
| 146 |
dojo.style(this.domNode,"lineHeight",this.norm.lh+"px"); |
| 147 |
} |
| 148 |
if(this.showProgress){ |
| 149 |
this.progTextNode.innerHTML=this.progressMessage; |
| 150 |
dojo.style(this.progTextNode,{width:this.fhtml.nr.w+"px",height:(this.fhtml.nr.h+0)+"px",padding:"0px",margin:"0px",left:"0px",lineHeight:(this.fhtml.nr.h+0)+"px",position:"absolute"}); |
| 151 |
dojo.style(this.progNode,{width:this.fhtml.nr.w+"px",height:(this.fhtml.nr.h+0)+"px",padding:"0px",margin:"0px",left:"0px",position:"absolute",display:"none",backgroundImage:"url("+this.progressBackgroundUrl+")",backgroundPosition:"bottom",backgroundRepeat:"repeat-x",backgroundColor:this.progressBackgroundColor}); |
| 152 |
}else{
|
| 153 |
dojo.destroy(this.progNode);
|
| 154 |
} |
| 155 |
dojo.style(this.insideNode,{position:"absolute",top:"0px",left:"0px",display:""}); |
| 156 |
dojo.addClass(this.domNode,this.srcNodeRef.className); |
| 157 |
if(this.fhtml.nr.d.indexOf("inline")>-1){ |
| 158 |
dojo.addClass(this.domNode,"dijitInline"); |
| 159 |
} |
| 160 |
try{
|
| 161 |
this.insideNode.innerHTML=this.fhtml.cn; |
| 162 |
} |
| 163 |
catch(e){
|
| 164 |
if(this.uploaderType=="flash"){ |
| 165 |
this.insideNode=this.insideNode.parentNode.removeChild(this.insideNode); |
| 166 |
dojo.body().appendChild(this.insideNode);
|
| 167 |
this.insideNode.innerHTML=this.fhtml.cn; |
| 168 |
var c=dojo.connect(this,"onReady",this,function(){ |
| 169 |
dojo.disconnect(c); |
| 170 |
this.insideNode=this.insideNode.parentNode.removeChild(this.insideNode); |
| 171 |
this.domNode.appendChild(this.insideNode); |
| 172 |
}); |
| 173 |
}else{
|
| 174 |
this.insideNode.appendChild(document.createTextNode(this.fhtml.cn)); |
| 175 |
} |
| 176 |
} |
| 177 |
this.flashDiv=this.insideNode; |
| 178 |
if(this._hiddenNode){ |
| 179 |
dojo.style(this._hiddenNode,"display","none"); |
| 180 |
} |
| 181 |
},onChange:function(_c){ |
| 182 |
},onProgress:function(_d){ |
| 183 |
},onComplete:function(_e){ |
| 184 |
},onCancel:function(){ |
| 185 |
},onError:function(_f){ |
| 186 |
},onReady:function(_10){ |
| 187 |
},onLoad:function(_11){ |
| 188 |
},submit:function(_12){ |
| 189 |
var _13=_12?dojo.formToObject(_12):null; |
| 190 |
this.upload(_13);
|
| 191 |
return false; |
| 192 |
},upload:function(_14){ |
| 193 |
if(!this.fileList.length){ |
| 194 |
return false; |
| 195 |
} |
| 196 |
if(!this.uploadUrl){ |
| 197 |
console.warn("uploadUrl not provided. Aborting.");
|
| 198 |
return false; |
| 199 |
} |
| 200 |
if(!this.showProgress){ |
| 201 |
this.set("disabled",true); |
| 202 |
} |
| 203 |
if(this.progressWidgetId){ |
| 204 |
var _15=dijit.byId(this.progressWidgetId).domNode; |
| 205 |
if(dojo.style(_15,"display")=="none"){ |
| 206 |
this.restoreProgDisplay="none"; |
| 207 |
dojo.style(_15,"display","block"); |
| 208 |
} |
| 209 |
if(dojo.style(_15,"visibility")=="hidden"){ |
| 210 |
this.restoreProgDisplay="hidden"; |
| 211 |
dojo.style(_15,"visibility","visible"); |
| 212 |
} |
| 213 |
} |
| 214 |
if(_14&&!_14.target){
|
| 215 |
this.postData=_14;
|
| 216 |
} |
| 217 |
this.log("upload type:",this.uploaderType," - postData:",this.postData); |
| 218 |
for(var i=0;i<this.fileList.length;i++){ |
| 219 |
var f=this.fileList[i]; |
| 220 |
f.bytesLoaded=0;
|
| 221 |
f.bytesTotal=f.size||100000;
|
| 222 |
f.percent=0;
|
| 223 |
} |
| 224 |
if(this.uploaderType=="flash"){ |
| 225 |
this.uploadFlash();
|
| 226 |
}else{
|
| 227 |
this.uploadHTML();
|
| 228 |
} |
| 229 |
return false; |
| 230 |
},removeFile:function(_16,_17){ |
| 231 |
var i;
|
| 232 |
for(i=0;i<this.fileList.length;i++){ |
| 233 |
if(this.fileList[i].name==_16){ |
| 234 |
if(!_17){
|
| 235 |
this.fileList.splice(i,1); |
| 236 |
} |
| 237 |
break;
|
| 238 |
} |
| 239 |
} |
| 240 |
if(this.uploaderType=="flash"){ |
| 241 |
this.flashMovie.removeFile(_16);
|
| 242 |
}else{
|
| 243 |
if(!_17){
|
| 244 |
dojo.destroy(this.fileInputs[i]);
|
| 245 |
this.fileInputs.splice(i,1); |
| 246 |
this._renumberInputs();
|
| 247 |
} |
| 248 |
} |
| 249 |
if(this.fileListId){ |
| 250 |
dojo.destroy("file_"+_16);
|
| 251 |
} |
| 252 |
},destroyAll:function(){ |
| 253 |
console.warn("DEPRECATED for 1.5 - use destroy() instead");
|
| 254 |
this.destroy();
|
| 255 |
},destroy:function(){ |
| 256 |
if(this.uploaderType=="flash"&&!this.flashMovie){ |
| 257 |
this._cons.push(dojo.connect(this,"onLoad",this,"destroy")); |
| 258 |
return;
|
| 259 |
} |
| 260 |
dojo.forEach(this._subs,dojo.unsubscribe,dojo);
|
| 261 |
dojo.forEach(this._cons,dojo.disconnect,dojo);
|
| 262 |
if(this.scrollConnect){ |
| 263 |
dojo.disconnect(this.scrollConnect);
|
| 264 |
} |
| 265 |
if(this.uploaderType=="flash"){ |
| 266 |
this.flashObject.destroy();
|
| 267 |
dojo.destroy(this.flashDiv);
|
| 268 |
}else{
|
| 269 |
dojo.destroy("dojoIoIframe");
|
| 270 |
dojo.destroy(this._fileInput);
|
| 271 |
dojo.destroy(this._formNode);
|
| 272 |
} |
| 273 |
this.inherited(arguments); |
| 274 |
},hide:function(){ |
| 275 |
console.warn("DEPRECATED for 1.5 - use dojo.style(domNode, 'display', 'none' instead");
|
| 276 |
dojo.style(this.domNode,"display","none"); |
| 277 |
},show:function(){ |
| 278 |
console.warn("DEPRECATED for 1.5 - use dojo.style(domNode, 'display', '') instead");
|
| 279 |
dojo.style(this.domNode,"display",""); |
| 280 |
},disable:function(_18){ |
| 281 |
console.warn("DEPRECATED: FileUploader.disable() - will be removed in 1.5. Use set('disable', true) instead.");
|
| 282 |
this.set("disable",_18); |
| 283 |
},_displayProgress:function(_19){ |
| 284 |
if(_19===true){ |
| 285 |
if(this.uploaderType=="flash"){ |
| 286 |
dojo.style(this.insideNode,"left","-2500px"); |
| 287 |
}else{
|
| 288 |
dojo.style(this.insideNode,"display","none"); |
| 289 |
} |
| 290 |
dojo.style(this.progNode,"display",""); |
| 291 |
}else{
|
| 292 |
if(_19===false){ |
| 293 |
dojo.style(this.insideNode,{display:"",left:"0px"}); |
| 294 |
dojo.style(this.progNode,"display","none"); |
| 295 |
}else{
|
| 296 |
var w=_19*this.fhtml.nr.w; |
| 297 |
dojo.style(this.progNode,"width",w+"px"); |
| 298 |
} |
| 299 |
} |
| 300 |
},_animateProgress:function(){ |
| 301 |
this._displayProgress(true); |
| 302 |
var _1a=false; |
| 303 |
var c=dojo.connect(this,"_complete",function(){ |
| 304 |
dojo.disconnect(c); |
| 305 |
_1a=true;
|
| 306 |
}); |
| 307 |
var w=0; |
| 308 |
var _1b=setInterval(dojo.hitch(this,function(){ |
| 309 |
w+=5;
|
| 310 |
if(w>this.fhtml.nr.w){ |
| 311 |
w=0;
|
| 312 |
_1a=true;
|
| 313 |
} |
| 314 |
this._displayProgress(w/this.fhtml.nr.w); |
| 315 |
if(_1a){
|
| 316 |
clearInterval(_1b); |
| 317 |
setTimeout(dojo.hitch(this,function(){ |
| 318 |
this._displayProgress(false); |
| 319 |
}),500);
|
| 320 |
} |
| 321 |
}),50);
|
| 322 |
},_error:function(evt){ |
| 323 |
if(typeof (evt)=="string"){ |
| 324 |
evt=new Error(evt);
|
| 325 |
} |
| 326 |
this.onError(evt);
|
| 327 |
},_addToFileList:function(){ |
| 328 |
if(this.fileListId){ |
| 329 |
var str=""; |
| 330 |
dojo.forEach(this.fileList,function(d){ |
| 331 |
str+="<table id=\"file_"+d.name+"\" class=\"fileToUpload\"><tr><td class=\"fileToUploadClose\"></td><td class=\"fileToUploadName\">"+d.name+"</td><td class=\"fileToUploadSize\">"+(d.size?Math.ceil(d.size*0.001)+"kb":"")+"</td></tr></table>"; |
| 332 |
},this);
|
| 333 |
dojo.byId(this.fileListId).innerHTML=str;
|
| 334 |
} |
| 335 |
},_change:function(_1c){ |
| 336 |
if(dojo.isIE){
|
| 337 |
dojo.forEach(_1c,function(f){
|
| 338 |
f.name=f.name.split("\\")[f.name.split("\\").length-1]; |
| 339 |
}); |
| 340 |
} |
| 341 |
if(this.selectMultipleFiles){ |
| 342 |
this.fileList=this.fileList.concat(_1c); |
| 343 |
}else{
|
| 344 |
if(this.fileList[0]){ |
| 345 |
this.removeFile(this.fileList[0].name,true); |
| 346 |
} |
| 347 |
this.fileList=_1c;
|
| 348 |
} |
| 349 |
this._addToFileList();
|
| 350 |
this.onChange(_1c);
|
| 351 |
if(this.uploadOnChange){ |
| 352 |
if(this.uploaderType=="html"){ |
| 353 |
this._buildFileInput();
|
| 354 |
} |
| 355 |
this.upload();
|
| 356 |
}else{
|
| 357 |
if(this.uploaderType=="html"&&this.selectMultipleFiles){ |
| 358 |
this._buildFileInput();
|
| 359 |
this._connectInput();
|
| 360 |
} |
| 361 |
} |
| 362 |
},_complete:function(_1d){ |
| 363 |
_1d=dojo.isArray(_1d)?_1d:[_1d]; |
| 364 |
dojo.forEach(_1d,function(f){
|
| 365 |
if(f.ERROR){
|
| 366 |
this._error(f.ERROR);
|
| 367 |
} |
| 368 |
},this);
|
| 369 |
dojo.forEach(this.fileList,function(f){ |
| 370 |
f.bytesLoaded=1;
|
| 371 |
f.bytesTotal=1;
|
| 372 |
f.percent=100;
|
| 373 |
this._progress(f);
|
| 374 |
},this);
|
| 375 |
dojo.forEach(this.fileList,function(f){ |
| 376 |
this.removeFile(f.name,true); |
| 377 |
},this);
|
| 378 |
this.onComplete(_1d);
|
| 379 |
this.fileList=[];
|
| 380 |
this._resetHTML();
|
| 381 |
this.set("disabled",false); |
| 382 |
if(this.restoreProgDisplay){ |
| 383 |
setTimeout(dojo.hitch(this,function(){ |
| 384 |
dojo.style(dijit.byId(this.progressWidgetId).domNode,this.restoreProgDisplay=="none"?"display":"visibility",this.restoreProgDisplay); |
| 385 |
}),500);
|
| 386 |
} |
| 387 |
},_progress:function(_1e){ |
| 388 |
var _1f=0; |
| 389 |
var _20=0; |
| 390 |
for(var i=0;i<this.fileList.length;i++){ |
| 391 |
var f=this.fileList[i]; |
| 392 |
if(f.name==_1e.name){
|
| 393 |
f.bytesLoaded=_1e.bytesLoaded; |
| 394 |
f.bytesTotal=_1e.bytesTotal; |
| 395 |
f.percent=Math.ceil(f.bytesLoaded/f.bytesTotal*100);
|
| 396 |
this.log(f.name,"percent:",f.percent); |
| 397 |
} |
| 398 |
_20+=Math.ceil(0.001*f.bytesLoaded);
|
| 399 |
_1f+=Math.ceil(0.001*f.bytesTotal);
|
| 400 |
} |
| 401 |
var _21=Math.ceil(_20/_1f*100); |
| 402 |
if(this.progressWidgetId){ |
| 403 |
dijit.byId(this.progressWidgetId).update({progress:_21+"%"}); |
| 404 |
} |
| 405 |
if(this.showProgress){ |
| 406 |
this._displayProgress(_21*0.01); |
| 407 |
} |
| 408 |
this.onProgress(this.fileList); |
| 409 |
},_getDisabledAttr:function(){ |
| 410 |
return this._disabled; |
| 411 |
},_setDisabledAttr:function(_22){ |
| 412 |
if(this._disabled==_22){ |
| 413 |
return;
|
| 414 |
} |
| 415 |
if(this.uploaderType=="flash"){ |
| 416 |
if(!this.flashReady){ |
| 417 |
var _23=dojo.connect(this,"onLoad",this,function(){ |
| 418 |
dojo.disconnect(_23); |
| 419 |
this._setDisabledAttr(_22);
|
| 420 |
}); |
| 421 |
return;
|
| 422 |
} |
| 423 |
this._disabled=_22;
|
| 424 |
this.flashMovie.doDisable(_22);
|
| 425 |
}else{
|
| 426 |
this._disabled=_22;
|
| 427 |
dojo.style(this._fileInput,"display",this._disabled?"none":""); |
| 428 |
} |
| 429 |
dojo.toggleClass(this.domNode,this.disabledClass,_22); |
| 430 |
},_onFlashBlur:function(){ |
| 431 |
this.flashMovie.blur();
|
| 432 |
if(!this.nextFocusObject&&this.tabIndex){ |
| 433 |
var _24=dojo.query("[tabIndex]"); |
| 434 |
for(var i=0;i<_24.length;i++){ |
| 435 |
if(_24[i].tabIndex>=Number(this.tabIndex)+1){ |
| 436 |
this.nextFocusObject=_24[i];
|
| 437 |
break;
|
| 438 |
} |
| 439 |
} |
| 440 |
} |
| 441 |
this.nextFocusObject.focus();
|
| 442 |
},_disconnect:function(){ |
| 443 |
dojo.forEach(this._cons,dojo.disconnect,dojo);
|
| 444 |
},uploadHTML:function(){ |
| 445 |
if(this.selectMultipleFiles){ |
| 446 |
dojo.destroy(this._fileInput);
|
| 447 |
} |
| 448 |
this._setHtmlPostData();
|
| 449 |
if(this.showProgress){ |
| 450 |
this._animateProgress();
|
| 451 |
} |
| 452 |
var dfd=dojo.io.iframe.send({url:this.uploadUrl,form:this._formNode,handleAs:"json",error:dojo.hitch(this,function(err){ |
| 453 |
this._error("HTML Upload Error:"+err.message); |
| 454 |
}),load:dojo.hitch(this,function(_25,_26,_27){ |
| 455 |
this._complete(_25);
|
| 456 |
})}); |
| 457 |
},createHtmlUploader:function(){ |
| 458 |
this._buildForm();
|
| 459 |
this._setFormStyle();
|
| 460 |
this._buildFileInput();
|
| 461 |
this._connectInput();
|
| 462 |
this._styleContent();
|
| 463 |
dojo.style(this.insideNode,"visibility","visible"); |
| 464 |
this.onReady();
|
| 465 |
},_connectInput:function(){ |
| 466 |
this._disconnect();
|
| 467 |
this._cons.push(dojo.connect(this._fileInput,"mouseover",this,function(evt){ |
| 468 |
dojo.addClass(this.domNode,this.hoverClass); |
| 469 |
this.onMouseOver(evt);
|
| 470 |
})); |
| 471 |
this._cons.push(dojo.connect(this._fileInput,"mouseout",this,function(evt){ |
| 472 |
dojo.removeClass(this.domNode,this.activeClass); |
| 473 |
dojo.removeClass(this.domNode,this.hoverClass); |
| 474 |
this.onMouseOut(evt);
|
| 475 |
this._checkHtmlCancel("off"); |
| 476 |
})); |
| 477 |
this._cons.push(dojo.connect(this._fileInput,"mousedown",this,function(evt){ |
| 478 |
dojo.addClass(this.domNode,this.activeClass); |
| 479 |
dojo.removeClass(this.domNode,this.hoverClass); |
| 480 |
this.onMouseDown(evt);
|
| 481 |
})); |
| 482 |
this._cons.push(dojo.connect(this._fileInput,"mouseup",this,function(evt){ |
| 483 |
dojo.removeClass(this.domNode,this.activeClass); |
| 484 |
this.onMouseUp(evt);
|
| 485 |
this.onClick(evt);
|
| 486 |
this._checkHtmlCancel("up"); |
| 487 |
})); |
| 488 |
this._cons.push(dojo.connect(this._fileInput,"change",this,function(){ |
| 489 |
this._checkHtmlCancel("change"); |
| 490 |
this._change([{name:this._fileInput.value,type:"",size:0}]); |
| 491 |
})); |
| 492 |
if(this.tabIndex>=0){ |
| 493 |
dojo.attr(this.domNode,"tabIndex",this.tabIndex); |
| 494 |
} |
| 495 |
},_checkHtmlCancel:function(_28){ |
| 496 |
if(_28=="change"){ |
| 497 |
this.dialogIsOpen=false; |
| 498 |
} |
| 499 |
if(_28=="up"){ |
| 500 |
this.dialogIsOpen=true; |
| 501 |
} |
| 502 |
if(_28=="off"){ |
| 503 |
if(this.dialogIsOpen){ |
| 504 |
this.onCancel();
|
| 505 |
} |
| 506 |
this.dialogIsOpen=false; |
| 507 |
} |
| 508 |
},_styleContent:function(){ |
| 509 |
var o=this.fhtml.nr; |
| 510 |
dojo.style(this.insideNode,{width:o.w+"px",height:o.va=="middle"?o.h+"px":"auto",textAlign:o.ta,paddingTop:o.p[0]+"px",paddingRight:o.p[1]+"px",paddingBottom:o.p[2]+"px",paddingLeft:o.p[3]+"px"}); |
| 511 |
try{
|
| 512 |
dojo.style(this.insideNode,"lineHeight","inherit"); |
| 513 |
} |
| 514 |
catch(e){
|
| 515 |
} |
| 516 |
},_resetHTML:function(){ |
| 517 |
if(this.uploaderType=="html"&&this._formNode){ |
| 518 |
this.fileInputs=[];
|
| 519 |
dojo.query("*",this._formNode).forEach(function(n){ |
| 520 |
dojo.destroy(n); |
| 521 |
}); |
| 522 |
this.fileCount=0; |
| 523 |
this._buildFileInput();
|
| 524 |
this._connectInput();
|
| 525 |
} |
| 526 |
},_buildForm:function(){ |
| 527 |
if(this._formNode){ |
| 528 |
return;
|
| 529 |
} |
| 530 |
if(dojo.isIE){
|
| 531 |
this._formNode=document.createElement("<form enctype=\"multipart/form-data\" method=\"post\">"); |
| 532 |
this._formNode.encoding="multipart/form-data"; |
| 533 |
}else{
|
| 534 |
this._formNode=document.createElement("form"); |
| 535 |
this._formNode.setAttribute("enctype","multipart/form-data"); |
| 536 |
} |
| 537 |
this._formNode.id=dijit.getUniqueId("FileUploaderForm"); |
| 538 |
this.domNode.appendChild(this._formNode); |
| 539 |
},_buildFileInput:function(){ |
| 540 |
if(this._fileInput){ |
| 541 |
this._disconnect();
|
| 542 |
this._fileInput.id=this._fileInput.id+this.fileCount; |
| 543 |
dojo.style(this._fileInput,"display","none"); |
| 544 |
} |
| 545 |
this._fileInput=document.createElement("input"); |
| 546 |
this.fileInputs.push(this._fileInput); |
| 547 |
var nm=this.htmlFieldName; |
| 548 |
var _29=this.id; |
| 549 |
if(this.selectMultipleFiles){ |
| 550 |
nm+=this.fileCount;
|
| 551 |
_29+=this.fileCount;
|
| 552 |
this.fileCount++;
|
| 553 |
} |
| 554 |
dojo.attr(this._fileInput,{id:this.id,name:nm,type:"file"}); |
| 555 |
dojo.addClass(this._fileInput,"dijitFileInputReal"); |
| 556 |
console.warn("BUILD FI");
|
| 557 |
this._formNode.appendChild(this._fileInput); |
| 558 |
var _2a=dojo.marginBox(this._fileInput); |
| 559 |
dojo.style(this._fileInput,{position:"relative",left:(this.fhtml.nr.w-_2a.w)+"px",opacity:0}); |
| 560 |
},_renumberInputs:function(){ |
| 561 |
if(!this.selectMultipleFiles){ |
| 562 |
return;
|
| 563 |
} |
| 564 |
var nm;
|
| 565 |
this.fileCount=0; |
| 566 |
dojo.forEach(this.fileInputs,function(inp){ |
| 567 |
nm=this.htmlFieldName+this.fileCount; |
| 568 |
this.fileCount++;
|
| 569 |
dojo.attr(inp,"name",nm);
|
| 570 |
},this);
|
| 571 |
},_setFormStyle:function(){ |
| 572 |
var _2b=Math.max(2,Math.max(Math.ceil(this.fhtml.nr.w/60),Math.ceil(this.fhtml.nr.h/15))); |
| 573 |
dojox.html.insertCssRule("#"+this._formNode.id+" input","font-size:"+_2b+"em"); |
| 574 |
dojo.style(this.domNode,{overflow:"hidden",position:"relative"}); |
| 575 |
dojo.style(this.insideNode,"position","absolute"); |
| 576 |
},_setHtmlPostData:function(){ |
| 577 |
if(this.postData){ |
| 578 |
for(var nm in this.postData){ |
| 579 |
dojo.create("input",{type:"hidden",name:nm,value:this.postData[nm]},this._formNode); |
| 580 |
} |
| 581 |
} |
| 582 |
},uploadFlash:function(){ |
| 583 |
try{
|
| 584 |
if(this.showProgress){ |
| 585 |
this._displayProgress(true); |
| 586 |
var c=dojo.connect(this,"_complete",this,function(){ |
| 587 |
dojo.disconnect(c); |
| 588 |
this._displayProgress(false); |
| 589 |
}); |
| 590 |
} |
| 591 |
var o={};
|
| 592 |
for(var nm in this.postData){ |
| 593 |
o[nm]=this.postData[nm];
|
| 594 |
} |
| 595 |
console.warn("this.postData:",o);
|
| 596 |
this.flashMovie.doUpload(o);
|
| 597 |
} |
| 598 |
catch(err){
|
| 599 |
this._error("FileUploader - Sorry, the SWF failed to initialize."+err); |
| 600 |
} |
| 601 |
},createFlashUploader:function(){ |
| 602 |
this.uploadUrl=this.uploadUrl.toString(); |
| 603 |
if(this.uploadUrl){ |
| 604 |
if(this.uploadUrl.toLowerCase().indexOf("http")<0&&this.uploadUrl.indexOf("/")!=0){ |
| 605 |
var loc=window.location.href.split("/"); |
| 606 |
loc.pop(); |
| 607 |
loc=loc.join("/")+"/"; |
| 608 |
this.uploadUrl=loc+this.uploadUrl; |
| 609 |
this.log("SWF Fixed - Relative loc:",loc," abs loc:",this.uploadUrl); |
| 610 |
}else{
|
| 611 |
this.log("SWF URL unmodified:",this.uploadUrl); |
| 612 |
} |
| 613 |
}else{
|
| 614 |
console.warn("Warning: no uploadUrl provided.");
|
| 615 |
} |
| 616 |
var w=this.fhtml.nr.w; |
| 617 |
var h=this.fhtml.nr.h; |
| 618 |
var _2c={expressInstall:true,path:this.swfPath.uri||this.swfPath,width:w,height:h,allowScriptAccess:"always",allowNetworking:"all",vars:{uploadDataFieldName:this.flashFieldName,uploadUrl:this.uploadUrl,uploadOnSelect:this.uploadOnChange,deferredUploading:this.deferredUploading||0,selectMultipleFiles:this.selectMultipleFiles,id:this.id,isDebug:this.isDebug,devMode:this.devMode,flashButton:dojox.embed.flashVars.serialize("fh",this.fhtml),fileMask:dojox.embed.flashVars.serialize("fm",this.fileMask),noReturnCheck:this.skipServerCheck,serverTimeout:this.serverTimeout},params:{scale:"noscale",wmode:"opaque"}}; |
| 619 |
this.flashObject=new dojox.embed.Flash(_2c,this.insideNode); |
| 620 |
this.flashObject.onError=dojo.hitch(function(msg){ |
| 621 |
this._error("Flash Error: "+msg); |
| 622 |
}); |
| 623 |
this.flashObject.onReady=dojo.hitch(this,function(){ |
| 624 |
dojo.style(this.insideNode,"visibility","visible"); |
| 625 |
this.log("FileUploader flash object ready"); |
| 626 |
this.onReady(this); |
| 627 |
}); |
| 628 |
this.flashObject.onLoad=dojo.hitch(this,function(mov){ |
| 629 |
this.flashMovie=mov;
|
| 630 |
this.flashReady=true; |
| 631 |
this.onLoad(this); |
| 632 |
}); |
| 633 |
this._connectFlash();
|
| 634 |
},_connectFlash:function(){ |
| 635 |
this._doSub("/filesSelected","_change"); |
| 636 |
this._doSub("/filesUploaded","_complete"); |
| 637 |
this._doSub("/filesProgress","_progress"); |
| 638 |
this._doSub("/filesError","_error"); |
| 639 |
this._doSub("/filesCanceled","onCancel"); |
| 640 |
this._doSub("/stageBlur","_onFlashBlur"); |
| 641 |
this._doSub("/up","onMouseUp"); |
| 642 |
this._doSub("/down","onMouseDown"); |
| 643 |
this._doSub("/over","onMouseOver"); |
| 644 |
this._doSub("/out","onMouseOut"); |
| 645 |
this.connect(this.domNode,"focus",function(){ |
| 646 |
this.flashMovie.focus();
|
| 647 |
this.flashMovie.doFocus();
|
| 648 |
}); |
| 649 |
if(this.tabIndex>=0){ |
| 650 |
dojo.attr(this.domNode,"tabIndex",this.tabIndex); |
| 651 |
} |
| 652 |
},_doSub:function(_2d,_2e){ |
| 653 |
this._subs.push(dojo.subscribe(this.id+_2d,this,_2e)); |
| 654 |
},urlencode:function(url){ |
| 655 |
if(!url||url=="none"){ |
| 656 |
return false; |
| 657 |
} |
| 658 |
return url.replace(/:/g,"||").replace(/\./g,"^^").replace("url(","").replace(")","").replace(/'/g,"").replace(/"/g,""); |
| 659 |
},isButton:function(_2f){ |
| 660 |
var tn=_2f.tagName.toLowerCase();
|
| 661 |
return tn=="button"||tn=="input"; |
| 662 |
},getTextStyle:function(_30){ |
| 663 |
var o={};
|
| 664 |
o.ff=dojo.style(_30,"fontFamily");
|
| 665 |
if(o.ff){
|
| 666 |
o.ff=o.ff.replace(", ",","); |
| 667 |
o.ff=o.ff.replace(/\"|\'/g,""); |
| 668 |
o.ff=o.ff=="sans-serif"?"Arial":o.ff; |
| 669 |
o.fw=dojo.style(_30,"fontWeight");
|
| 670 |
o.fi=dojo.style(_30,"fontStyle");
|
| 671 |
o.fs=parseInt(dojo.style(_30,"fontSize"),10); |
| 672 |
if(dojo.style(_30,"fontSize").indexOf("%")>-1){ |
| 673 |
var n=_30;
|
| 674 |
while(n.tagName){
|
| 675 |
if(dojo.style(n,"fontSize").indexOf("%")==-1){ |
| 676 |
o.fs=parseInt(dojo.style(n,"fontSize"),10); |
| 677 |
break;
|
| 678 |
} |
| 679 |
if(n.tagName.toLowerCase()=="body"){ |
| 680 |
o.fs=16*0.01*parseInt(dojo.style(n,"fontSize"),10); |
| 681 |
} |
| 682 |
n=n.parentNode; |
| 683 |
} |
| 684 |
} |
| 685 |
o.fc=new dojo.Color(dojo.style(_30,"color")).toHex(); |
| 686 |
o.fc=parseInt(o.fc.substring(1,Infinity),16); |
| 687 |
} |
| 688 |
o.lh=dojo.style(_30,"lineHeight");
|
| 689 |
o.ta=dojo.style(_30,"textAlign");
|
| 690 |
o.ta=o.ta=="start"||!o.ta?"left":o.ta; |
| 691 |
o.va=this.isButton(_30)?"middle":o.lh==o.h?"middle":dojo.style(_30,"verticalAlign"); |
| 692 |
return o;
|
| 693 |
},getText:function(_31){ |
| 694 |
var cn=dojo.trim(_31.innerHTML);
|
| 695 |
if(cn.indexOf("<")>-1){ |
| 696 |
cn=escape(cn); |
| 697 |
} |
| 698 |
return cn;
|
| 699 |
},getStyle:function(_32){ |
| 700 |
var o={};
|
| 701 |
var dim=dojo.contentBox(_32);
|
| 702 |
var pad=dojo._getPadExtents(_32);
|
| 703 |
o.p=[pad.t,pad.w-pad.l,pad.h-pad.t,pad.l]; |
| 704 |
o.w=dim.w+pad.w; |
| 705 |
o.h=dim.h+pad.h; |
| 706 |
o.d=dojo.style(_32,"display");
|
| 707 |
var clr=new dojo.Color(dojo.style(_32,"backgroundColor")); |
| 708 |
o.bc=clr.a==0?"#ffffff":clr.toHex(); |
| 709 |
o.bc=parseInt(o.bc.substring(1,Infinity),16); |
| 710 |
var url=this.urlencode(dojo.style(_32,"backgroundImage")); |
| 711 |
if(url){
|
| 712 |
o.bi={url:url,rp:dojo.style(_32,"backgroundRepeat"),pos:escape(dojo.style(_32,"backgroundPosition"))};
|
| 713 |
if(!o.bi.pos){
|
| 714 |
var rx=dojo.style(_32,"backgroundPositionX"); |
| 715 |
var ry=dojo.style(_32,"backgroundPositionY"); |
| 716 |
rx=(rx=="left")?"0%":(rx=="right")?"100%":rx; |
| 717 |
ry=(ry=="top")?"0%":(ry=="bottom")?"100%":ry; |
| 718 |
o.bi.pos=escape(rx+" "+ry);
|
| 719 |
} |
| 720 |
} |
| 721 |
return dojo.mixin(o,this.getTextStyle(_32)); |
| 722 |
},getTempNodeStyle:function(_33,_34,_35){ |
| 723 |
var _36,_37;
|
| 724 |
if(_35){
|
| 725 |
_36=dojo.place("<"+_33.tagName+"><span>"+_33.innerHTML+"</span></"+_33.tagName+">",_33.parentNode); |
| 726 |
var _38=_36.firstChild;
|
| 727 |
dojo.addClass(_38,_33.className); |
| 728 |
dojo.addClass(_36,_34); |
| 729 |
_37=this.getStyle(_38);
|
| 730 |
}else{
|
| 731 |
_36=dojo.place("<"+_33.tagName+">"+_33.innerHTML+"</"+_33.tagName+">",_33.parentNode); |
| 732 |
dojo.addClass(_36,_33.className); |
| 733 |
dojo.addClass(_36,_34); |
| 734 |
_36.id=_33.id; |
| 735 |
_37=this.getStyle(_36);
|
| 736 |
} |
| 737 |
dojo.destroy(_36); |
| 738 |
return _37;
|
| 739 |
}}); |
| 740 |
} |