Project

General

Profile

Revision 212

View differences:

trunk/scripts/extjs3-ext/ux.swfupload/SwfUploadPanel.css
1
.SwfUploadPanel_iconAdd {
2
	background-image:url(add.png) !important;
3
}
4

  
5
.SwfUploadPanel_iconUpload {
6
	background-image:url(arrow_up.png) !important;
7
}
8

  
9
.SwfUploadPanel_iconCancel {
10
	background-image:url(delete.png) !important;
11
}
12
.SwfUploadPanel_iconClear {
13
	background-image:url(cancel.png) !important;
14
}
15 0

  
trunk/scripts/extjs3-ext/ux.swfupload/SwfUploadPanel.js
1
// Create user extension namespace
2
Ext.namespace('Ext.ux');
3

  
4
/**
5
 * @class Ext.ux.SwfUploadPanel
6
 * @extends Ext.grid.GridPanel
7

  
8
 * Makes a Panel to provide the ability to upload multiple files using the SwfUpload flash script.
9
 *
10
 * @author Stephan Wentz
11
 * @author Michael Giddens (Original author)
12
 * @website http://www.brainbits.net
13
 * @created 2008-02-26
14
 * @version 0.5
15
 * 
16
 * known_issues 
17
 *      - Progress bar used hardcoded width. Not sure how to make 100% in bbar
18
 *      - Panel requires width / height to be set.  Not sure why it will not fit
19
 *      - when panel is nested sometimes the column model is not always shown to fit until a file is added. Render order issue.
20
 *      
21
 * @constructor
22
 * @param {Object} config The config object
23
 */
