Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / docs / source / UploadQueue.html
1 <html>\r
2 <head>\r
3   <title>The source code</title>\r
4     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
5     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
6 </head>\r
7 <body  onload="prettyPrint();">\r
8     <pre class="prettyprint lang-js">Imgorg.UploadQueue = Ext.extend(Ext.Panel,{
9     swfu: '',
10     autoRemove: false,
11     uploaded: false,
12     
13     initComponent: function() {
14         Ext.apply(this,{
15             layout: 'fit',
16             autoScroll: true,
17             items: [{
18                 xtype: 'dataview',
19                 id: 'img-uploaddv',
20                 autoWidth: true,
21                 tpl: new Ext.XTemplate(
22                     '<tpl for=".">',
23                         '<div class="upload-file" id="{id}">',
24                             '<div class="upload-name">{name}</div>',
25                             '<div id="{id}-pb" class="upload-pb"></div>',
26                             '<div class="x-clear"></div>',
27                             '<div class="upload-info">{size:fileSize}</div>',
28                         '</div>',
29                     '</tpl>'
30                 ),
31                 store: new Ext.data.JsonStore({
32                     root: '',
33                     id: 'id',
34                     fields: [
35                         {name: 'creationdate', type: 'date'},
36                         {name: 'modificationdate', type: 'date'},
37                         'filestatus','id','index','name','size','type','dbid'
38                     ]
39                 }),
40                 itemSelector: 'div.upload-file',
41                 selectedClass: 'upload-file-selected',
42                 singleSelect: true
43             }],
44             tbar:[{
45                 text: 'Start Upload',
46                 handler: this.startUpload,
47                 scope: this,
48                 iconCls: 'start-upload'
49             },{
50                 text: 'Clear',
51                 handler: this.cancelUpload,
52                 scope: this,
53                 iconCls: 'cancel'
54             },'-',{
55                 text: 'Add to Album',
56                 handler: this.addAllAlbum,
57                 scope: this,
58                 iconCls: 'album-add'
59             },{
60                 text: 'Tag',
61                 handler: this.tagAll,
62                 scope: this,
63                 iconCls: 'tag'
64             },
65             '->',{
66                 xtype: 'checkbox',
67                 checked: this.autoRemove,
68                 listeners: {
69                     check: function(cb, checked) {
70                         this.autoRemove = checked;
71                     },
72                     scope: this
73                 }
74             },'Auto-Remove Uploaded']
75         });
76         Imgorg.UploadQueue.superclass.initComponent.call(this);
77         
78         this.progressBars = {};
79         
80         Ext.ux.SwfuMgr.on('filequeued', this.addFile, this);
81         Ext.ux.SwfuMgr.on('uploadprogress', this.updateProgress, this);
82         Ext.ux.SwfuMgr.on('uploadsuccess', this.uploadSuccess, this);
83     },
84     
85     getDv: function() {
86         if (!this.imgUplDv) {
87             this.imgUplDv = this.getComponent('img-uploaddv');
88         }
89         return this.imgUplDv;
90     },
91     
92     startUpload: function() {
93         this.swfu.startUpload();
94     },
95     
96     cancelUpload: function() {
97         this.swfu.cancelUpload();
98         for (var pb in this.progressBars) {
99             this.progressBars[pb].destroy();
100         }
101         this.getDv().store.removeAll();
102         this.uploaded = false;
103     },
104     
105     addFile: function(swfu, file) {
106         this.getDv().store.loadData([file], true);
107     },
108     
109     addAllAlbum: function(btn) {
110         if (!this.uploaded) {
111             Ext.Msg.alert('Warning', 'You must upload files before you can add them to an Album');
112             return;
113         }
114         var dv = this.getDv();
115         var recs = dv.getRecords(dv.getNodes());
116         if (!this.albumWin) {
117             this.albumWin = new Imgorg.AlbumWin();
118         }
119         this.albumWin.selectedRecords = recs;
120         this.albumWin.show(btn.btnEl.dom);
121     },
122     
123     tagAll: function(btn) {
124         if (!this.uploaded) {
125             Ext.Msg.alert('Warning', 'You must upload files before you can Tag them');
126             return;
127         }
128         var dv = this.getDv();
129         var recs = dv.getRecords(dv.getNodes());
130         Imgorg.TagWin.selectedRecords = recs;
131         Imgorg.TagWin.show(btn.btnEl.dom);
132     },
133     
134     updateProgress: function(swfu, file, complete, total) {
135         if (this.progressBars[file.id]) {
136             this.progressBars[file.id].updateProgress(file.percentUploaded/100,Math.round(file.percentUploaded)+'% Completed... '+Ext.util.Format.fileSize(file.currentSpeed)+'s');
137         } else {
138             this.progressBars[file.id] = new Ext.ProgressBar({
139                 text:'0% Completed...',
140                 renderTo: file.id+'-pb'
141             });
142         }
143     },
144     
145     uploadSuccess: function(swfu, file, data) {
146         var store = this.getDv().store;
147         var rec = store.getById(file.id);
148         if (this.progressBars[file.id]) {
149             this.progressBars[file.id].updateProgress(1, '100% Completed...');
150         }
151         if (this.autoRemove) {
152             store.remove(rec);
153         }
154         var data = Ext.decode(Ext.util.Format.stripTags(data));
155         rec.data.dbid = data.result.res.id;
156         this.uploaded = true;
157     }
158 });
159 Ext.reg('img-uploadqueue', Imgorg.UploadQueue);
160
161 Ext.ux.SwfuManager = Ext.extend(Ext.util.Observable, {
162     constructor: function(config) {
163         Ext.ux.SwfuManager.superclass.constructor.call(this, config);
164         this.addEvents(
165             'filequeued',
166             'uploadstart',
167             'uploadprogress',
168             'uploaderror',
169             'uploadsuccess'
170         );
171     }
172 });
173
174 Ext.ux.SwfuMgr = new Ext.ux.SwfuManager();
175 </pre>    \r
176 </body>\r
177 </html>