handlers.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. function att_show(serverData,file)
  2. {
  3. var serverData = serverData.replace(/<div.*?<\/div>/g,'');
  4. var data = serverData.split(',');
  5. var id = data[0];
  6. var src = data[1];
  7. var ext = data[2];
  8. var filename = data[3];
  9. if(id == 0) {
  10. alert(src)
  11. return false;
  12. }
  13. if(ext == 1) {
  14. var img = '<a href="javascript:;" onclick="javascript:att_cancel(this,'+id+',\'upload\')" class="on"><div class="icon"></div><img src="'+src+'" width="80" imgid="'+id+'" path="'+src+'" title="'+filename+'"/></a>';
  15. } else {
  16. var img = '<a href="javascript:;" onclick="javascript:att_cancel(this,'+id+',\'upload\')" class="on"><div class="icon"></div><img src="statics/images/ext/'+ext+'.png" width="80" imgid="'+id+'" path="'+src+'" title="'+filename+'"/></a>';
  17. }
  18. $.get('index.php?m=attachment&c=attachments&a=swfupload_json&aid='+id+'&src='+src+'&filename='+filename);
  19. $('#fsUploadProgress').append('<li><div id="attachment_'+id+'" class="img-wrap"></div></li>');
  20. $('#attachment_'+id).html(img);
  21. $('#att-status').append('|'+src);
  22. $('#att-name').append('|'+filename);
  23. }
  24. function att_insert(obj,id)
  25. {
  26. var uploadfile = $("#attachment_"+id+"> img").attr('path');
  27. $('#att-status').append('|'+uploadfile);
  28. }
  29. function att_cancel(obj,id,source){
  30. var src = $(obj).children("img").attr("path");
  31. var filename = $(obj).children("img").attr("title");
  32. if($(obj).hasClass('on')){
  33. $(obj).removeClass("on");
  34. var imgstr = $("#att-status").html();
  35. var length = $("a[class='on']").children("img").length;
  36. var strs = filenames = '';
  37. for(var i=0;i<length;i++){
  38. strs += '|'+$("a[class='on']").children("img").eq(i).attr('path');
  39. filenames += '|'+$("a[class='on']").children("img").eq(i).attr('title');
  40. }
  41. $('#att-status').html(strs);
  42. $('#att-name').html(filenames);
  43. if(source=='upload') $('#att-status-del').append('|'+id);
  44. } else {
  45. $(obj).addClass("on");
  46. $('#att-status').append('|'+src);
  47. $('#att-name').append('|'+filename);
  48. var imgstr_del = $("#att-status-del").html();
  49. var imgstr_del_obj = $("a[class!='on']").children("img")
  50. var length_del = imgstr_del_obj.length;
  51. var strs_del='';
  52. for(var i=0;i<length_del;i++){strs_del += '|'+imgstr_del_obj.eq(i).attr('imgid');}
  53. if(source=='upload') $('#att-status-del').html(strs_del);
  54. }
  55. }
  56. //swfupload functions
  57. function fileDialogStart() {
  58. /* I don't need to do anything here */
  59. }
  60. function fileQueued(file) {
  61. if(file!= null){
  62. try {
  63. var progress = new FileProgress(file, this.customSettings.progressTarget);
  64. progress.toggleCancel(true, this);
  65. } catch (ex) {
  66. this.debug(ex);
  67. }
  68. }
  69. }
  70. function fileDialogComplete(numFilesSelected, numFilesQueued)
  71. {
  72. try {
  73. if (this.getStats().files_queued > 0) {
  74. document.getElementById(this.customSettings.cancelButtonId).disabled = false;
  75. }
  76. /* I want auto start and I can do that here */
  77. //this.startUpload();
  78. } catch (ex) {
  79. this.debug(ex);
  80. }
  81. }
  82. function uploadStart(file)
  83. {
  84. var progress = new FileProgress(file, this.customSettings.progressTarget);
  85. progress.setStatus("正在上传请稍后...");
  86. return true;
  87. }
  88. function uploadProgress(file, bytesLoaded, bytesTotal)
  89. {
  90. var percent = Math.ceil((bytesLoaded / bytesTotal) * 100);
  91. var progress = new FileProgress(file, this.customSettings.progressTarget);
  92. progress.setProgress(percent);
  93. progress.setStatus("正在上传("+percent+" %)请稍后...");
  94. }
  95. function uploadSuccess(file, serverData)
  96. {
  97. att_show(serverData,file);
  98. var progress = new FileProgress(file, this.customSettings.progressTarget);
  99. progress.setComplete();
  100. progress.setStatus("文件上传成功");
  101. }
  102. function uploadComplete(file)
  103. {
  104. if (this.getStats().files_queued > 0)
  105. {
  106. this.startUpload();
  107. }
  108. }
  109. function uploadError(file, errorCode, message) {
  110. var msg;
  111. switch (errorCode)
  112. {
  113. case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:
  114. msg = "上传错误: " + message;
  115. break;
  116. case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:
  117. msg = "上传错误";
  118. break;
  119. case SWFUpload.UPLOAD_ERROR.IO_ERROR:
  120. msg = "服务器 I/O 错误";
  121. break;
  122. case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:
  123. msg = "服务器安全认证错误";
  124. break;
  125. case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:
  126. msg = "附件安全检测失败,上传终止";
  127. break;
  128. case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
  129. msg = '上传取消';
  130. break;
  131. case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
  132. msg = '上传终止';
  133. break;
  134. case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
  135. msg = '单次上传文件数限制为 '+swfu.settings.file_upload_limit+' 个';
  136. break;
  137. default:
  138. msg = message;
  139. break;
  140. }
  141. var progress = new FileProgress(file,this.customSettings.progressTarget);
  142. progress.setError();
  143. progress.setStatus(msg);
  144. }
  145. function fileQueueError(file, errorCode, message)
  146. {
  147. var errormsg;
  148. switch (errorCode) {
  149. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  150. errormsg = "请不要上传空文件";
  151. break;
  152. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  153. errormsg = "队列文件数量超过设定值";
  154. break;
  155. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  156. errormsg = "文件尺寸超过设定值";
  157. break;
  158. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  159. errormsg = "文件类型不合法";
  160. default:
  161. errormsg = '上传错误,请与管理员联系!';
  162. break;
  163. }
  164. var progress = new FileProgress('file',this.customSettings.progressTarget);
  165. progress.setError();
  166. progress.setStatus(errormsg);
  167. }