24
Ext.ux.SwfUploadPanel = Ext.extend(Ext.grid.GridPanel, {
25
    
26
    /**
27
     * @cfg {Object} strings
28
     * All strings used by Ext.ux.SwfUploadPanel
29
     */
30
    strings: {
31
        text_add: 'Add File(s)',
32
        text_upload: 'Upload File(s)',
33
        text_cancel: 'Cancel Upload',
34
        text_clear: 'Clear Queue',
35
        text_progressbar: 'Progress Bar',
36
        text_remove: 'Remove File',
37
        text_remove_sure: 'Are you sure you wish to remove this file from queue?',
38
        text_error: 'Error',
39
        text_uploading: 'Uploading file: {0} ({1} of {2})',
40
        header_filename: 'Filename',
41
        header_size: 'Size',
42
        header_status: 'Status',
43
        status: {
44
            0: 'Queued',
45
            1: 'Uploading...',
46
            2: 'Completed',
47
            3: 'Error',
48
            4: 'Cancelled'
49
        },
50
        error_queue_exceeded: 'The selected file(s) exceed(s) the maximum number of {0} queued files.',
51
        error_queue_slots_0: 'There is no slot left',
52
        error_queue_slots_1: 'There is only one slot left',
53
        error_queue_slots_2: 'There are only {0} slots left',
54
        error_size_exceeded: 'The selected files size exceeds the allowed limit of {0}.',
55
        error_zero_byte_file: 'Zero byte file selected.',
56
        error_invalid_filetype: 'Invalid filetype selected.',
57
        error_file_not_found: 'File not found 404.',
58
        error_security_error: 'Security Error. Not allowed to post to different url.'
59
    },
60
    
61
    /**
62
     * @cfg {Boolean} single_select
63
     * True to allow multiple file selections, false for single file selection.
64
     * Please note that this doesn't affect the number of allowed files in the queue. 
65
     * Use the {@link #file_queue_limit} parameter to change the allowed number of files in the queue. 
66
     */
67
    single_select: false,
68
    /**
69
     * @cfg {Boolean} confirm_delete
70
     * Show a confirmation box on deletion of queued files.
71
     */ 
72
    confirm_delete: true,
73
    /**
74
     * @cfg {String} file_types
75
     * Allowed file types for the File Selection Dialog. Use semi-colon as a seperator for multiple file-types.
76
     */ 
77
    file_types: "*.*",                   // Default allow all file types
78
    /**
79
     * @cfg {String} file_types
80
     * A text description that is displayed to the user in the File Browser dialog.
81
     */ 
82
    file_types_description: "All Files", // 
83
    /**
84
     * @cfg {String} file_size_limit
85
     * The file_size_limit setting defines the maximum allowed size of a file to be uploaded. 
86
     * This setting accepts a value and unit. Valid units are B, KB, MB and GB. If the unit is omitted default is KB. 
87
     * A value of 0 (zero) is interpretted as unlimited.
88
     */ 
89
    file_size_limit: "1048576",          // Default size limit 100MB
90
    /**
91
     * @cfg {String} file_upload_limit
92
     * Defines the number of files allowed to be uploaded by SWFUpload. 
93
     * This setting also sets the upper bound of the {@link #file_queue_limit} setting. 
94
     * The value of 0 (zero) is interpretted as unlimited.
95
     */ 
96
    file_upload_limit: "0",              // Default no upload limit
97
    /**
98
     * @cfg {String} file_queue_limit
99
     * Defines the number of unprocessed files allowed to be simultaneously queued.
100
     * The value of 0 (zero) is interpretted as unlimited.
101
     */ 
102
    file_queue_limit: "0",               // Default no queue limit
103
    /**
104
     * @cfg {String} file_post_name
105
     * The file_post_name allows you to set the value name used to post the file.
106
     */ 
107
    file_post_name: "Filedata",          // Default name
108
    /**
109
     * @cfg {String} flash_url
110
     * The full, absolute, or relative URL to the Flash Control swf file.
111
     */ 
112
    flash_url: "swfupload.swf",       // Default url, relative to the page url
113
    /**
114
     * @cfg {Boolean} debug
115
     * A boolean value that defines whether the debug event handler should be fired.
116
     */ 
117
    debug: false,
118
    
119
    // standard grid parameters
120
    autoExpandColumn: 'name',
121
    enableColumnResize: false,
122
    enableColumnMove: false,
123

  
124
    // private
125
    upload_cancelled: false,
126
        
127
    // private
128
    initComponent: function() {
129
       var grid = this; 
130
        this.addEvents(
131
            /**
132
             * @event swfUploadLoaded
133
             * Fires after the Flash object has been loaded
134
             * @param {Ext.grid.GridPanel} grid This grid
135
             */
136
            'swfUploadLoaded',
137
            /**
138
             * @event swfUploadLoaded
139
             * Fires after a file has been qeueud
140
             * @param {Ext.grid.GridPanel} grid This grid
141
             * @param {Object} file The file object that produced the error
142
             */
143
            'fileQueued',
144
            /**
145
             * @event startUpload
146
             * Fires before the upload starts
147
             * @param {Ext.grid.GridPanel} grid This grid
148
             */
149
            'startUpload',
150
            /**
151
             * @event fileUploadError
152
             * Fires after an upload has been stopped or cancelled
153
             * @param {Ext.grid.GridPanel} grid This grid
154
             * @param {Object} file The file object that produced the error
155
             * @param {String} code The error code
156
             * @param {String} message Supplemental error message
157
             */
158
            'fileUploadError',
159
            /**
160
             * @event fileUploadSuccess
161
             * Fires after an upload has been successfully uploaded
162
             * @param {Ext.grid.GridPanel} grid This grid
163
             * @param {Object} file The file object that has been uploaded
164
             * @param {Object} data The response data of the upload request
165
             */
166
            'fileUploadSuccess',
167
            /**
168
             * @event fileUploadComplete
169
             * Fires after the upload cycle for one file finished
170
             * @param {Ext.grid.GridPanel} grid This grid
171
             * @param {Object} file The file object that has been uploaded
172
             */
173
            'fileUploadComplete',
174
            /**
175
             * @event fileUploadComplete
176
             * Fires after the upload cycle for all files in the queue finished
177
             * @param {Ext.grid.GridPanel} grid This grid
178
             */
179
            'allUploadsComplete',
180
            /**
181
             * @event fileUploadComplete
182
             * Fires after one or more files have been removed from the queue
183
             * @param {Ext.grid.GridPanel} grid This grid
184
             */
185
            'removeFiles',
186
            /**
187
             * @event fileUploadComplete
188
             * Fires after all files have been removed from the queue
189
             * @param {Ext.grid.GridPanel} grid This grid
190
             */
191
            'removeAllFiles'
192
        );
193
        
194
        this.rec = Ext.data.Record.create([
195
             {name: 'name'},
196
             {name: 'size'},
197
             {name: 'id'},
198
             {name: 'type'},
199
             {name: 'creationdate', type: 'date', dateFormat: 'm/d/Y'},
200
             {name: 'status'}
201
        ]);
202
        
203
        this.store = new Ext.data.Store({
204
            reader: new Ext.data.JsonReader({
205
                  id: 'id'
206
             }, this.rec)
207
        });
208
        
209
        this.columns = [{
210
            id:'name', 
211
            header: this.strings.header_filename, 
212
            dataIndex: 'name'
213
        },{
214
            id:'size', 
215
            header: this.strings.header_size, 
216
            width: 80, 
217
            dataIndex: 'size', 
218
            renderer: this.formatBytes
219
        },{
220
            id:'status', 
221
            header: this.strings.header_status, 
222
            width: 80, 
223
            dataIndex: 'status', 
224
            renderer: this.formatStatus.createDelegate(this)
225
        }];
226
        
227
        this.sm = new Ext.grid.RowSelectionModel({
228
            singleSelect: this.single_select
229
        });
230

  
231

  
232
        this.progress_bar = new Ext.ProgressBar({
233
            text: this.strings.text_progressbar
234
//            width: this.width - 7
235
        }); 
236

  
237
        this.tbar = [{
238
            text: this.strings.text_add,
239
            iconCls: 'SwfUploadPanel_iconAdd',
240
            id: 'swfuploadpanel-add-button',
241
            xhandler: function() {
242
                if (this.single_select) {
243
                    this.suo.selectFile();
244
                }
245
                else {
246
                    this.suo.selectFiles();
247
                }
248
            },
249
            xscope: this,
250
            listeners: {
251
                render: function() {
252
                    grid.myInit();
253
                }
254
            }
255
        }, '->', {
256
            text: this.strings.text_cancel,
257
            id: 'swfuploadpanel-cancel-button',
258
            iconCls: 'SwfUploadPanel_iconCancel',
259
            handler: this.stopUpload,
260
            scope: this,
261
            hidden: true
262
        }, {
263
            text: this.strings.text_upload,
264
            id: 'swfuploadpanel-upload-button',
265
            iconCls: 'SwfUploadPanel_iconUpload',
266
            handler: this.startUpload,
267
            scope: this,
268
            hidden: true
269
        }, {
270
            text: this.strings.text_clear,
271
            id: 'swfuploadpanel-clear-button',
272
            iconCls: 'SwfUploadPanel_iconClear',
273
            handler: this.removeAllFiles,
274
            scope: this,
275
            hidden: false
276
        }];
277
        
278
        this.bbar = [
279
            this.progress_bar
280
        ];
281
        
282
        Ext.ux.SwfUploadPanel.superclass.initComponent.call(this);
283
        this.addListener({
284
            keypress: {
285
                fn: function(e) {
286
                    if (this.confirm_delete) {
287
                        if(e.getKey() == e.DELETE) {
288
                            Ext.MessageBox.confirm(this.strings.text_remove,this.strings.text_remove_sure, function(e) {
289
                                if (e == 'yes') {
290
                                    this.removeFiles();
291
                                }
292
                            }, this);
293
                        }   
294
                    } else {
295
                        this.removeFiles(this);
296
                    }
297
                },
298
                scope: this
299
            },
300
            
301
            // Prevent the default right click to show up in the grid.
302
            contextmenu: function(e) {
303
                e.stopEvent();
304
            }
305
        });
306
    },
307
    onRender: function() {
308
        Ext.ux.SwfUploadPanel.superclass.onRender.apply(this,arguments);
309
		
310
		this.setHeight( parseInt( this.height ) );
311
		
312
        this.resizeProgressBar();
313
        var tb = this.getTopToolbar();
314
        this.addBtn = Ext.getCmp('swfuploadpanel-add-button');
315
        this.cancelBtn = Ext.getCmp('swfuploadpanel-cancel-button');
316
        this.uploadBtn = Ext.getCmp('swfuploadpanel-upload-button');
317
        this.clearBtn = Ext.getCmp('swfuploadpanel-clear-button');
318
        this.on('resize', this.resizeProgressBar, this);
319
		
320
    
321
    },
322
    myInit: function() {
323
        var suoID = Ext.id();
324
        var em = this.addBtn.el.child('em');
325
        em.setStyle({
326
            position: 'relative',
327
            display: 'block'
328
        });
329
        em.createChild({
330
            tag: 'div',
331
            id: suoID
332
        });
333
        this.suo = new SWFUpload({
334
            button_placeholder_id: suoID,
335
            button_width: em.getWidth(),
336
            button_height: em.getHeight(),
337
            button_cursor: SWFUpload.CURSOR.HAND,
338
            button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
339
            
340
            upload_url: this.upload_url,
341
            post_params: this.post_params,
342
            file_post_name: this.file_post_name,  
343
            file_size_limit: this.file_size_limit,
344
            file_queue_limit: this.file_queue_limit,
345
            file_types: this.file_types,
346
            file_types_description: this.file_types_description,
347
            file_upload_limit: this.file_upload_limit,
348
            flash_url: this.flash_url,   
349
			prevent_swf_caching: this.prevent_swf_caching,
350
    
351
            // Event Handler Settings
352
            swfupload_loaded_handler: this.swfUploadLoaded.createDelegate(this),
353
    
354
            file_dialog_start_handler: this.fileDialogStart.createDelegate(this),
355
            file_queued_handler: this.fileQueue.createDelegate(this),
356
            file_queue_error_handler: this.fileQueueError.createDelegate(this),
357
            file_dialog_complete_handler: this.fileDialogComplete.createDelegate(this),
358
            
359
            upload_start_handler: this.uploadStart.createDelegate(this),
360
            upload_progress_handler: this.uploadProgress.createDelegate(this),
361
            upload_error_handler: this.uploadError.createDelegate(this), 
362
            upload_success_handler: this.uploadSuccess.createDelegate(this),
363
            upload_complete_handler: this.uploadComplete.createDelegate(this),
364
    
365
            debug: this.debug,
366
            debug_handler: this.debugHandler
367
        });
368
        
369
        Ext.get(this.suo.movieName).setStyle({
370
            position: 'absolute', 
371
            top: 0,
372
            left: 0
373
        });
374
    },
375

  
376
    // private
377
    resizeProgressBar: function() {
378
        if (this.progress_bar.el) {
379
            this.progress_bar.setWidth(this.getBottomToolbar().el.getWidth() - 5);
380
            Ext.fly(this.progress_bar.el.dom.firstChild.firstChild).applyStyles("height: 16px");
381
        }
382
    },
383
    
384
    /**
385
     * SWFUpload debug handler
386
     * @param {Object} line
387
     */
388
    debugHandler: function(line) {
389
        if( typeof console != "undefined" ) {
390
        	console.log(line);
391
        }
392
    },
393
    
394
    /**
395
     * Formats file status
396
     * @param {Integer} status
397
     * @return {String}
398
     */
399
    formatStatus: function(status) {
400
        return this.strings.status[status];
401
    },
402
    
403
    /**
404
     * Formats raw bytes into kB/mB/GB/TB
405
     * @param {Integer} bytes
406
     * @return {String}
407
     */
408
    formatBytes: function(size) {
409
        if (!size) {
410
            size = 0;
411
        }
412
        var suffix = ["B", "KB", "MB", "GB"];
413
        var result = size;
414
        size = parseInt(size, 10);
415
        result = size + " " + suffix[0];
416
        var loop = 0;
417
        while (size / 1024 > 1) {
418
            size = size / 1024;
419
            loop++;
420
        }
421
        result = Math.round(size) + " " + suffix[loop];
422

  
423
        return result;
424

  
425
    },
426

  
427
    /**
428
     * SWFUpload swfUploadLoaded event
429
     */
430
    swfUploadLoaded: function() {
431
        if(this.debug) console.info('SWFUPLOAD LOADED');
432
        
433
        this.fireEvent('swfUploadLoaded', this);
434
    },
435
        
436
    /**
437
     * SWFUpload fileDialogStart event
438
     */
439
    fileDialogStart: function() {
440
        if(this.debug) console.info('FILE DIALOG START');
441
        
442
        this.fireEvent('fileDialogStart', this);
443
    },
444
    
445
    /**
446
     * Add file to store / grid
447
     * SWFUpload fileQueue event
448
     * @param {Object} file
449
     */
450
    fileQueue: function(file) {
451
        if(this.debug) console.info('FILE QUEUE');
452
        
453
        file.status = 0;
454
        r = new this.rec(file);
455
        r.id = file.id;
456
        this.store.add(r);
457
        
458
        this.fireEvent('fileQueued', this, file);
459
    },
460

  
461
    /**
462
     * Error when file queue error occurs
463
     * SWFUpload fileQueueError event
464
     * @param {Object}  file
465
     * @param {Integer} code
466
     * @param {string}  message
467
     */
468
    fileQueueError: function(file, code, message) {
469
        if(this.debug) console.info('FILE QUEUE ERROR');
470

  
471
        switch (code) {
472
            case -100: 
473
                var slots;
474
                switch(message) {
475
                    case '0':
476
                        slots = this.strings.error_queue_slots_0;
477
                        break;
478
                    case '1':
479
                        slots = this.strings.error_queue_slots_1;
480
                        break;
481
                    default:
482
                        slots = String.format(this.strings.error_queue_slots_2, message);
483
                }
484
                Ext.MessageBox.alert(this.strings.text_error, String.format(this.strings.error_queue_exceeded + ' ' + slots, this.file_queue_limit));
485
                break;
486
                
487
            case -110:				
488
               Ext.MessageBox.alert(this.strings.text_error, String.format(this.strings.error_size_exceeded, this.formatBytes( parseInt(this.file_size_limit) )));
489
                break;
490

  
491
            case -120:
492
                Ext.MessageBox.alert(this.strings.text_error, this.strings.error_zero_byte_file);
493
                break;
494

  
495
            case -130:
496
                Ext.MessageBox.alert(this.strings.text_error, this.strings.error_invalid_filetype);
497
                break;
498
        }
499
        
500
        this.fireEvent('fileQueueError', this, file, code );
501
    },
502

  
503
    /**
504
     * SWFUpload fileDialogComplete event
505
     * @param {Integer} file_count
506
     */
507
    fileDialogComplete: function(file_count) {
508
        if(this.debug) console.info('FILE DIALOG COMPLETE');
509
        
510
        if (file_count > 0) {
511
            this.uploadBtn.show();
512
        }
513
        
514
        this.addBtn.show();
515
        this.clearBtn.show();
516
        
517
        this.fireEvent('fileDialogComplete', this, file_count);
518
    },
519

  
520
    /**
521
     * SWFUpload uploadStart event
522
     * @param {Object} file
523
     */
524
    uploadStart: function(file) {
525
        if(this.debug) console.info('UPLOAD START');
526
        
527
        this.fireEvent('uploadStart', this, file);
528
        
529
        return true;
530
    },
531
    
532
    /**
533
     * SWFUpload uploadProgress event
534
     * @param {Object}  file
535
     * @param {Integer} bytes_completed
536
     * @param {Integer} bytes_total
537
     */
538
    uploadProgress: function(file, bytes_completed, bytes_total) {
539
        if(this.debug) console.info('UPLOAD PROGRESS');
540
        
541
        this.store.getById(file.id).set('status', 1);       
542
        this.store.getById(file.id).commit();
543
        this.progress_bar.updateProgress(bytes_completed/bytes_total, String.format(this.strings.text_uploading, file.name, this.formatBytes(bytes_completed), this.formatBytes(bytes_total)));
544
        
545
        this.fireEvent('uploadProgress', this, file, bytes_completed, bytes_total);
546
    },
547

  
548
    /**
549
     * SWFUpload uploadError event
550
     * Show notice when error occurs
551
     * @param {Object} file
552
     * @param {Integer} error
553
     * @param {Integer} code
554
     * @return {}
555
     */
556
    uploadError: function(file, error, code) {
557
        if(this.debug) console.info('UPLOAD ERROR');
558

  
559
        switch (error) {
560
            case -200:  
561
                Ext.MessageBox.alert(this.strings.text_error, this.strings.error_file_not_found);
562
                break;
563
                
564
            case -230:  
565
                Ext.MessageBox.alert(this.strings.text_error, this.strings.error_security_error);
566
                break;
567
                
568
            case -290:
569
                this.store.getById(file.id).set('status', 4);
570
                this.store.getById(file.id).commit();
571
                break;
572
        }
573
        
574
        this.fireEvent('fileUploadError', this, file, error, code);
575
    },
576

  
577
    /**
578
     * SWFUpload uploadSuccess event
579
     * @param {Object} file
580
     * @param {Object} response
581
     */ 
582
    uploadSuccess: function(file, response) {
583
        if(this.debug) console.info('UPLOAD SUCCESS');
584
        
585
        var data = Ext.decode(response); 
586
        if (data.success) {
587
            this.store.remove(this.store.getById(file.id));
588
        } else {
589
            this.store.getById(file.id).set('status', 3);
590
            this.store.getById(file.id).commit();
591
            if (data.msg) {
592
                Ext.MessageBox.alert(this.strings.text_error, data.msg);
593
            }
594
        }
595
        
596
        
597
        this.fireEvent('fileUploadSuccess', this, file, data);
598
    },
599

  
600
    /**
601
     * SWFUpload uploadComplete event
602
     * @param {Object} file
603
     */
604
    uploadComplete: function(file) {
605
        if(this.debug) console.info('UPLOAD COMPLETE');
606
        
607
        this.progress_bar.reset();
608
        this.progress_bar.updateText(this.strings.text_progressbar);
609
        
610
        if(this.suo.getStats().files_queued && !this.upload_cancelled) {
611
            this.suo.startUpload();
612
        } else {
613
            this.fireEvent('fileUploadComplete', this, file);
614
            
615
            this.allUploadsComplete();
616
        }
617
        
618
    },
619
    
620
    /**
621
     * SWFUpload allUploadsComplete method
622
     */
623
    allUploadsComplete: function() {
624
        this.cancelBtn.hide();
625
        this.addBtn.show();
626
        this.clearBtn.show();
627
        
628
        this.fireEvent('allUploadsComplete', this);
629
    },
630
    
631
    /**
632
     * SWFUpload setPostParams method
633
     * @param {String} name
634
     * @param {String} value
635
     */
636
    addPostParam: function(name, value) {
637
        if (this.suo) {
638
            this.suo.settings.post_params[name] = value;
639
            this.suo.setPostParams(this.suo.settings.post_params);
640
        } else {
641
            this.post_params[name] = value;
642
        }
643
    },
644
        
645
    /**
646
     * Start file upload
647
     * SWFUpload startUpload method
648
     */
649
    startUpload: function() {
650
        if(this.debug) console.info('START UPLOAD');
651
        
652
        this.cancelBtn.show();
653
        this.uploadBtn.hide();
654
        this.clearBtn.hide();
655
//        this.addBtn.hide();
656
        
657
        this.upload_cancelled = false;
658
        
659
        this.fireEvent('startUpload', this);
660
        
661
        this.suo.startUpload();
662
    },
663
    
664
    /**
665
     * SWFUpload stopUpload method
666
     * @param {Object} file
667
     */
668
    stopUpload: function(file) {
669
        if(this.debug) console.info('STOP UPLOAD');
670
        
671
        this.suo.stopUpload();
672
        
673
        this.upload_cancelled = true;
674
        
675
        this.getStore().each(function() {
676
            if (this.data.status == 1) {
677
                this.set('status', 0);
678
                this.commit();
679
            }
680
        });
681

  
682
        this.cancelBtn.hide();
683
        if (this.suo.getStats().files_queued > 0) {
684
            this.uploadBtn.show();
685
        }
686
        this.addBtn.show();
687
        this.clearBtn.show();
688

  
689
        this.progress_bar.reset();
690
        this.progress_bar.updateText(this.strings.text_progressbar);
691

  
692
    },
693
    
694
    /**
695
     * Delete one or multiple rows
696
     * SWFUpload cancelUpload method
697
     */
698
    removeFiles: function() {
699
        if(this.debug) console.info('REMOVE FILES');
700
        
701
        var selRecords = this.getSelections();
702
        for (var i=0; i < selRecords.length; i++) {
703
            if (selRecords[i].data.status != 1) {
704
                this.suo.cancelUpload(selRecords[i].id);
705
                this.store.remove(selRecords[i]);
706
            }
707
        }
708
        
709
        if (this.suo.getStats().files_queued === 0) {
710
            this.uploadBtn.hide();
711
//            this.clearBtn.hide();
712
        }
713
        
714
        this.fireEvent('removeFiles', this);
715
    },
716
    
717
    /**
718
     * Clear the Queue
719
     * SWFUpload cancelUpload method
720
     */
721
    removeAllFiles: function() {
722
        if(this.debug) console.info('REMOVE ALL');
723
        
724
        // mark all internal files as cancelled
725
        var files_left = this.suo.getStats().files_queued;
726

  
727
        while (files_left > 0) {
728
            this.suo.cancelUpload();
729
            files_left = this.suo.getStats().files_queued;
730
        }
731
        
732
        this.store.removeAll();
733
        
734
        this.cancelBtn.hide();
735
        this.uploadBtn.hide();
736
//        this.clearBtn.hide();
737
        
738
        this.fireEvent('removeAllFiles', this);
739
    }   
740
    
741
});
742
Ext.reg("swfuploadpanel", Ext.ux.SwfUploadPanel );
743 0

  
trunk/scripts/extjs3-ext/ux.swfupload/SwfUpload.js
1
/**
2
 * SWFUpload: http://www.swfupload.org, http://swfupload.googlecode.com
3
 *
4
 * mmSWFUpload 1.0: Flash upload dialog - http://profandesign.se/swfupload/,  http://www.vinterwebb.se/
5
 *
6
 * SWFUpload is (c) 2006-2007 Lars Huring, Olov Nilz?n and Mammon Media and is released under the MIT License:
7
 * http://www.opensource.org/licenses/mit-license.php
8
 *
9
 * SWFUpload 2 is (c) 2007-2008 Jake Roberts and is released under the MIT License:
10
 * http://www.opensource.org/licenses/mit-license.php
11
 *
12
 * SWFObject v2.2 <http://code.google.com/p/swfobject/> 
13
 *	is released under the MIT License <http://www.opensource.org/licenses/mit-license.php> 
14
 */
