国内流行的内容管理系统(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.

265 line
7.9KB

  1. /**
  2. *
  3. * @version $Id: handlers.js 1 22:28 2010年7月20日Z tianya $
  4. * @package DedeCMS.Administrator
  5. * @copyright Copyright (c) 2020, 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. {
  152. iptwidth = 100;
  153. if(pid != 0) {
  154. newImgDiv.innerHTML = '<img src="'+src+'" width="120" onClick="addtoEdit('+pid+')"/>'+delstr;
  155. }
  156. }
  157. newImgDiv.innerHTML += '<div style="margin-top:10px">注释:<input type="text" name="picinfo'+albImg+'" value="" style="width:'+iptwidth+'px;" /></div>';
  158. }
  159. /* ******************************************
  160. * FileProgress Object
  161. * Control object for displaying file info
  162. * ****************************************** */
  163. function FileProgress(file, targetID) {
  164. this.fileProgressID = "divFileProgress";
  165. this.fileProgressWrapper = document.getElementById(this.fileProgressID);
  166. if (!this.fileProgressWrapper) {
  167. this.fileProgressWrapper = document.createElement("div");
  168. this.fileProgressWrapper.className = "progressWrapper";
  169. this.fileProgressWrapper.id = this.fileProgressID;
  170. this.fileProgressElement = document.createElement("div");
  171. this.fileProgressElement.className = "progressContainer";
  172. var progressCancel = document.createElement("a");
  173. progressCancel.className = "progressCancel";
  174. progressCancel.href = "#";
  175. progressCancel.style.visibility = "hidden";
  176. progressCancel.appendChild(document.createTextNode(" "));
  177. var progressText = document.createElement("div");
  178. progressText.className = "progressName";
  179. progressText.appendChild(document.createTextNode(file.name));
  180. var progressBar = document.createElement("div");
  181. progressBar.className = "progressBarInProgress";
  182. var progressStatus = document.createElement("div");
  183. progressStatus.className = "progressBarStatus";
  184. progressStatus.innerHTML = "&nbsp;";
  185. this.fileProgressElement.appendChild(progressCancel);
  186. this.fileProgressElement.appendChild(progressText);
  187. this.fileProgressElement.appendChild(progressStatus);
  188. this.fileProgressElement.appendChild(progressBar);
  189. this.fileProgressWrapper.appendChild(this.fileProgressElement);
  190. document.getElementById(targetID).appendChild(this.fileProgressWrapper);
  191. } else {
  192. this.fileProgressElement = this.fileProgressWrapper.firstChild;
  193. this.fileProgressElement.childNodes[1].firstChild.nodeValue = file.name;
  194. }
  195. this.height = this.fileProgressWrapper.offsetHeight;
  196. }
  197. FileProgress.prototype.setProgress = function (percentage) {
  198. this.fileProgressElement.className = "progressContainer blue";
  199. this.fileProgressElement.childNodes[3].className = "progressBarInProgress";
  200. this.fileProgressElement.childNodes[3].style.width = percentage + "%";
  201. };
  202. FileProgress.prototype.setComplete = function () {
  203. this.fileProgressElement.className = "progressContainer green";
  204. this.fileProgressElement.childNodes[3].className = "progressBarComplete";
  205. this.fileProgressElement.childNodes[3].style.width = "";
  206. };
  207. FileProgress.prototype.setError = function () {
  208. this.fileProgressElement.className = "progressContainer red";
  209. this.fileProgressElement.childNodes[3].className = "progressBarError";
  210. this.fileProgressElement.childNodes[3].style.width = "";
  211. };
  212. FileProgress.prototype.setCancelled = function () {
  213. this.fileProgressElement.className = "progressContainer";
  214. this.fileProgressElement.childNodes[3].className = "progressBarError";
  215. this.fileProgressElement.childNodes[3].style.width = "";
  216. };
  217. FileProgress.prototype.setStatus = function (status) {
  218. this.fileProgressElement.childNodes[2].innerHTML = status;
  219. };
  220. FileProgress.prototype.toggleCancel = function (show, swfuploadInstance) {
  221. this.fileProgressElement.childNodes[0].style.visibility = show ? "visible" : "hidden";
  222. if (swfuploadInstance) {
  223. var fileID = this.fileProgressID;
  224. this.fileProgressElement.childNodes[0].onclick = function () {
  225. swfuploadInstance.cancelUpload(fileID);
  226. return false;
  227. };
  228. }
  229. };