|
| 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 preLoad() { |
| 15 | + if (!this.support.loading) { |
| 16 | + alert(lang.flashVersionError); |
| 17 | + return false; |
| 18 | + } |
| 19 | + return true; |
| 20 | +} |
| 21 | +function loadFailed() { |
| 22 | + alert(lang.flashLoadingError); |
| 23 | +} |
| 24 | + |
| 25 | +function fileQueued(file) { |
| 26 | + try { |
| 27 | + var progress = new FileProgress(file, this.customSettings.progressTarget); |
| 28 | + progress.setStatus(lang.fileUploadReady); |
| 29 | + progress.toggleCancel(true, this,lang.delUploadQueue); |
| 30 | + } catch (ex) { |
| 31 | + this.debug(ex); |
| 32 | + } |
| 33 | + |
| 34 | +} |
| 35 | + |
| 36 | +function fileQueueError(file, errorCode, message) { |
| 37 | + try { |
| 38 | + if (errorCode === SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) { |
| 39 | + alert(lang.limitPrompt1+ message + lang.limitPrompt2); |
| 40 | + return; |
| 41 | + } |
| 42 | + |
| 43 | + var progress = new FileProgress(file, this.customSettings.progressTarget); |
| 44 | + progress.setError(); |
| 45 | + progress.toggleCancel(true, this,lang.delFailFile); |
| 46 | + |
| 47 | + switch (errorCode) { |
| 48 | + case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT: |
| 49 | + progress.setStatus(lang.fileSizeLimit); |
| 50 | + this.debug("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); |
| 51 | + break; |
| 52 | + case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE: |
| 53 | + progress.setStatus(lang.emptyFile); |
| 54 | + this.debug("Error Code: Zero byte file, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); |
| 55 | + break; |
| 56 | + case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE: |
| 57 | + progress.setStatus(lang.fileTypeError); |
| 58 | + this.debug("Error Code: Invalid File Type, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); |
| 59 | + break; |
| 60 | + default: |
| 61 | + if (file !== null) { |
| 62 | + progress.setStatus(lang.unknownError); |
| 63 | + } |
| 64 | + this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message); |
| 65 | + break; |
| 66 | + } |
| 67 | + } catch (ex) { |
| 68 | + this.debug(ex); |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | +function uploadStart(file) { |
| 75 | + try { |
| 76 | + /* I don't want to do any file validation or anything, I'll just update the UI and |
| 77 | + return true to indicate that the upload should start. |
| 78 | + It's important to update the UI here because in Linux no uploadProgress events are called. The best |
| 79 | + we can do is say we are uploading. |
| 80 | + */ |
| 81 | + var progress = new FileProgress(file, this.customSettings.progressTarget); |
| 82 | + progress.setStatus(lang.fileUploading); |
| 83 | + progress.toggleCancel(true, this,lang.cancelUpload); |
| 84 | + }catch (ex) {} |
| 85 | + |
| 86 | + return true; |
| 87 | +} |
| 88 | + |
| 89 | +function uploadProgress(file, bytesLoaded, bytesTotal) { |
| 90 | + try { |
| 91 | + var percent = Math.ceil((bytesLoaded / bytesTotal) * 100); |
| 92 | + |
| 93 | + var progress = new FileProgress(file, this.customSettings.progressTarget); |
| 94 | + progress.setProgress(percent); |
| 95 | + progress.setStatus(lang.fileUploading); |
| 96 | + } catch (ex) { |
| 97 | + this.debug(ex); |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | + |
| 102 | +function uploadError(file, errorCode, message) { |
| 103 | + try { |
| 104 | + var progress = new FileProgress(file, this.customSettings.progressTarget); |
| 105 | + progress.setError(); |
| 106 | + //progress.toggleCancel(false); |
| 107 | + |
| 108 | + switch (errorCode) { |
| 109 | + case SWFUpload.UPLOAD_ERROR.HTTP_ERROR: |
| 110 | + progress.setStatus(lang.netError + message); |
| 111 | + this.debug("Error Code: HTTP Error, File name: " + file.name + ", Message: " + message); |
| 112 | + break; |
| 113 | + case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED: |
| 114 | + progress.setStatus(lang.failUpload); |
| 115 | + this.debug("Error Code: Upload Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); |
| 116 | + break; |
| 117 | + case SWFUpload.UPLOAD_ERROR.IO_ERROR: |
| 118 | + progress.setStatus(lang.serverIOError); |
| 119 | + this.debug("Error Code: IO Error, File name: " + file.name + ", Message: " + message); |
| 120 | + break; |
| 121 | + case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR: |
| 122 | + progress.setStatus(lang.noAuthority); |
| 123 | + this.debug("Error Code: Security Error, File name: " + file.name + ", Message: " + message); |
| 124 | + break; |
| 125 | + case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED: |
| 126 | + progress.setStatus(lang.fileNumLimit); |
| 127 | + this.debug("Error Code: Upload Limit Exceeded, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); |
| 128 | + break; |
| 129 | + case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED: |
| 130 | + progress.setStatus(lang.failCheck); |
| 131 | + this.debug("Error Code: File Validation Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); |
| 132 | + break; |
| 133 | + case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED: |
| 134 | + // If there aren't any files left (they were all cancelled) disable the cancel button |
| 135 | +// if (this.getStats().files_queued === 0) { |
| 136 | +// document.getElementById(this.customSettings.cancelButtonId).disabled = true; |
| 137 | +// } |
| 138 | + progress.setStatus(lang.fileCanceling); |
| 139 | + progress.setCancelled(); |
| 140 | + break; |
| 141 | + case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED: |
| 142 | + progress.setStatus(lang.stopUploading); |
| 143 | + break; |
| 144 | + default: |
| 145 | + progress.setStatus(lang.unknownError + errorCode); |
| 146 | + this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message); |
| 147 | + break; |
| 148 | + } |
| 149 | + } catch (ex) { |
| 150 | + this.debug(ex); |
| 151 | + } |
| 152 | +} |
| 153 | + |
| 154 | +function uploadComplete(file) { |
| 155 | + //alert(file); |
| 156 | + // if (this.getStats().files_queued === 0) { |
| 157 | + // document.getElementById(this.customSettings.cancelButtonId).disabled = true; |
| 158 | + // } |
| 159 | +} |
| 160 | + |
| 161 | +// This event comes from the Queue Plugin |
| 162 | +function queueComplete(numFilesUploaded) { |
| 163 | + var status = document.getElementById("divStatus"); |
| 164 | + var num = status.innerHTML.match(/\d+/g); |
| 165 | + status.innerHTML = ((num && num[0] ?parseInt(num[0]):0) + numFilesUploaded) +lang.statusPrompt; |
| 166 | +} |
0 commit comments