15

  
16

  
17

  
18
/* ******************* */
19
/* Constructor & Init  */
20
/* ******************* */
21
var SWFUpload;
22
var swfobject;
23

  
24
if (SWFUpload == undefined) {
25
	SWFUpload = function (settings) {
26
		this.initSWFUpload(settings);
27
	};
28
}
29

  
30
SWFUpload.prototype.initSWFUpload = function (userSettings) {
31
	try {
32
		this.customSettings = {};	// A container where developers can place their own settings associated with this instance.
33
		this.settings = {};
34
		this.eventQueue = [];
35
		this.movieName = "SWFUpload_" + SWFUpload.movieCount++;
36
		this.movieElement = null;
37

  
38

  
39
		// Setup global control tracking
40
		SWFUpload.instances[this.movieName] = this;
41

  
42
		// Load the settings.  Load the Flash movie.
43
		this.initSettings(userSettings);
44
		this.loadSupport();
45
		if (this.swfuploadPreload()) {
46
			this.loadFlash();
47
		}
48

  
49
		this.displayDebugInfo();
50
	} catch (ex) {
51
		delete SWFUpload.instances[this.movieName];
52
		throw ex;
53
	}
54
};
55

  
56
/* *************** */
57
/* Static Members  */
58
/* *************** */
59
SWFUpload.instances = {};
60
SWFUpload.movieCount = 0;
61
SWFUpload.version = "2.5.0 2010-01-15 Beta 2";
62
SWFUpload.QUEUE_ERROR = {
63
	QUEUE_LIMIT_EXCEEDED            : -100,
64
	FILE_EXCEEDS_SIZE_LIMIT         : -110,
65
	ZERO_BYTE_FILE                  : -120,
66
	INVALID_FILETYPE                : -130
67
};
68
SWFUpload.UPLOAD_ERROR = {
69
	HTTP_ERROR                      : -200,
70
	MISSING_UPLOAD_URL              : -210,
71
	IO_ERROR                        : -220,
72
	SECURITY_ERROR                  : -230,
73
	UPLOAD_LIMIT_EXCEEDED           : -240,
74
	UPLOAD_FAILED                   : -250,
75
	SPECIFIED_FILE_ID_NOT_FOUND     : -260,
76
	FILE_VALIDATION_FAILED          : -270,
77
	FILE_CANCELLED                  : -280,
78
	UPLOAD_STOPPED                  : -290,
79
	RESIZE                          : -300
80
};
81
SWFUpload.FILE_STATUS = {
82
	QUEUED       : -1,
83
	IN_PROGRESS  : -2,
84
	ERROR        : -3,
85
	COMPLETE     : -4,
86
	CANCELLED    : -5
87
};
88
SWFUpload.UPLOAD_TYPE = {
89
	NORMAL       : -1,
90
	RESIZED      : -2
91
};
92

  
93
SWFUpload.BUTTON_ACTION = {
94
	SELECT_FILE             : -100,
95
	SELECT_FILES            : -110,
96
	START_UPLOAD            : -120,
97
	JAVASCRIPT              : -130,	// DEPRECATED
98
	NONE                    : -130
99
};
100
SWFUpload.CURSOR = {
101
	ARROW : -1,
102
	HAND  : -2
103
};
104
SWFUpload.WINDOW_MODE = {
105
	WINDOW       : "window",
106
	TRANSPARENT  : "transparent",
107
	OPAQUE       : "opaque"
108
};
109

  
110
SWFUpload.RESIZE_ENCODING = {
111
	JPEG  : -1,
112
	PNG   : -2
113
};
114

  
115
// Private: takes a URL, determines if it is relative and converts to an absolute URL
116
// using the current site. Only processes the URL if it can, otherwise returns the URL untouched
117
SWFUpload.completeURL = function (url) {
118
	try {
119
		var path = "", indexSlash = -1;
120
		if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//) || url === "") {
121
			return url;
122
		}
123
		
124
		indexSlash = window.location.pathname.lastIndexOf("/");
125
		if (indexSlash <= 0) {
126
			path = "/";
127
		} else {
128
			path = window.location.pathname.substr(0, indexSlash) + "/";
129
		}
130
		
131
		return path + url;
132
	} catch (ex) {
133
		return url;
134
	}
