220ad546843331fc58c56ff281a8a6acf7b7540f.svn-base 5.9 KB

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