handlers.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /* This is an example of how to cancel all the files queued up. It's made somewhat generic. Just pass your SWFUpload
  2. object in to this method and it loops through cancelling the uploads. */
  3. function cancelQueue(instance) {
  4. document.getElementById(instance.customSettings.cancelButtonId).disabled = true;
  5. instance.stopUpload();
  6. var stats;
  7. do {
  8. stats = instance.getStats();
  9. instance.cancelUpload();
  10. } while (stats.files_queued !== 0);
  11. }
  12. /* **********************
  13. Event Handlers
  14. These are my custom event handlers to make my
  15. web application behave the way I went when SWFUpload
  16. completes different tasks. These aren't part of the SWFUpload
  17. package. They are part of my application. Without these none
  18. of the actions SWFUpload makes will show up in my application.
  19. ********************** */
  20. function fileDialogStart() {
  21. /* I don't need to do anything here */
  22. }
  23. function fileQueued(file) {
  24. try {
  25. // You might include code here that prevents the form from being submitted while the upload is in
  26. // progress. Then you'll want to put code in the Queue Complete handler to "unblock" the form
  27. var progress = new FileProgress(file, this.customSettings.progressTarget);
  28. //progress.setStatus("Pending...");
  29. progress.setStatus("等待...");
  30. progress.toggleCancel(true, this);
  31. } catch (ex) {
  32. this.debug(ex);
  33. }
  34. }
  35. function fileQueueError(file, errorCode, message) {
  36. try {
  37. if (errorCode === SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) {
  38. //alert("You have attempted to queue too many files.\n" + (message === 0 ? "You have reached the upload limit." : "You may select " + (message > 1 ? "up to " + message + " files." : "one file.")));
  39. alert("添加的文件过多.\n" + (message === 0 ? "You have reached the upload limit." : "你可以最多 " + (message > 1 ? "选择 " + message + " 个文件." : "1个文件.")));
  40. return;
  41. }
  42. var progress = new FileProgress(file, this.customSettings.progressTarget);
  43. progress.setError();
  44. progress.toggleCancel(false);
  45. switch (errorCode) {
  46. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  47. //progress.setStatus("File is too big.");
  48. progress.setStatus("文件太大,请上传大小为"+file_size_limit/1024+"M以内的文件.");
  49. this.debug("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
  50. break;
  51. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  52. //progress.setStatus("Cannot upload Zero Byte files.");
  53. progress.setStatus("不能上传大小为0B的文件.");
  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("Invalid File Type.");
  58. progress.setStatus("文件类型无效.");
  59. this.debug("Error Code: Invalid File Type, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
  60. break;
  61. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  62. //alert("You have selected too many files. " + (message > 1 ? "You may only add " + message + " more files" : "You cannot add any more files."));
  63. alert("上传文件选的过多。");
  64. break;
  65. default:
  66. if (file !== null) {
  67. progress.setStatus("未知错误.");
  68. }
  69. this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
  70. break;
  71. }
  72. } catch (ex) {
  73. this.debug(ex);
  74. }
  75. }
  76. function fileDialogComplete(numFilesSelected, numFilesQueued) {
  77. try {
  78. if (this.getStats().files_queued > 0) {
  79. document.getElementById(this.customSettings.cancelButtonId).disabled = false;
  80. }
  81. /* I want auto start and I can do that here */
  82. this.startUpload();
  83. } catch (ex) {
  84. this.debug(ex);
  85. }
  86. }
  87. function uploadStart(file) {
  88. try {
  89. /* I don't want to do any file validation or anything, I'll just update the UI and return true to indicate that the upload should start */
  90. var progress = new FileProgress(file, this.customSettings.progressTarget);
  91. //progress.setStatus("Uploading...");
  92. progress.setStatus("上传中...");
  93. progress.toggleCancel(true, this);
  94. this.setPostParams({
  95. 'fileName':encodeURIComponent(file.name),
  96. 'fileType':encodeURIComponent(file.type),
  97. 'filepath':file_path,
  98. 'fileYWBM':file_YWBM
  99. });
  100. //var post_params = this.settings.post_params;
  101. // Ext.apply(post_params,{
  102. // 'fileName':encodeURI(file.name)
  103. // });
  104. // this.setPostParams(post_params);
  105. }
  106. catch (ex) {
  107. }
  108. return true;
  109. }
  110. function uploadProgress(file, bytesLoaded, bytesTotal) {
  111. try {
  112. var percent = Math.ceil((bytesLoaded / bytesTotal) * 100);
  113. var progress = new FileProgress(file, this.customSettings.progressTarget);
  114. progress.setProgress(percent);
  115. //progress.setStatus("Uploading...");
  116. progress.setStatus("上传中...");
  117. } catch (ex) {
  118. this.debug(ex);
  119. }
  120. }
  121. function uploadSuccess(file, serverData) {
  122. try {
  123. var progress = new FileProgress(file, this.customSettings.progressTarget);
  124. alert(file.name);
  125. progress.setComplete();
  126. progress.setStatus("Complete.");
  127. progress.toggleCancel(false);
  128. } catch (ex) {
  129. this.debug(ex);
  130. }
  131. }
  132. function uploadComplete(file) {
  133. try {
  134. /* I want the next upload to continue automatically so I'll call startUpload here */
  135. if (this.getStats().files_queued === 0) {
  136. document.getElementById(this.customSettings.cancelButtonId).disabled = true;
  137. } else {
  138. this.startUpload();
  139. }
  140. } catch (ex) {
  141. this.debug(ex);
  142. }
  143. }
  144. function uploadError(file, errorCode, message) {
  145. try {
  146. var progress = new FileProgress(file, this.customSettings.progressTarget);
  147. progress.setError();
  148. progress.toggleCancel(false);
  149. switch (errorCode) {
  150. case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:
  151. progress.setStatus("Upload Error: " + message);
  152. this.debug("Error Code: HTTP Error, File name: " + file.name + ", Message: " + message);
  153. break;
  154. case SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL:
  155. //progress.setStatus("Configuration Error");
  156. progress.setStatus("配置错误.");
  157. this.debug("Error Code: No backend file, File name: " + file.name + ", Message: " + message);
  158. break;
  159. case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:
  160. //progress.setStatus("Upload Failed.");
  161. progress.setStatus("上传失败.");
  162. this.debug("Error Code: Upload Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
  163. break;
  164. case SWFUpload.UPLOAD_ERROR.IO_ERROR:
  165. //progress.setStatus("Server (IO) Error");
  166. progress.setStatus("服务器 (IO) 错误.");
  167. this.debug("Error Code: IO Error, File name: " + file.name + ", Message: " + message);
  168. break;
  169. case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:
  170. //progress.setStatus("Security Error");
  171. progress.setStatus("安全错误.");
  172. this.debug("Error Code: Security Error, File name: " + file.name + ", Message: " + message);
  173. break;
  174. case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
  175. //progress.setStatus("Upload limit exceeded.");
  176. progress.setStatus("上传的文件过多.");
  177. this.debug("Error Code: Upload Limit Exceeded, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
  178. break;
  179. case SWFUpload.UPLOAD_ERROR.SPECIFIED_FILE_ID_NOT_FOUND:
  180. //progress.setStatus("File not found.");
  181. progress.setStatus("找不到文件.");
  182. this.debug("Error Code: The file was not found, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
  183. break;
  184. case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:
  185. progress.setStatus("Failed Validation. Upload skipped.");
  186. this.debug("Error Code: File Validation Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
  187. break;
  188. case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
  189. if (this.getStats().files_queued === 0) {
  190. document.getElementById(this.customSettings.cancelButtonId).disabled = true;
  191. }
  192. //progress.setStatus("Cancelled");
  193. progress.setStatus("取消上传");
  194. progress.setCancelled();
  195. break;
  196. case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
  197. //progress.setStatus("Stopped");
  198. progress.setStatus("已停止");
  199. break;
  200. default:
  201. progress.setStatus("Unhandled Error: " + error_code);
  202. this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
  203. break;
  204. }
  205. } catch (ex) {
  206. this.debug(ex);
  207. }
  208. }