135
};
136

  
137
// Public: assign a new function to onload to use swfobject's domLoad functionality
138
SWFUpload.onload = function () {};
139

  
140

  
141
/* ******************** */
142
/* Instance Members  */
143
/* ******************** */
144

  
145
// Private: initSettings ensures that all the
146
// settings are set, getting a default value if one was not assigned.
147
SWFUpload.prototype.initSettings = function (userSettings) {
148
	this.ensureDefault = function (settingName, defaultValue) {
149
		var setting = userSettings[settingName];
150
		if (setting != undefined) {
151
			this.settings[settingName] = setting;
152
		} else {
153
			this.settings[settingName] = defaultValue;
154
		}
155
	};
156
	
157
	// Upload backend settings
158
	this.ensureDefault("upload_url", "");
159
	this.ensureDefault("preserve_relative_urls", false);
160
	this.ensureDefault("file_post_name", "Filedata");
161
	this.ensureDefault("post_params", {});
162
	this.ensureDefault("use_query_string", false);
163
	this.ensureDefault("requeue_on_error", false);
164
	this.ensureDefault("http_success", []);
165
	this.ensureDefault("assume_success_timeout", 0);
166
	
167
	// File Settings
168
	this.ensureDefault("file_types", "*.*");
169
	this.ensureDefault("file_types_description", "All Files");
170
	this.ensureDefault("file_size_limit", 0);	// Default zero means "unlimited"
171
	this.ensureDefault("file_upload_limit", 0);
172
	this.ensureDefault("file_queue_limit", 0);
173

  
174
	// Flash Settings
175
	this.ensureDefault("flash_url", "swfupload.swf");
176
	this.ensureDefault("flash9_url", "swfupload_fp9.swf");
177
	this.ensureDefault("prevent_swf_caching", false);
178
	
179
	// Button Settings
180
	this.ensureDefault("button_image_url", "");
181
	this.ensureDefault("button_width", 1);
182
	this.ensureDefault("button_height", 1);
183
	this.ensureDefault("button_text", "");
184
	this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
185
	this.ensureDefault("button_text_top_padding", 0);
186
	this.ensureDefault("button_text_left_padding", 0);
187
	this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
188
	this.ensureDefault("button_disabled", false);
189
	this.ensureDefault("button_placeholder_id", "");
190
	this.ensureDefault("button_placeholder", null);
191
	this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
192
	this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
193
	
194
	// Debug Settings
195
	this.ensureDefault("debug", false);
196
	this.settings.debug_enabled = this.settings.debug;	// Here to maintain v2 API
197
	
198
	// Event Handlers
199
	this.settings.return_upload_start_handler = this.returnUploadStart;
200
	this.ensureDefault("swfupload_preload_handler", null);
201
	this.ensureDefault("swfupload_load_failed_handler", null);
202
	this.ensureDefault("swfupload_loaded_handler", null);
203
	this.ensureDefault("file_dialog_start_handler", null);
204
	this.ensureDefault("file_queued_handler", null);
205
	this.ensureDefault("file_queue_error_handler", null);
206
	this.ensureDefault("file_dialog_complete_handler", null);
207
	
208
	this.ensureDefault("upload_resize_start_handler", null);
209
	this.ensureDefault("upload_start_handler", null);
210
	this.ensureDefault("upload_progress_handler", null);
211
	this.ensureDefault("upload_error_handler", null);
212
	this.ensureDefault("upload_success_handler", null);
213
	this.ensureDefault("upload_complete_handler", null);
214
	
215
	this.ensureDefault("mouse_click_handler", null);
216
	this.ensureDefault("mouse_out_handler", null);
217
	this.ensureDefault("mouse_over_handler", null);
218
	
219
	this.ensureDefault("debug_handler", this.debugMessage);
220

  
221
	this.ensureDefault("custom_settings", {});
222

  
223
	// Other settings
224
	this.customSettings = this.settings.custom_settings;
225
	
226
	// Update the flash url if needed
227
	if (!!this.settings.prevent_swf_caching) {
228
		this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
229
		this.settings.flash9_url = this.settings.flash9_url + (this.settings.flash9_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
230
	}
231
	
232
	if (!this.settings.preserve_relative_urls) {
233
		this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
234
		this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
235
	}
236
	
237
	delete this.ensureDefault;
238
};
239

  
240
// Initializes the supported functionality based the Flash Player version, state, and event that occur during initialization
241
SWFUpload.prototype.loadSupport = function () {
242
	this.support = {
243
		loading : swfobject.hasFlashPlayerVersion("9.0.28"),
244
		imageResize : swfobject.hasFlashPlayerVersion("10.0.0")
245
	};
246
	
247
};
248

  
249
// Private: loadFlash replaces the button_placeholder element with the flash movie.
250
SWFUpload.prototype.loadFlash = function () {
251
	var targetElement, tempParent, wrapperType, flashHTML, els;
252

  
253
	if (!this.support.loading) {
254
		this.queueEvent("swfupload_load_failed_handler", ["Flash Player doesn't support SWFUpload"]);
255
		return;
256
	}
257
	
258
	// Make sure an element with the ID we are going to use doesn't already exist
259
	if (document.getElementById(this.movieName) !== null) {
260
		this.support.loading = false;
261
		this.queueEvent("swfupload_load_failed_handler", ["Element ID already in use"]);
262
		return;
263
	}
264

  
265
	// Get the element where we will be placing the flash movie
266
	targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
267

  
268
	if (targetElement == undefined) {
269
		this.support.loading = false;
270
		this.queueEvent("swfupload_load_failed_handler", ["button place holder not found"]);
271
		return;
272
	}
273

  
274
	wrapperType = (targetElement.currentStyle && targetElement.currentStyle["display"] || window.getComputedStyle && document.defaultView.getComputedStyle(targetElement, null).getPropertyValue("display")) !== "block" ? "span" : "div";
275
	
276
	// Append the container and load the flash
277
	tempParent = document.createElement(wrapperType);
278

  
279
	flashHTML = this.getFlashHTML();
280

  
281
	try {
282
		tempParent.innerHTML = flashHTML;	// Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)
283
	} catch (ex) {
284
		this.support.loading = false;
285
		this.queueEvent("swfupload_load_failed_handler", ["Exception loading Flash HTML into placeholder"]);
286
		return;
287
	}
288

  
289
	// Try to get the movie element immediately
290
	els = tempParent.getElementsByTagName("object");
291
	if (!els || els.length > 1 || els.length === 0) {
292
		this.support.loading = false;
293
		this.queueEvent("swfupload_load_failed_handler", ["Unable to find movie after adding to DOM"]);
294
		return;
295
	} else if (els.length === 1) {
296
		this.movieElement = els[0];
297
	}
298
	
299
	targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
300

  
301
	// Fix IE Flash/Form bug
302
	if (window[this.movieName] == undefined) {
303
		window[this.movieName] = this.getMovieElement();
304
	}
305
};
306

  
307
// Private: getFlashHTML generates the object tag needed to embed the flash in to the document
308
SWFUpload.prototype.getFlashHTML = function (flashVersion) {
309
	// Flash Satay object syntax: http://www.alistapart.com/articles/flashsatay
310
	return ['<object id="', this.movieName, '" type="application/x-shockwave-flash" data="', (this.support.imageResize ? this.settings.flash_url : this.settings.flash9_url), '" width="', this.settings.button_width, '" height="', this.settings.button_height, '" class="swfupload">',
311
				'<param name="wmode" value="', this.settings.button_window_mode, '" />',
312
				'<param name="movie" value="', (this.support.imageResize ? this.settings.flash_url : this.settings.flash9_url), '" />',
313
				'<param name="quality" value="high" />',
314
				'<param name="allowScriptAccess" value="always" />',
315
				'<param name="flashvars" value="' + this.getFlashVars() + '" />',
316
				'</object>'].join("");
317
};
318

  
319
// Private: getFlashVars builds the parameter string that will be passed
320
// to flash in the flashvars param.
321
SWFUpload.prototype.getFlashVars = function () {
322
	// Build a string from the post param object
323
	var httpSuccessString, paramString;
324
	
325
	paramString = this.buildParamString();
326
	httpSuccessString = this.settings.http_success.join(",");
327
	
328
	// Build the parameter string
329
	return ["movieName=", encodeURIComponent(this.movieName),
330
			"&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
331
			"&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
332
			"&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
333
			"&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
334
			"&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
335
			"&amp;params=", encodeURIComponent(paramString),
336
			"&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
337
			"&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
338
			"&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
339
			"&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
340
			"&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
341
			"&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
342
			"&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
343
			"&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
344
			"&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
345
			"&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
346
			"&amp;buttonText=", encodeURIComponent(this.settings.button_text),
347
			"&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
348
			"&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
349
			"&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
350
			"&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
351
			"&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
352
			"&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
353
		].join("");
354
};
355

  
356
// Public: get retrieves the DOM reference to the Flash element added by SWFUpload
357
// The element is cached after the first lookup
358
SWFUpload.prototype.getMovieElement = function () {
359
	if (this.movieElement == undefined) {
360
		this.movieElement = document.getElementById(this.movieName);
361
	}
362

  
363
	if (this.movieElement === null) {
364
		throw "Could not find Flash element";
365
	}
366
	
367
	return this.movieElement;
368
};
369

  
370
// Private: buildParamString takes the name/value pairs in the post_params setting object
371
// and joins them up in to a string formatted "name=value&amp;name=value"
372
SWFUpload.prototype.buildParamString = function () {
373
	var name, postParams, paramStringPairs = [];
374
	
375
	postParams = this.settings.post_params; 
376

  
377
	if (typeof(postParams) === "object") {
378
		for (name in postParams) {
379
			if (postParams.hasOwnProperty(name)) {
380
				paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
381
			}
382
		}
383
	}
384

  
385
	return paramStringPairs.join("&amp;");
386
};
387

  
388
// Public: Used to remove a SWFUpload instance from the page. This method strives to remove
389
// all references to the SWF, and other objects so memory is properly freed.
390
// Returns true if everything was destroyed. Returns a false if a failure occurs leaving SWFUpload in an inconsistant state.
391
// Credits: Major improvements provided by steffen
392
SWFUpload.prototype.destroy = function () {
393
	var movieElement;
394
	
395
	try {
396
		// Make sure Flash is done before we try to remove it
397
		this.cancelUpload(null, false);
398
		
399
		movieElement = this.cleanUp();
400

  
401
		// Remove the SWFUpload DOM nodes
402
		if (movieElement) {
403
			// Remove the Movie Element from the page
404
			try {
405
				movieElement.parentNode.removeChild(movieElement);
406
			} catch (ex) {}
407
		}
408

  
409
		// Remove IE form fix reference
410
		window[this.movieName] = null;
411

  
412
		// Destroy other references
413
		SWFUpload.instances[this.movieName] = null;
414
		delete SWFUpload.instances[this.movieName];
415

  
416
		this.movieElement = null;
417
		this.settings = null;
418
		this.customSettings = null;
419
		this.eventQueue = null;
420
		this.movieName = null;
421
		
422
		
423
		return true;
424
	} catch (ex2) {
425
		return false;
426
	}
427
};
428

  
429

  
430
// Public: displayDebugInfo prints out settings and configuration
431
// information about this SWFUpload instance.
432
// This function (and any references to it) can be deleted when placing
433
// SWFUpload in production.
434
SWFUpload.prototype.displayDebugInfo = function () {
435
	this.debug(
436
		[
437
			"---SWFUpload Instance Info---\n",
438
			"Version: ", SWFUpload.version, "\n",
439
			"Movie Name: ", this.movieName, "\n",
440
			"Settings:\n",
441
			"\t", "upload_url:               ", this.settings.upload_url, "\n",
442
			"\t", "flash_url:                ", this.settings.flash_url, "\n",
443
			"\t", "flash9_url:                ", this.settings.flash9_url, "\n",
444
			"\t", "use_query_string:         ", this.settings.use_query_string.toString(), "\n",
445
			"\t", "requeue_on_error:         ", this.settings.requeue_on_error.toString(), "\n",
446
			"\t", "http_success:             ", this.settings.http_success.join(", "), "\n",
447
			"\t", "assume_success_timeout:   ", this.settings.assume_success_timeout, "\n",
448
			"\t", "file_post_name:           ", this.settings.file_post_name, "\n",
449
			"\t", "post_params:              ", this.settings.post_params.toString(), "\n",
450
			"\t", "file_types:               ", this.settings.file_types, "\n",
451
			"\t", "file_types_description:   ", this.settings.file_types_description, "\n",
452
			"\t", "file_size_limit:          ", this.settings.file_size_limit, "\n",
453
			"\t", "file_upload_limit:        ", this.settings.file_upload_limit, "\n",
454
			"\t", "file_queue_limit:         ", this.settings.file_queue_limit, "\n",
455
			"\t", "debug:                    ", this.settings.debug.toString(), "\n",
456

  
457
			"\t", "prevent_swf_caching:      ", this.settings.prevent_swf_caching.toString(), "\n",
458

  
459
			"\t", "button_placeholder_id:    ", this.settings.button_placeholder_id.toString(), "\n",
460
			"\t", "button_placeholder:       ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
461
			"\t", "button_image_url:         ", this.settings.button_image_url.toString(), "\n",
462
			"\t", "button_width:             ", this.settings.button_width.toString(), "\n",
463
			"\t", "button_height:            ", this.settings.button_height.toString(), "\n",
464
			"\t", "button_text:              ", this.settings.button_text.toString(), "\n",
465
			"\t", "button_text_style:        ", this.settings.button_text_style.toString(), "\n",
466
			"\t", "button_text_top_padding:  ", this.settings.button_text_top_padding.toString(), "\n",
467
			"\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
468
			"\t", "button_action:            ", this.settings.button_action.toString(), "\n",
469
			"\t", "button_cursor:            ", this.settings.button_cursor.toString(), "\n",
470
			"\t", "button_disabled:          ", this.settings.button_disabled.toString(), "\n",
471

  
472
			"\t", "custom_settings:          ", this.settings.custom_settings.toString(), "\n",
473
			"Event Handlers:\n",
474
			"\t", "swfupload_preload_handler assigned:  ", (typeof this.settings.swfupload_preload_handler === "function").toString(), "\n",
475
			"\t", "swfupload_load_failed_handler assigned:  ", (typeof this.settings.swfupload_load_failed_handler === "function").toString(), "\n",
476
			"\t", "swfupload_loaded_handler assigned:  ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
477
			"\t", "mouse_click_handler assigned:       ", (typeof this.settings.mouse_click_handler === "function").toString(), "\n",
478
			"\t", "mouse_over_handler assigned:        ", (typeof this.settings.mouse_over_handler === "function").toString(), "\n",
479
			"\t", "mouse_out_handler assigned:         ", (typeof this.settings.mouse_out_handler === "function").toString(), "\n",
480
			"\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
481
			"\t", "file_queued_handler assigned:       ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
482
			"\t", "file_queue_error_handler assigned:  ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
483
			"\t", "upload_resize_start_handler assigned:      ", (typeof this.settings.upload_resize_start_handler === "function").toString(), "\n",
484
			"\t", "upload_start_handler assigned:      ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
485
			"\t", "upload_progress_handler assigned:   ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
486
			"\t", "upload_error_handler assigned:      ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
487
			"\t", "upload_success_handler assigned:    ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
488
			"\t", "upload_complete_handler assigned:   ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
489
			"\t", "debug_handler assigned:             ", (typeof this.settings.debug_handler === "function").toString(), "\n",
490

  
491
			"Support:\n",
492
			"\t", "Load:                     ", (this.support.loading ? "Yes" : "No"), "\n",
493
			"\t", "Image Resize:             ", (this.support.imageResize ? "Yes" : "No"), "\n"
494

  
495
		].join("")
496
	);
497
};
498

  
499
/* Note: addSetting and getSetting are no longer used by SWFUpload but are included
500
	the maintain v2 API compatibility
501
*/
502
// Public: (Deprecated) addSetting adds a setting value. If the value given is undefined or null then the default_value is used.
503
SWFUpload.prototype.addSetting = function (name, value, default_value) {
504
    if (value == undefined) {
505
        return (this.settings[name] = default_value);
506
    } else {
507
        return (this.settings[name] = value);
508
	}
509
};
510

  
511
// Public: (Deprecated) getSetting gets a setting. Returns an empty string if the setting was not found.
512
SWFUpload.prototype.getSetting = function (name) {
513
    if (this.settings[name] != undefined) {
514
        return this.settings[name];
515
	}
516

  
517
    return "";
518
};
519

  
520

  
521

  
522
// Private: callFlash handles function calls made to the Flash element.
523
// Calls are made with a setTimeout for some functions to work around
524
// bugs in the ExternalInterface library.
525
SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
526
	var movieElement, returnValue, returnString;
527
	
528
	argumentArray = argumentArray || [];
529
	movieElement = this.getMovieElement();
530

  
531
	// Flash's method if calling ExternalInterface methods (code adapted from MooTools).
532
	try {
533
		if (movieElement != undefined) {
534
			returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
535
			returnValue = eval(returnString);
536
		} else {
537
			this.debug("Can't call flash because the movie wasn't found.");
538
		}
539
	} catch (ex) {
540
		this.debug("Exception calling flash function '" + functionName + "': " + ex.message);
541
	}
542
	
543
	// Unescape file post param values
544
	if (returnValue != undefined && typeof returnValue.post === "object") {
545
		returnValue = this.unescapeFilePostParams(returnValue);
546
	}
547

  
548
	return returnValue;
549
};
550

  
551
/* *****************************
552
	-- Flash control methods --
553
	Your UI should use these
554
	to operate SWFUpload
555
   ***************************** */
