国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

264 lines
7.9KB

  1. /**
  2. *
  3. * @version $Id: handlers.js 1 22:28 2010年7月20日Z tianya $
  4. * @package DedeBIZ.Administrator
  5. * @copyright Copyright (c) 2021, DedeBIZ.COM
  6. * @license https://www.dedebiz.com/license
  7. * @link https://www.dedebiz.com
  8. */
  9. //---事件句并------------------------------
  10. function fileQueueError(file, errorCode, message) {
  11. try {
  12. var imageName = "error.gif";
  13. var errorName = "";
  14. if (errorCode === SWFUpload.errorCode_QUEUE_LIMIT_EXCEEDED) {
  15. errorName = "您添加的文件超过了限制!";
  16. }
  17. if (errorName !== "") {
  18. alert(errorName);
  19. return;
  20. }
  21. switch (errorCode) {
  22. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  23. imageName = "zerobyte.gif";
  24. break;
  25. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  26. imageName = "toobig.gif";
  27. break;
  28. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  29. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  30. default:
  31. alert(message);
  32. break;
  33. }
  34. addImage("images/" + imageName, 0);
  35. } catch (ex) {
  36. this.debug(ex);
  37. }
  38. }
  39. function fileDialogComplete(numFilesSelected, numFilesQueued) {
  40. try {
  41. if (numFilesQueued > 0) {
  42. this.startUpload();
  43. }
  44. } catch (ex) {
  45. this.debug(ex);
  46. }
  47. }
  48. function uploadProgress(file, bytesLoaded) {
  49. try {
  50. var percent = Math.ceil((bytesLoaded / file.size) * 100);
  51. var progress = new FileProgress(file, this.customSettings.upload_target);
  52. progress.setProgress(percent);
  53. if (percent === 100) {
  54. progress.setStatus("创建缩略图...");
  55. progress.toggleCancel(false, this);
  56. } else {
  57. progress.setStatus("上传中...");
  58. progress.toggleCancel(true, this);
  59. }
  60. } catch (ex) {
  61. this.debug(ex);
  62. }
  63. }
  64. function uploadSuccess(file, serverData) {
  65. try {
  66. var progress = new FileProgress(file, this.customSettings.upload_target);
  67. if (serverData.substring(0, 7) === "FILEID:") {
  68. addImage("swfupload.php?dopost=thumbnail&id=" + serverData.substring(7), serverData.substring(7));
  69. progress.setStatus("获取缩略图...");
  70. progress.toggleCancel(false);
  71. } else {
  72. addImage("images/error.gif", 0);
  73. progress.setStatus("有错误!");
  74. progress.toggleCancel(false);
  75. alert(serverData);
  76. }
  77. } catch (ex) {
  78. this.debug(ex);
  79. }
  80. }
  81. function uploadComplete(file) {
  82. try {
  83. /* I want the next upload to continue automatically so I'll call startUpload here */
  84. if (this.getStats().files_queued > 0) {
  85. this.startUpload();
  86. } else {
  87. var progress = new FileProgress(file, this.customSettings.upload_target);
  88. progress.setComplete();
  89. progress.setStatus("所有图片上传完成...");
  90. progress.toggleCancel(false);
  91. }
  92. } catch (ex) {
  93. this.debug(ex);
  94. }
  95. }
  96. function uploadError(file, errorCode, message) {
  97. var imageName = "error.gif";
  98. var progress;
  99. try {
  100. switch (errorCode) {
  101. case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
  102. try {
  103. progress = new FileProgress(file, this.customSettings.upload_target);
  104. progress.setCancelled();
  105. progress.setStatus("Cancelled");
  106. progress.toggleCancel(false);
  107. }
  108. catch (ex1) {
  109. this.debug(ex1);
  110. }
  111. break;
  112. case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
  113. try {
  114. progress = new FileProgress(file, this.customSettings.upload_target);
  115. progress.setCancelled();
  116. progress.setStatus("Stopped");
  117. progress.toggleCancel(true);
  118. }
  119. catch (ex2) {
  120. this.debug(ex2);
  121. }
  122. case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
  123. imageName = "uploadlimit.gif";
  124. break;
  125. default:
  126. alert(message);
  127. break;
  128. }
  129. addImage("images/" + imageName, 0);
  130. } catch (ex3) {
  131. this.debug(ex3);
  132. }
  133. }
  134. var albImg = 0;
  135. function addImage(src, pid) {
  136. var newImgDiv = document.createElement("div");
  137. var delstr = '';
  138. var iptwidth = 190;
  139. albImg++;
  140. if (pid != 0) {
  141. albImg = 'ok' + pid;
  142. delstr = '<a href="javascript:delAlbPic(' + pid + ')">[删除]</a>';
  143. } else {
  144. albImg = 'err' + albImg;
  145. }
  146. newImgDiv.className = 'albCt';
  147. newImgDiv.id = 'albCt' + albImg;
  148. document.getElementById("thumbnails").appendChild(newImgDiv);
  149. newImgDiv.innerHTML = '<img src="' + src + '" width="120" />' + delstr;
  150. if (typeof arctype != 'undefined' && arctype == 'article') {
  151. iptwidth = 100;
  152. if (pid != 0) {
  153. newImgDiv.innerHTML = '<img src="' + src + '" width="120" onClick="addtoEdit(' + pid + ')"/>' + delstr;
  154. }
  155. }
  156. newImgDiv.innerHTML += '<div style="margin-top:10px">注释:<input type="text" name="picinfo' + albImg + '" value="" style="width:' + iptwidth + 'px;" /></div>';
  157. }
  158. /* ******************************************
  159. * FileProgress Object
  160. * Control object for displaying file info
  161. * ****************************************** */
  162. function FileProgress(file, targetID) {
  163. this.fileProgressID = "divFileProgress";
  164. this.fileProgressWrapper = document.getElementById(this.fileProgressID);
  165. if (!this.fileProgressWrapper) {
  166. this.fileProgressWrapper = document.createElement("div");
  167. this.fileProgressWrapper.className = "progressWrapper";
  168. this.fileProgressWrapper.id = this.fileProgressID;
  169. this.fileProgressElement = document.createElement("div");
  170. this.fileProgressElement.className = "progressContainer";
  171. var progressCancel = document.createElement("a");
  172. progressCancel.className = "progressCancel";
  173. progressCancel.href = "#";
  174. progressCancel.style.visibility = "hidden";
  175. progressCancel.appendChild(document.createTextNode(" "));
  176. var progressText = document.createElement("div");
  177. progressText.className = "progressName";
  178. progressText.appendChild(document.createTextNode(file.name));
  179. var progressBar = document.createElement("div");
  180. progressBar.className = "progressBarInProgress";
  181. var progressStatus = document.createElement("div");
  182. progressStatus.className = "progressBarStatus";
  183. progressStatus.innerHTML = "&nbsp;";
  184. this.fileProgressElement.appendChild(progressCancel);
  185. this.fileProgressElement.appendChild(progressText);
  186. this.fileProgressElement.appendChild(progressStatus);
  187. this.fileProgressElement.appendChild(progressBar);
  188. this.fileProgressWrapper.appendChild(this.fileProgressElement);
  189. document.getElementById(targetID).appendChild(this.fileProgressWrapper);
  190. } else {
  191. this.fileProgressElement = this.fileProgressWrapper.firstChild;
  192. this.fileProgressElement.childNodes[1].firstChild.nodeValue = file.name;
  193. }
  194. this.height = this.fileProgressWrapper.offsetHeight;
  195. }
  196. FileProgress.prototype.setProgress = function (percentage) {
  197. this.fileProgressElement.className = "progressContainer blue";
  198. this.fileProgressElement.childNodes[3].className = "progressBarInProgress";
  199. this.fileProgressElement.childNodes[3].style.width = percentage + "%";
  200. };
  201. FileProgress.prototype.setComplete = function () {
  202. this.fileProgressElement.className = "progressContainer green";
  203. this.fileProgressElement.childNodes[3].className = "progressBarComplete";
  204. this.fileProgressElement.childNodes[3].style.width = "";
  205. };
  206. FileProgress.prototype.setError = function () {
  207. this.fileProgressElement.className = "progressContainer red";
  208. this.fileProgressElement.childNodes[3].className = "progressBarError";
  209. this.fileProgressElement.childNodes[3].style.width = "";
  210. };
  211. FileProgress.prototype.setCancelled = function () {
  212. this.fileProgressElement.className = "progressContainer";
  213. this.fileProgressElement.childNodes[3].className = "progressBarError";
  214. this.fileProgressElement.childNodes[3].style.width = "";
  215. };
  216. FileProgress.prototype.setStatus = function (status) {
  217. this.fileProgressElement.childNodes[2].innerHTML = status;
  218. };
  219. FileProgress.prototype.toggleCancel = function (show, swfuploadInstance) {
  220. this.fileProgressElement.childNodes[0].style.visibility = show ? "visible" : "hidden";
  221. if (swfuploadInstance) {
  222. var fileID = this.fileProgressID;
  223. this.fileProgressElement.childNodes[0].onclick = function () {
  224. swfuploadInstance.cancelUpload(fileID);
  225. return false;
  226. };
  227. }
  228. };