Validform.swfupload.handler.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*set handlers here*/
  2. var swfuploadhandler={
  3. init:function(settings,index){
  4. settings=$.extend(true,{},swfuploadefaults,settings);
  5. swfuploadhandler["SWFUPLOAD_"+settings.custom_settings.form.attr("id")+"_"+index]=new SWFUpload(settings);
  6. },
  7. swfUploadLoaded:function(){
  8. },
  9. uploadStart:function(){
  10. //this.customSettings.form.find(".fsUploadProgress").show();
  11. },
  12. uploadDone:function(){
  13. //this.customSettings.form.find(".fsUploadProgress").hide();
  14. this.customSettings.showmsg("已成功上传文件!",2);
  15. //this.customSettings.form.submit();
  16. },
  17. fileDialogStart:function(){
  18. this.customSettings.form.find("input[plugin='swfupload']").val("");
  19. this.cancelUpload();
  20. },
  21. fileQueueError:function(file, errorCode, message){
  22. try {
  23. // Handle this error separately because we don't want to create a FileProgress element for it.
  24. switch (errorCode) {
  25. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  26. this.customSettings.showmsg("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.")),3);
  27. return;
  28. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  29. this.customSettings.showmsg("The file you selected is too big.",3);
  30. this.debug("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
  31. return;
  32. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  33. this.customSettings.showmsg("The file you selected is empty. Please select another file.",3);
  34. this.debug("Error Code: Zero byte file, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
  35. return;
  36. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  37. this.customSettings.showmsg("The file you choose is not an allowed file type.",3);
  38. this.debug("Error Code: Invalid File Type, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
  39. return;
  40. default:
  41. swfu.customSettings.showmsg("An error occurred in the upload. Try again later.",3);
  42. this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
  43. return;
  44. }
  45. } catch (e) {}
  46. },
  47. fileQueued:function(file){
  48. try {
  49. this.customSettings.form.find("input[plugin='swfupload']").val(file.name);
  50. } catch (e) {}
  51. },
  52. fileDialogComplete:function(numFilesSelected, numFilesQueued){
  53. this.startUpload();
  54. },
  55. uploadProgress:function(file, bytesLoaded, bytesTotal){
  56. try {
  57. var percent = Math.ceil((bytesLoaded / bytesTotal) * 100);
  58. this.customSettings.showmsg("已上传:"+percent+"%",1);
  59. //this.customSettings.form.find(".fsUploadProgress").text("已上传:"+percent+"%");
  60. } catch (e) {}
  61. },
  62. uploadSuccess:function(file, serverData){
  63. try {
  64. if (serverData === " ") {
  65. this.customSettings.upload_successful = false;
  66. } else {
  67. this.customSettings.upload_successful = true;
  68. this.customSettings.form.find("input[pluginhidden='swfupload']").val(serverData);
  69. }
  70. } catch (e) {}
  71. },
  72. uploadComplete:function(file){
  73. try {
  74. if (this.customSettings.upload_successful) {
  75. //this.setButtonDisabled(true);
  76. swfuploadhandler.uploadDone.call(this);
  77. } else {
  78. this.customSettings.form.find("input[plugin='swfupload']").val("");
  79. this.customSettings.showmsg("There was a problem with the upload.\nThe server did not accept it.",3);
  80. }
  81. } catch (e) {}
  82. },
  83. uploadError:function(file, errorCode, message){
  84. try {
  85. if (errorCode === SWFUpload.UPLOAD_ERROR.FILE_CANCELLED) {
  86. // Don't show cancelled error boxes
  87. return;
  88. }
  89. this.customSettings.form.find("input[plugin='swfupload']").val("");
  90. // Handle this error separately because we don't want to create a FileProgress element for it.
  91. switch (errorCode) {
  92. case SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL:
  93. this.customSettings.showmsg("There was a configuration error. You will not be able to upload a resume at this time.",3);
  94. this.debug("Error Code: No backend file, File name: " + file.name + ", Message: " + message);
  95. return;
  96. case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
  97. this.customSettings.showmsg("You may only upload 1 file.",3);
  98. this.debug("Error Code: Upload Limit Exceeded, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
  99. return;
  100. case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
  101. case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
  102. break;
  103. default:
  104. this.customSettings.showmsg("An error occurred in the upload. Try again later.",3);
  105. this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
  106. return;
  107. }
  108. } catch (ex) {}
  109. }
  110. }
  111. var swfuploadefaults={
  112. file_size_limit : "10 MB",
  113. file_types : "*.*",
  114. file_types_description : "All Files",
  115. file_upload_limit : "0",
  116. file_queue_limit : "10",
  117. button_placeholder_id : "spanButtonPlaceholder",
  118. file_post_name: "resume_file",
  119. upload_url: "demo/plugin/swfupload/upload.php",
  120. button_image_url: "demo/plugin/swfupload/XPButtonUploadText_61x22.png",
  121. button_width: 61,
  122. button_height: 22,
  123. flash_url: "demo/plugin/swfupload/swfupload.swf",
  124. swfupload_loaded_handler : swfuploadhandler.swfUploadLoaded,
  125. file_dialog_start_handler: swfuploadhandler.fileDialogStart,
  126. file_queued_handler : swfuploadhandler.fileQueued,
  127. file_queue_error_handler : swfuploadhandler.fileQueueError,
  128. file_dialog_complete_handler : swfuploadhandler.fileDialogComplete,
  129. upload_start_handler : swfuploadhandler.uploadStart,
  130. upload_progress_handler : swfuploadhandler.uploadProgress,
  131. upload_error_handler : swfuploadhandler.uploadError,
  132. upload_success_handler : swfuploadhandler.uploadSuccess,
  133. upload_complete_handler : swfuploadhandler.uploadComplete,
  134. custom_settings:{},
  135. debug: false
  136. }
  137. //$(function(){
  138. //独立触发事件;
  139. //var custom={
  140. // custom_settings:{
  141. // form:$this,
  142. // showmsg:function(msg){
  143. // alert(msg);
  144. // }
  145. // }
  146. //}
  147. //swfuploadhandler.init(custom);
  148. //})