556

  
557
// WARNING: this function does not work in Flash Player 10
558
// Public: selectFile causes a File Selection Dialog window to appear.  This
559
// dialog only allows 1 file to be selected.
560
SWFUpload.prototype.selectFile = function () {
561
	this.callFlash("SelectFile");
562
};
563

  
564
// WARNING: this function does not work in Flash Player 10
565
// Public: selectFiles causes a File Selection Dialog window to appear/ This
566
// dialog allows the user to select any number of files
567
// Flash Bug Warning: Flash limits the number of selectable files based on the combined length of the file names.
568
// If the selection name length is too long the dialog will fail in an unpredictable manner.  There is no work-around
569
// for this bug.
570
SWFUpload.prototype.selectFiles = function () {
571
	this.callFlash("SelectFiles");
572
};
573

  
574

  
575
// Public: startUpload starts uploading the first file in the queue unless
576
// the optional parameter 'fileID' specifies the ID 
577
SWFUpload.prototype.startUpload = function (fileID) {
578
	this.callFlash("StartUpload", [fileID]);
579
};
580

  
581
// Public: startUpload starts uploading the first file in the queue unless
582
// the optional parameter 'fileID' specifies the ID 
583
SWFUpload.prototype.startResizedUpload = function (fileID, width, height, encoding, quality, allowEnlarging) {
584
	this.callFlash("StartUpload", [fileID, { "width": width, "height" : height, "encoding" : encoding, "quality" : quality, "allowEnlarging" : allowEnlarging }]);
585
};
586

  
587
// Public: cancelUpload cancels any queued file.  The fileID parameter may be the file ID or index.
588
// If you do not specify a fileID the current uploading file or first file in the queue is cancelled.
589
// If you do not want the uploadError event to trigger you can specify false for the triggerErrorEvent parameter.
590
SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
591
	if (triggerErrorEvent !== false) {
592
		triggerErrorEvent = true;
593
	}
