Debian Codegraph @

dojox/form/uploader/FileList.js

raw symbols SCIP
1 define([
2 "dojo/_base/fx",
3 "dojo/dom-style",
4 "dojo/dom-class",
5 "dojo/_base/declare",
6 "dojo/_base/lang",
7 "dojo/_base/array",
8 "dijit/_base/manager",
9 "dojox/form/uploader/_Base",
10 "dojo/text!../resources/UploaderFileList.html"
11 ],function(fx, domStyle, domClass, declare, lang, arrayUtil, manager, Base, template){
12
13 return declare("dojox.form.uploader.FileList", Base, {
14 // summary:
15 // A simple widget that provides a list of the files currently selected by
16 // dojox/form/Uploader
17 // description:
18 // There is a required CSS file: resources/UploaderFileList.css.
19 // This is a very simple widget, and not beautifully styled. It is here mainly for test
20 // cases, but could very easily be used, extended, modified, or copied.
21
22 // uploaderId: String
23 // The id of the dojox.form.Uploader to connect to.
24 uploaderId:"",
25
26 // uploader: dojox.form.Uploader
27 // The dojox.form.Uploader to connect to. Use either this property of unploaderId. This
28 // property is populated if uploaderId is used.
29 uploader:null,
30
31 // headerIndex: String
32 // The label for the index column.
33 headerIndex:"#",
34
35 // headerType: String
36 // The label for the file type column.
37 headerType:"Type",
38
39 // headerFilename: String
40 // The label for the file name column.
41 headerFilename:"File Name",
42
43 // headerFilesize: String
44 // The label for the file size column.
45 headerFilesize:"Size",
46
47 _upCheckCnt:0,
48 rowAmt:0,
49
50 templateString:template,
51
52 postCreate: function(){
53 this.setUploader();
54 this.hideProgress();
55 },
56
57 reset: function(){
58 // summary:
59 // Clears all rows of items. Happens automatically if Uploader is reset, but you
60 // could call this directly.
61
62 for(var i=0;i<this.rowAmt;i++){
63 this.listNode.deleteRow(0);
64 }
65 this.rowAmt = 0;
66 },
67
68 setUploader: function(){
69 // summary:
70 // Connects to the Uploader based on the uploader or the uploaderId properties.
71
72 if(!this.uploaderId && !this.uploader){
73 console.warn("uploaderId not passed to UploaderFileList");
74 }else if(this.uploaderId && !this.uploader){
75 this.uploader = manager.byId(this.uploaderId);
76 }else if(this._upCheckCnt>4){
77 console.warn("uploader not found for ID ", this.uploaderId);
78 return;
79 }
80 if(this.uploader){
81 this.connect(this.uploader, "onChange", "_onUploaderChange");
82 this.connect(this.uploader, "reset", "reset");
83 this.connect(this.uploader, "onBegin", function(){
84 this.showProgress(true);
85 });
86 this.connect(this.uploader, "onProgress", "_progress");
87 this.connect(this.uploader, "onComplete", function(){
88 setTimeout(lang.hitch(this, function(){
89 this.hideProgress(true);
90 }), 1250);
91 });
92 if(!(this._fileSizeAvail = {'html5':1,'flash':1}[this.uploader.uploadType])){
93 //if uploadType is neither html5 nor flash, file size is not available
94 //hide the size header
95 this.sizeHeader.style.display="none";
96 }
97 }else{
98 this._upCheckCnt++;
99 setTimeout(lang.hitch(this, "setUploader"), 250);
100 }
101 },
102
103 hideProgress: function(/*Boolean*/ animate){
104 var o = animate ? {
105 ani:true,
106 endDisp:"none",
107 beg:15,
108 end:0
109 } : {
110 endDisp:"none",
111 ani:false
112 };
113 this._hideShowProgress(o);
114 },
115
116 showProgress: function(/*Boolean*/ animate){
117 var o = animate ? {
118 ani:true,
119 endDisp:"block",
120 beg:0,
121 end:15
122 } : {
123 endDisp:"block",
124 ani:false
125 };
126 this._hideShowProgress(o);
127 },
128
129 _progress: function(/*Object*/ customEvent){
130 this.percentTextNode.innerHTML = customEvent.percent;
131 domStyle.set(this.percentBarNode, "width", customEvent.percent);
132 },
133
134 _hideShowProgress: function(o){
135 var node = this.progressNode;
136 var onEnd = function(){
137 domStyle.set(node, "display", o.endDisp);
138 };
139 if(o.ani){
140 domStyle.set(node, "display", "block");
141 fx.animateProperty({
142 node: node,
143 properties:{
144 height:{
145 start:o.beg,
146 end:o.end,
147 units:"px"
148 }
149 },
150 onEnd:onEnd
151 }).play();
152 }else{
153 onEnd();
154 }
155 },
156
157 _onUploaderChange: function(fileArray){
158 this.reset();
159 arrayUtil.forEach(fileArray, function(f, i){
160 this._addRow(i+1, this.getFileType(f.name), f.name, f.size);
161 }, this)
162 },
163
164 _addRow: function(index, type, name, size){
165
166 var c, r = this.listNode.insertRow(-1);
167 c = r.insertCell(-1);
168 domClass.add(c, "dojoxUploaderIndex");
169 c.innerHTML = index;
170
171 c = r.insertCell(-1);
172 domClass.add(c, "dojoxUploaderIcon");
173 c.innerHTML = type;
174
175 c = r.insertCell(-1);
176 domClass.add(c, "dojoxUploaderFileName");
177 c.innerHTML = name;
178 if(this._fileSizeAvail){
179 c = r.insertCell(-1);
180 domClass.add(c, "dojoxUploaderSize");
181 c.innerHTML = this.convertBytes(size).value;
182 }
183
184 this.rowAmt++;
185 }
186 });
187 });