ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

handlers.js
Go to the documentation of this file.
1 /* Demo Note: This demo uses a FileProgress class that handles the UI for displaying the file name and percent complete.
2 The FileProgress class is not part of SWFUpload.
3 */
4
5
6 /* **********************
7 Event Handlers
8 These are my custom event handlers to make my
9 web application behave the way I went when SWFUpload
10 completes different tasks. These aren't part of the SWFUpload
11 package. They are part of my application. Without these none
12 of the actions SWFUpload makes will show up in my application.
13 ********************** */
14 function fileQueued(file) {
15 try {
16 var progress = new FileProgress(file, this.customSettings.progressTarget);
17 progress.setStatus( ultimix.get_string( "pending" ) );
18 progress.toggleCancel(true, this);
19
20 } catch (ex) {
21 this.debug(ex);
22 }
23
24 }
25
26 function fileQueueError(file, errorCode, message) {
27 try {
28 if (file.name == null) {
29 file.name = ultimix.get_string( "file_error" );
30 }
31
32 var progress = new FileProgress(file, this.customSettings.progressTarget);
33 progress.setError();
34 progress.toggleCancel(false);
35
36 switch( errorCode )
37 {
38 case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
39 console.log( file );
40 progress.setStatus( ultimix.get_string( "file_is_too_big" ) );
41 this.debug("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
42 break;
43 case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
44 progress.setStatus( ultimix.get_string( "cannot_upload_zero_bytes" ) );
45 this.debug("Error Code: Zero byte file, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
46 break;
47 case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
48 progress.setStatus( ultimix.get_string( "invalid_file_type" ) );
49 this.debug("Error Code: Invalid File Type, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
50 break;
51 case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
52 progress.setStatus( ultimix.get_string( "queue_limit_exceded" ) );
53 this.debug("Error Code: Invalid File Type, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
54 break;
55 default:
56 if (file !== null) {
57 progress.setStatus( ultimix.get_string( "unhandled_error" ) );
58 }
59 this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
60 break;
61 }
62 } catch (ex) {
63 this.debug(ex);
64 }
65 }
66
67 function fileDialogComplete(numFilesSelected, numFilesQueued) {
68 try {
69 if (numFilesSelected > 0) {
70 document.getElementById(this.customSettings.cancelButtonId).disabled = false;
71 }
72
73 /* I want auto start the upload and I can do that here */
74 this.startUpload();
75 } catch (ex) {
76 this.debug(ex);
77 }
78 }
79
80 function uploadStart(file) {
81 try {
82 /* I don't want to do any file validation or anything, I'll just update the UI and
83 return true to indicate that the upload should start.
84 It's important to update the UI here because in Linux no uploadProgress events are called. The best
85 we can do is say we are uploading.
86 */
87 var progress = new FileProgress(file, this.customSettings.progressTarget);
88 progress.setStatus( ultimix.get_string( 'uploading' ) );
89 progress.toggleCancel(true, this);
90 }
91 catch (ex) {}
92
93 return true;
94 }
95
96 function uploadProgress(file, bytesLoaded, bytesTotal) {
97 try {
98 var percent = Math.ceil((bytesLoaded / bytesTotal) * 100);
99
100 var progress = new FileProgress(file, this.customSettings.progressTarget);
101 progress.setProgress(percent);
102 progress.setStatus( ultimix.get_string( 'uploading' ) );
103 } catch (ex) {
104 this.debug(ex);
105 }
106 }
107
108 function uploadSuccess(file, serverData) {
109 try {
110 var progress = new FileProgress(file, this.customSettings.progressTarget);
111 progress.setComplete();
112 progress.setStatus( ultimix.get_string( 'complete' ) );
113 progress.toggleCancel(false);
114
115 } catch (ex) {
116 this.debug(ex);
117 }
118 }
119
120 function uploadError(file, errorCode, message) {
121 try {
122 var progress = new FileProgress(file, this.customSettings.progressTarget);
123 progress.setError();
124 progress.toggleCancel(false);
125
126 switch (errorCode)
127 {
128 case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:
129 progress.setStatus( ultimix.get_string( "http_error" ) );
130 this.debug("Error Code: HTTP Error, File name: " + file.name + ", Message: " + message);
131 break;
132 case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:
133 progress.setStatus( ultimix.get_string( "upload_failed" ) );
134 this.debug("Error Code: Upload Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
135 break;
136 case SWFUpload.UPLOAD_ERROR.IO_ERROR:
137 progress.setStatus( ultimix.get_string( "server_io_error" ) ) ;
138 this.debug("Error Code: IO Error, File name: " + file.name + ", Message: " + message);
139 break;
140 case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:
141 progress.setStatus( ultimix.get_string( "security_error" ) );
142 this.debug("Error Code: Security Error, File name: " + file.name + ", Message: " + message);
143 break;
144 case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
145 progress.setStatus( ultimix.get_string( "upload_limit" ) );
146 this.debug("Error Code: Upload Limit Exceeded, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
147 break;
148 case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:
149 progress.setStatus( ultimix.get_string( "failed_validation" ) );
150 this.debug("Error Code: File Validation Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
151 break;
152 case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
153 /* If there aren't any files left (they were all cancelled) disable the cancel button */
154 if (this.getStats().files_queued === 0) {
155 document.getElementById(this.customSettings.cancelButtonId).disabled = true;
156 }
157 progress.setStatus( ultimix.get_string( "cancelled" ) );
158 progress.setCancelled();
159 break;
160 case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
161 progress.setStatus( ultimix.get_string( "stopped" ) );
162 break;
163 default:
164 progress.setStatus( ultimix.get_string( "unhandled_error" ) + ": " + errorCode);
165 this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
166 break;
167 }
168 } catch (ex) {
169 this.debug(ex);
170 }
171 }
172
173 function uploadComplete(file) {
174 if (this.getStats().files_queued === 0) {
175 document.getElementById(this.customSettings.cancelButtonId).disabled = true;
176 }
177 }
178
179 /* This event comes from the Queue Plugin */
180 function queueComplete(numFilesUploaded) {
181 var status = document.getElementById("divStatus");
182 status.innerHTML = numFilesUploaded + " file" + (numFilesUploaded === 1 ? "" : "s") + " uploaded.";
183 }