594
	this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
595
};
596

  
597
// Public: stopUpload stops the current upload and requeues the file at the beginning of the queue.
598
// If nothing is currently uploading then nothing happens.
599
SWFUpload.prototype.stopUpload = function () {
600
	this.callFlash("StopUpload");
601
};
602

  
603

  
604
// Public: requeueUpload requeues any file. If the file is requeued or already queued true is returned.
605
// If the file is not found or is currently uploading false is returned.  Requeuing a file bypasses the
606
// file size, queue size, upload limit and other queue checks.  Certain files can't be requeued (e.g, invalid or zero bytes files).
607
SWFUpload.prototype.requeueUpload = function (indexOrFileID) {
608
	return this.callFlash("RequeueUpload", [indexOrFileID]);
609
};
610

  
611

  
612
/* ************************
613
 * Settings methods
614
 *   These methods change the SWFUpload settings.
615
 *   SWFUpload settings should not be changed directly on the settings object
616
 *   since many of the settings need to be passed to Flash in order to take
617
 *   effect.
618
 * *********************** */
619

  
620
// Public: getStats gets the file statistics object.
621
SWFUpload.prototype.getStats = function () {
622
	return this.callFlash("GetStats");
623
};
624

  
625
// Public: setStats changes the SWFUpload statistics.  You shouldn't need to 
626
// change the statistics but you can.  Changing the statistics does not
627
// affect SWFUpload accept for the successful_uploads count which is used
628
// by the upload_limit setting to determine how many files the user may upload.
629
SWFUpload.prototype.setStats = function (statsObject) {
630
	this.callFlash("SetStats", [statsObject]);
631
};
632

  
633
// Public: getFile retrieves a File object by ID or Index.  If the file is
634
// not found then 'null' is returned.
635
SWFUpload.prototype.getFile = function (fileID) {
636
	if (typeof(fileID) === "number") {
637
		return this.callFlash("GetFileByIndex", [fileID]);
638
	} else {
639
		return this.callFlash("GetFile", [fileID]);
640
	}
641
};
642

  
643
// Public: getFileFromQueue retrieves a File object by ID or Index.  If the file is
644
// not found then 'null' is returned.
645
SWFUpload.prototype.getQueueFile = function (fileID) {
646
	if (typeof(fileID) === "number") {
647
		return this.callFlash("GetFileByQueueIndex", [fileID]);
648
	} else {
649
		return this.callFlash("GetFile", [fileID]);
650
	}
651
};
652

  
653

  
654
// Public: addFileParam sets a name/value pair that will be posted with the
655
// file specified by the Files ID.  If the name already exists then the
656
// exiting value will be overwritten.
657
SWFUpload.prototype.addFileParam = function (fileID, name, value) {
658
	return this.callFlash("AddFileParam", [fileID, name, value]);
659
};
660

  
661
// Public: removeFileParam removes a previously set (by addFileParam) name/value
662
// pair from the specified file.
663
SWFUpload.prototype.removeFileParam = function (fileID, name) {
664
	this.callFlash("RemoveFileParam", [fileID, name]);
665
};
666

  
667
// Public: setUploadUrl changes the upload_url setting.
668
SWFUpload.prototype.setUploadURL = function (url) {
669
	this.settings.upload_url = url.toString();
670
	this.callFlash("SetUploadURL", [url]);
671
};
672

  
673
// Public: setPostParams changes the post_params setting
674
SWFUpload.prototype.setPostParams = function (paramsObject) {
675
	this.settings.post_params = paramsObject;
676
	this.callFlash("SetPostParams", [paramsObject]);
677
};
678

  
679
// Public: addPostParam adds post name/value pair.  Each name can have only one value.
680
SWFUpload.prototype.addPostParam = function (name, value) {
681
	this.settings.post_params[name] = value;
682
	this.callFlash("SetPostParams", [this.settings.post_params]);
683
};
684

  
685
// Public: removePostParam deletes post name/value pair.
686
SWFUpload.prototype.removePostParam = function (name) {
687
	delete this.settings.post_params[name];
688
	this.callFlash("SetPostParams", [this.settings.post_params]);
689
};
690

  
691
// Public: setFileTypes changes the file_types setting and the file_types_description setting
692
SWFUpload.prototype.setFileTypes = function (types, description) {
693
	this.settings.file_types = types;
694
	this.settings.file_types_description = description;
695
	this.callFlash("SetFileTypes", [types, description]);
696
};
697

  
698
// Public: setFileSizeLimit changes the file_size_limit setting
699
SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
700
	this.settings.file_size_limit = fileSizeLimit;
701
	this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff