root / trunk / web / dojo / dojox / form / FileInputAuto.js @ 12
History | View | Annotate | Download (4.01 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
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.FileInputAuto"]){ |
||
9 | dojo._hasResource["dojox.form.FileInputAuto"]=true; |
||
10 | dojo.provide("dojox.form.FileInputAuto");
|
||
11 | dojo.require("dojox.form.FileInput");
|
||
12 | dojo.require("dojo.io.iframe");
|
||
13 | dojo.declare("dojox.form.FileInputAuto",dojox.form.FileInput,{url:"",blurDelay:2000,duration:500,uploadMessage:"Uploading ...",triggerEvent:"onblur",_sent:false,templateString:dojo.cache("dojox.form","resources/FileInputAuto.html","<div class=\"dijitFileInput\">\n\t<input id=\"${id}\" name=\"${name}\" class=\"dijitFileInputReal\" type=\"file\" dojoAttachPoint=\"fileInput\" />\n\t<div class=\"dijitFakeInput\" dojoAttachPoint=\"fakeNodeHolder\">\n\t\t<input class=\"dijitFileInputVisible\" type=\"text\" dojoAttachPoint=\"focusNode, inputNode\" />\n\t\t<div class=\"dijitInline dijitFileInputText\" dojoAttachPoint=\"titleNode\">${label}</div>\n\t\t<div class=\"dijitInline dijitFileInputButton\" dojoAttachPoint=\"cancelNode\" dojoAttachEvent=\"onclick:reset\">${cancelText}</div>\n\t</div>\n\t<div class=\"dijitProgressOverlay\" dojoAttachPoint=\"overlay\"> </div>\n</div>\n"),onBeforeSend:function(){ |
||
14 | return {};
|
||
15 | },startup:function(){ |
||
16 | this._blurListener=this.connect(this.fileInput,this.triggerEvent,"_onBlur"); |
||
17 | this._focusListener=this.connect(this.fileInput,"onfocus","_onFocus"); |
||
18 | this.inherited(arguments); |
||
19 | },_onFocus:function(){ |
||
20 | if(this._blurTimer){ |
||
21 | clearTimeout(this._blurTimer);
|
||
22 | } |
||
23 | },_onBlur:function(){ |
||
24 | if(this._blurTimer){ |
||
25 | clearTimeout(this._blurTimer);
|
||
26 | } |
||
27 | if(!this._sent){ |
||
28 | this._blurTimer=setTimeout(dojo.hitch(this,"_sendFile"),this.blurDelay); |
||
29 | } |
||
30 | },setMessage:function(_1){ |
||
31 | this.overlay.removeChild(this.overlay.firstChild); |
||
32 | this.overlay.appendChild(document.createTextNode(_1));
|
||
33 | },_sendFile:function(e){ |
||
34 | if(this._sent||this._sending||!this.fileInput.value){ |
||
35 | return;
|
||
36 | } |
||
37 | this._sending=true; |
||
38 | dojo.style(this.fakeNodeHolder,"display","none"); |
||
39 | dojo.style(this.overlay,{opacity:0,display:"block"}); |
||
40 | this.setMessage(this.uploadMessage); |
||
41 | dojo.fadeIn({node:this.overlay,duration:this.duration}).play(); |
||
42 | var _2;
|
||
43 | if(dojo.isIE){
|
||
44 | _2=document.createElement("<form enctype=\"multipart/form-data\" method=\"post\">");
|
||
45 | _2.encoding="multipart/form-data";
|
||
46 | }else{
|
||
47 | _2=document.createElement("form");
|
||
48 | _2.setAttribute("enctype","multipart/form-data"); |
||
49 | } |
||
50 | _2.appendChild(this.fileInput);
|
||
51 | dojo.body().appendChild(_2); |
||
52 | dojo.io.iframe.send({url:this.url,form:_2,handleAs:"json",handle:dojo.hitch(this,"_handleSend"),content:this.onBeforeSend()}); |
||
53 | },_handleSend:function(_3,_4){ |
||
54 | this.overlay.removeChild(this.overlay.firstChild); |
||
55 | this._sent=true; |
||
56 | this._sending=false; |
||
57 | dojo.style(this.overlay,{opacity:0,border:"none",background:"none"}); |
||
58 | this.overlay.style.backgroundImage="none"; |
||
59 | this.fileInput.style.display="none"; |
||
60 | this.fakeNodeHolder.style.display="none"; |
||
61 | dojo.fadeIn({node:this.overlay,duration:this.duration}).play(250); |
||
62 | this.disconnect(this._blurListener); |
||
63 | this.disconnect(this._focusListener); |
||
64 | dojo.body().removeChild(_4.args.form); |
||
65 | this.fileInput=null; |
||
66 | this.onComplete(_3,_4,this); |
||
67 | },reset:function(e){ |
||
68 | if(this._blurTimer){ |
||
69 | clearTimeout(this._blurTimer);
|
||
70 | } |
||
71 | this.disconnect(this._blurListener); |
||
72 | this.disconnect(this._focusListener); |
||
73 | this.overlay.style.display="none"; |
||
74 | this.fakeNodeHolder.style.display=""; |
||
75 | this.inherited(arguments); |
||
76 | this._sent=false; |
||
77 | this._sending=false; |
||
78 | this._blurListener=this.connect(this.fileInput,this.triggerEvent,"_onBlur"); |
||
79 | this._focusListener=this.connect(this.fileInput,"onfocus","_onFocus"); |
||
80 | },onComplete:function(_5,_6,_7){ |
||
81 | }}); |
||
82 | dojo.declare("dojox.form.FileInputBlind",dojox.form.FileInputAuto,{startup:function(){ |
||
83 | this.inherited(arguments); |
||
84 | this._off=dojo.style(this.inputNode,"width"); |
||
85 | this.inputNode.style.display="none"; |
||
86 | this._fixPosition();
|
||
87 | },_fixPosition:function(){ |
||
88 | if(dojo.isIE){
|
||
89 | dojo.style(this.fileInput,"width","1px"); |
||
90 | }else{
|
||
91 | dojo.style(this.fileInput,"left","-"+(this._off)+"px"); |
||
92 | } |
||
93 | },reset:function(e){ |
||
94 | this.inherited(arguments); |
||
95 | this._fixPosition();
|
||
96 | }}); |
||
97 | } |