source: trunk/web/addons/job_monarch/lib/extjs-30/examples/image-organizer/SWFUpload/plugins/swfupload.queue.js @ 625

Last change on this file since 625 was 625, checked in by ramonb, 15 years ago

lib/extjs-30:

  • new ExtJS 3.0
File size: 3.5 KB
Line 
1/*!
2 * Ext JS Library 3.0.0
3 * Copyright(c) 2006-2009 Ext JS, LLC
4 * licensing@extjs.com
5 * http://www.extjs.com/license
6 */
7/*
8        Queue Plug-in
9       
10        Features:
11                *Adds a cancelQueue() method for cancelling the entire queue.
12                *All queued files are uploaded when startUpload() is called.
13                *If false is returned from uploadComplete then the queue upload is stopped.
14                 If false is not returned (strict comparison) then the queue upload is continued.
15                *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
16                 Set the event handler with the queue_complete_handler setting.
17               
18        */
19
20var SWFUpload;
21if (typeof(SWFUpload) === "function") {
22        SWFUpload.queue = {};
23       
24        SWFUpload.prototype.initSettings = (function (oldInitSettings) {
25                return function () {
26                        if (typeof(oldInitSettings) === "function") {
27                                oldInitSettings.call(this);
28                        }
29                       
30                        this.queueSettings = {};
31                       
32                        this.queueSettings.queue_cancelled_flag = false;
33                        this.queueSettings.queue_upload_count = 0;
34                       
35                        this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
36                        this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
37                        this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
38                        this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
39                       
40                        this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
41                };
42        })(SWFUpload.prototype.initSettings);
43
44        SWFUpload.prototype.startUpload = function (fileID) {
45                this.queueSettings.queue_cancelled_flag = false;
46                this.callFlash("StartUpload", [fileID]);
47        };
48
49        SWFUpload.prototype.cancelQueue = function () {
50                this.queueSettings.queue_cancelled_flag = true;
51                this.stopUpload();
52               
53                var stats = this.getStats();
54                while (stats.files_queued > 0) {
55                        this.cancelUpload();
56                        stats = this.getStats();
57                }
58        };
59       
60        SWFUpload.queue.uploadStartHandler = function (file) {
61                var returnValue;
62                if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
63                        returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
64                }
65               
66                // To prevent upload a real "FALSE" value must be returned, otherwise default to a real "TRUE" value.
67                returnValue = (returnValue === false) ? false : true;
68               
69                this.queueSettings.queue_cancelled_flag = !returnValue;
70
71                return returnValue;
72        };
73       
74        SWFUpload.queue.uploadCompleteHandler = function (file) {
75                var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
76                var continueUpload;
77               
78                if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
79                        this.queueSettings.queue_upload_count++;
80                }
81
82                if (typeof(user_upload_complete_handler) === "function") {
83                        continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
84                } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
85                        // If the file was stopped and re-queued don't restart the upload
86                        continueUpload = false;
87                } else {
88                        continueUpload = true;
89                }
90               
91                if (continueUpload) {
92                        var stats = this.getStats();
93                        if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
94                                this.startUpload();
95                        } else if (this.queueSettings.queue_cancelled_flag === false) {
96                                this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
97                                this.queueSettings.queue_upload_count = 0;
98                        } else {
99                                this.queueSettings.queue_cancelled_flag = false;
100                                this.queueSettings.queue_upload_count = 0;
101                        }
102                }
103        };
104}
Note: See TracBrowser for help on using the repository browser.