PageRenderTime 52ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/9D.FrameWork/iSun.Web/WebFilesExplorer/js/WebExplorerMain.js

#
JavaScript | 576 lines | 442 code | 102 blank | 32 comment | 66 complexity | 2d9598778e4a428ae7de922a9fc06da0 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, Apache-2.0, GPL-2.0, BSD-3-Clause, LGPL-2.0, MIT, GPL-3.0
  1. //和界面交互的主文件
  2. //初始化树
  3. var nd = new TreeNode(); //创建树对象
  4. nd.container = $("tree"); //找到容器
  5. nd.text = "后台程序文件";
  6. nd.Show();
  7. currentNode = nd;
  8. currentNode.Refersh();
  9. //加载对话框
  10. var dialog = new Dialog();
  11. dialog.ImgZIndex = 110;
  12. dialog.DialogZIndex = 111;
  13. //下载操作
  14. clickFile = function (fName) {
  15. window.onbeforeunload = function () { }
  16. window.location = defaultURL + "?action=DOWNLOAD&value1=" + encodeURIComponent(currentNode.path + fName);
  17. window.onbeforeunload = function () {
  18. return "无法保存当前状态,请退出!"
  19. };
  20. }
  21. //在线编辑操作
  22. var fileEditor = new Dialog();
  23. fileEditor.Content = "<div id='editorDiv'><input id='switchEditor' type='button' value='切换编辑器'/><br><textarea id='FileContentTextArea' name='FileContentTextArea' cols='80' rows='30' style='width:600px;height:400px'></textarea></div>";
  24. fileEditor.Width = 626;
  25. var oFCKeditor; //富文本编辑器对象
  26. var oEditor; //定义富文本比机器示例
  27. var isRichEditor = false; //当前编辑器状态
  28. var currentContent = ""; //当前内容
  29. var textareaEditor = null; //文本编辑器
  30. var switchButton = null; //切换按钮
  31. var list = null; //选中的文件
  32. var cutCopyOperate = null; //当前操作
  33. var cutCopyFiles = null; //操作的文件
  34. var currentEditFile = null;//要编辑的文件
  35. //在切换回普通文本框时发生
  36. function FCKeditor_OnComplete(editorInstance) {
  37. oEditor = editorInstance;
  38. if (currentContent != null) {
  39. oEditor.SetData(currentContent);
  40. }
  41. }
  42. function switchEditor() {
  43. getEditorContent(); //先获取要编辑的内容
  44. if (isRichEditor) {
  45. isRichEditor = false;
  46. //创建新文件
  47. newFile();
  48. }
  49. else {
  50. isRichEditor = true;
  51. //创建编辑器
  52. createEditor();
  53. }
  54. }
  55. //创建一个编辑器
  56. function createEditor() {
  57. if (oFCKeditor == null) {
  58. oFCKeditor = new FCKeditor('FileContentTextArea');
  59. oFCKeditor.BasePath = "fckeditor/";
  60. oFCKeditor.Width = '600';
  61. oFCKeditor.Height = '400';
  62. oFCKeditor.ToolbarSet = 'Dialog';
  63. oFCKeditor.Config['FullPage'] = true;
  64. }
  65. oFCKeditor.ReplaceTextarea();
  66. }
  67. //获取编辑器的内容
  68. function getEditorContent() {
  69. if (isRichEditor) {
  70. currentContent = oEditor.GetXHTML(true); //这是FCK的情况
  71. }
  72. else {
  73. currentContent = textareaEditor.value;
  74. }
  75. }
  76. //创建新文件
  77. function newFile() {
  78. isRichEditor = false;
  79. fileEditor.Text = "新建文件";
  80. fileEditor.Show(2);
  81. //找到编辑器的元素
  82. textareaEditor = $("FileContentTextArea");
  83. switchButton = $("switchEditor");
  84. textareaEditor.value = currentContent;
  85. switchButton.onclick = switchEditor;
  86. fileEditor.Close = closeConfirm;
  87. fileEditor.OK = function () {
  88. dialog.Content = "<span>请输入文件名:</span><input id='inputFile' type='textbox' style='width:100px'/>";
  89. dialog.Show(2);
  90. dialog.OK = saveNewFile;//调用保存新文件
  91. }
  92. }
  93. //保存新建的文件
  94. function saveNewFile() {
  95. var result = saveFile("NEWFILE", $("inputFile").value);
  96. dialog.Text = "提示";
  97. if (result == "OK") {
  98. dialog.Content = "文件创建成功!";
  99. currentNode.Refersh();
  100. fileEditor.Hide();
  101. dialog.Show(1);
  102. dialog.OK = dialog.Close;
  103. }
  104. }
  105. //保存文件
  106. function saveFile(action, fileName) {
  107. getEditorContent();
  108. var url = defaultURL + "?action=" + action + "&value1=" + encodeURIComponent(currentNode.path + fileName);
  109. return executeHttpRequest("POST", url, "content=" + encodeURIComponent(currentContent));
  110. }
  111. //退出确认对话框
  112. function closeConfirm() {
  113. dialog.Text = "提示";
  114. dialog.Content = "<span style='color:red;'>文本已经改变,确定要退出吗?</span>";
  115. dialog.Show();
  116. dialog.OK = function () {
  117. dialog.Close();
  118. fileEditor.Hide();
  119. currentContent = "";//***************
  120. }
  121. }
  122. //编辑文件
  123. editFile = function (fName) {
  124. isRichEditor = false;
  125. currentEditFile = fName;
  126. fileEditor.Text = "修改文件:" + fName;
  127. // fileEditor.
  128. fileEditor.Show(3);
  129. textareaEditor = $("FileContentTextArea");
  130. switchButton = $("switchEditor");
  131. textareaEditor.value = loadFileContent(fName); //获取要编辑的文件
  132. switchButton.onclick = switchEditor;
  133. fileEditor.Close = closeConfirm;
  134. fileEditor.OK = function () {
  135. var result = saveFile("SAVEEDITFILE", fName);
  136. dialog.Text = "提示";
  137. if (result == "OK") {
  138. dialog.Content = "文件保存成功!";
  139. currentNode.Refersh();
  140. fileEditor.Hide();
  141. }
  142. else {
  143. dialog.Content = "文件保存失败!";
  144. }
  145. dialog.OK = dialog.Close;
  146. dialog.Show(1);
  147. }
  148. fileEditor.Retry = function () {
  149. if (isRichEditor) {//如果是富文本编辑器
  150. oEditor.SetData(loadFileContent(fName));
  151. }
  152. else {
  153. textareaEditor.value = loadFileContent(fName);
  154. }
  155. }
  156. }
  157. //读取服务器文件
  158. loadFileContent = function (fName) {
  159. var url = defaultURL + "?action=GETEDITFILE&value1=" + encodeURIComponent(currentNode.path + fName);
  160. var content = executeHttpRequest("GET", url, null);
  161. if (content == "ERROR") {
  162. dialog.Text = "错误";
  163. dialog.Content = "读取文件出错";
  164. dialog.Show(1);
  165. content = "";
  166. dialog.OK = dialog.Close;
  167. }
  168. return content;
  169. }
  170. //****************************************************************
  171. //*********************** 以下是新加代码 *********************
  172. //****************************************************************
  173. //返回上级目录
  174. function gotoParentDirectory() {
  175. if (currentNode != null) {
  176. currentNode.GotoParentNode();
  177. }
  178. }
  179. //根目录
  180. function goRoot() {
  181. currentNode = nd;
  182. currentNode.Refersh();
  183. }
  184. //刷新
  185. function refersh() {
  186. if (currentNode != null) {
  187. currentNode.Refersh();
  188. }
  189. }
  190. //全选
  191. function selectAll() {
  192. var checkBoxes = $("fileList").getElementsByTagName("input");
  193. for (var i = 0; i < checkBoxes.length; i++) {
  194. if (checkBoxes[i].type == "checkbox") {
  195. checkBoxes[i].checked = $("checkAll").checked;
  196. }
  197. }
  198. }
  199. //新建目录
  200. function newDirectory() {
  201. dialog.Content = "<div><span>请输入新目录名称:</span><input id='dirName' type='textbox' style='width:100px;' /></div>";
  202. dialog.Text = "新建目录";
  203. dialog.Show();
  204. var dir = $("dirName");
  205. dir.focus();
  206. dialog.OK = function () {
  207. if (!(/^[\w\u4e00-\u9fa5-\.]+$/.test(dir.value))) {
  208. dialog.Content = "<span style='color:red;'>目录名称不正确!</span>";
  209. dialog.OK = function () {
  210. newDirectory();
  211. }
  212. dialog.Show(1);
  213. return;
  214. }
  215. var url = defaultURL + "?action=NEWDIR&value1=" + encodeURIComponent(currentNode.path + dir.value);
  216. var result = executeHttpRequest("GET", url, null);
  217. if (result == "OK") {
  218. currentNode.Refersh();
  219. dialog.Content = "目录创建成功!";
  220. dialog.Show(1);
  221. dialog.OK = dialog.Close;
  222. }
  223. else {
  224. dialog.Content = "<span style='color:red;'>目录创建失败,请重试!</span>";
  225. dialog.Show();
  226. dialog.OK = function () {
  227. newDirectory();
  228. }
  229. }
  230. }
  231. }
  232. //检查文件名合法性
  233. function checkFileName() {
  234. return (/^[\w\u4e00-\u9fa5-\.]+\.[a-zA-Z0-9]{1,8}$/.test($("inputFile").value));
  235. }
  236. //获取选中的文件
  237. function getSelectedFile() {
  238. list = [];
  239. var checkBoxes = $("fileList").getElementsByTagName("input");
  240. for (var i = 0; i < checkBoxes.length; i++) {
  241. if (checkBoxes[i].type == "checkbox") {
  242. if (checkBoxes[i].checked) {
  243. list.push(currentNode.path + checkBoxes[i].title);
  244. }
  245. }
  246. }
  247. }
  248. function del() {
  249. getSelectedFile();
  250. dialog.Text = "删除文件";
  251. if (list.length <= 0) {
  252. dialog.Content = "请选择要删除的文件!";
  253. dialog.OK = dialog.Close;
  254. dialog.Show(1);
  255. return;
  256. }
  257. dialog.Content = "这些文件删除后将不可恢复,是否确定?";
  258. dialog.Show();
  259. dialog.OK = function () {
  260. var url = defaultURL + "?action=DELETE&value1=" + encodeURIComponent(list.join("|"));
  261. var result = executeHttpRequest("GET", url, null);
  262. if (result == "OK") {
  263. currentNode.Refersh();
  264. dialog.Content = "目录删除成功!";
  265. dialog.OK = dialog.Close;
  266. dialog.Show(1);
  267. }
  268. else {
  269. dialog.Content = "<span style='color:red;'>目录删除失败,请重试!</span>";
  270. dialog.Show(1);
  271. currentNode.Refersh();
  272. dialog.OK = dialog.Close;
  273. }
  274. }
  275. }
  276. function cut() {
  277. getSelectedFile();
  278. dialog.Text = "剪切";
  279. if (list.length < 1) {
  280. dialog.Content = "请选择要剪切的文件及文件夹。";
  281. }
  282. else {
  283. dialog.Content = "已剪切以下文件及文件夹:<br /><div style='text-align:left;'>" + list.join("<br />") + "</div>";
  284. cutCopyOperate = "CUT";
  285. cutCopyFiles = list;
  286. }
  287. dialog.Show(1);
  288. dialog.OK = dialog.Close;
  289. }
  290. function copy() {
  291. getSelectedFile();
  292. dialog.Text = "复制";
  293. if (list.length < 1) {
  294. dialog.Content = "请选择要复制的文件及文件夹。";
  295. }
  296. else {
  297. dialog.Content = "已复制以下文件及文件夹:<br /><div style='text-align:left;'>" + list.join("<br />") + "</div>";
  298. cutCopyOperate = "COPY";
  299. cutCopyFiles = list;
  300. }
  301. dialog.Show(1);
  302. dialog.OK = dialog.Close;
  303. }
  304. function paste() {
  305. dialog.Text = "粘贴";
  306. if (cutCopyOperate != 'CUT' && cutCopyOperate != 'COPY' || cutCopyFiles.length < 1) {
  307. dialog.Content = "剪贴板没有任何文件及文件夹。";
  308. dialog.OK = dialog.Close;
  309. dialog.Show(1);
  310. return;
  311. }
  312. dialog.Content = "确认将以下文件粘贴到当前目录:" + currentNode.path + "?<br /><div style='text-align:left;'>" + cutCopyFiles.join("<br />") + "</div>";
  313. dialog.Show();
  314. dialog.OK = function () {
  315. var url = defaultURL + "?action=" + cutCopyOperate + "&value1=" + encodeURIComponent(currentNode.path) + "&value2=" + encodeURIComponent(cutCopyFiles.join("|"));
  316. var result = executeHttpRequest("GET", url, null);
  317. if (result == "OK") {
  318. dialog.Content = "粘贴操作成功!";
  319. currentNode.Refersh();
  320. }
  321. else {
  322. dialog.Content = "<span style='color:red;'>粘贴操作失败!</span>";
  323. }
  324. dialog.Show(1);
  325. dialog.OK = dialog.Close;
  326. }
  327. }
  328. var iframeOnload = function () { }
  329. //上传文件
  330. function uploadFile() {
  331. iframeOnload = function () { }
  332. dialog.Content = "<iframe id='uploadFrm' frameborder='no' border='0' scrolling='no' allowtransparency='yes' onload='iframeOnload()' name='uploadFrm' style='width:0px; height:0px; display:none;'></iframe><form name='actionForm' id='actionForm' action='" + defaultURL + "?action=UPLOAD&value1=" + currentNode.path + "' method='POST' target='uploadFrm' enctype='multipart/form-data'><input name='selectFile' width='150' type='file' /></form><div id='uploadStatus' style='display:none;'><img src='images/process.gif' /><div style='color:#ccc;'>正在上传,如果长时间不响应,可能是上传文件太大导致出错!</div></div>";
  333. dialog.Text = "上传文件";
  334. dialog.Show();
  335. dialog.OK = function () {
  336. iframeOnload = function () {
  337. dialog.Text = "提示";
  338. dialog.Content = "文件上传成功!";
  339. dialog.OK = dialog.Close;
  340. dialog.Show(1);
  341. currentNode.Refersh();
  342. }
  343. $("actionForm").submit();
  344. $("actionForm").style.display = "none";
  345. $("uploadStatus").style.display = "";
  346. }
  347. }
  348. //下载多个文件
  349. function downloadsFiles() {
  350. getSelectedFile();
  351. dialog.Text="下载";
  352. if(list.length<1)
  353. {
  354. dialog.Content="请选择要下载的文件";
  355. dialog.Show();
  356. dialog.OK=dialog.Close;
  357. return;
  358. }
  359. window.onbeforeunload=function(){}
  360. window.location.href=defaultURL + "?action=DOWNLOADS&value1=" + list.join("|");
  361. window.onbeforeunload=function(){
  362. return "cuole ";
  363. };
  364. }
  365. //重命名文件
  366. renameFile = function (fName) {
  367. dialog.Text = "重命名:" + fName;
  368. dialog.Content = "请输入新名称:<input id='newName' type='textbox' style='width:120px;' value='" + fName + "' />";
  369. dialog.Show();
  370. var txtNewName = $("newName");
  371. txtNewName.value = fName;
  372. txtNewName.focus();
  373. dialog.OK = function () {
  374. if (!(/^[\w\u4e00-\u9fa5-\.]+[a-zA-Z0-9.]*$/.test(txtNewName.value))) {
  375. dialog.Content = "<span style='color:red;'>输入的新名称不正确!</span>";
  376. dialog.OK = function () {
  377. renameFile(fName);
  378. }
  379. dialog.Show(1);
  380. return;
  381. }
  382. var url = defaultURL + "?action=RENAME&value1=" + encodeURIComponent(currentNode.path + fName) + "&value2=" + encodeURIComponent(currentNode.path + txtNewName.value);
  383. var result = executeHttpRequest("GET", url, null);
  384. if (result == "OK") {
  385. currentNode.Refersh();
  386. dialog.Content = "重命名成功!";
  387. dialog.OK = dialog.Close;
  388. dialog.Show(1);
  389. }
  390. else {
  391. dialog.Content = "<span style='color:red;'>重命名失败,请重试!</span>";
  392. dialog.OK = function () {
  393. renameFile(fName);
  394. }
  395. dialog.Show();
  396. }
  397. }
  398. }
  399. function zipFile() {
  400. getSelectedFile();
  401. if (list.length < 1) {
  402. dialog.Text = "提示";
  403. dialog.Content = "请选择要压缩的文件和文件夹!";
  404. dialog.Show(1);
  405. dialog.OK = dialog.Close;
  406. return;
  407. }
  408. dialog.Text = "压缩";
  409. dialog.Content = "<span>请输入压缩文件名:</span><input id='inputFile' type='textbox' style='width:100px;' />";
  410. dialog.Show();
  411. dialog.OK = function () {
  412. if (checkFileName()) {
  413. var url = defaultURL + "?action=ZIP&value1=" + encodeURIComponent(currentNode.path + $("inputFile").value) + "&value2=" + encodeURIComponent(list.join("|"));
  414. var result = executeHttpRequest("GET", url, null);
  415. dialog.Text = "提示";
  416. if (result == "OK") {
  417. dialog.Content = "压缩成功!";
  418. currentNode.Refersh();
  419. }
  420. else {
  421. dialog.Content = "压缩失败!";
  422. }
  423. dialog.OK = dialog.Close;
  424. dialog.Show(1);
  425. }
  426. else {
  427. dialog.Content = "输入的文件名不正确!";
  428. dialog.Text = "提示";
  429. dialog.Show(1);
  430. dialog.OK = function () {
  431. dialog.Close();
  432. zipFile();
  433. }
  434. }
  435. }
  436. }
  437. function unZipFile() {
  438. getSelectedFile();
  439. if (list.length < 1) {
  440. dialog.Text = "提示";
  441. dialog.Content = "请选择要解压的文件!";
  442. dialog.Show(1);
  443. dialog.OK = dialog.Close;
  444. return;
  445. }
  446. var url = defaultURL + "?action=UNZIP&value1=" + encodeURIComponent(currentNode.path) + "&value2=" + encodeURIComponent(list.join("|"));
  447. var result = executeHttpRequest("GET", url, null);
  448. dialog.Text = "提示";
  449. if (result == "OK") {
  450. dialog.Content = "解压成功!";
  451. currentNode.Refersh();
  452. }
  453. else {
  454. dialog.Content = "解压失败!";
  455. }
  456. dialog.OK = dialog.Close;
  457. dialog.Show(1);
  458. }
  459. $("tree").style.height = document.documentElement.clientHeight + "px";
  460. if (document.compatMode != 'CSS1Compat') {
  461. $("tree").style.height = document.body.clientHeight + "px";
  462. }
  463. //menuitem 鼠标移上变色
  464. var menuItems = $("menu").getElementsByTagName("div");
  465. for (var i = 0; i < menuItems.length; i++) {
  466. menuItems[i].onmouseover = function () {
  467. this.style.color = "red";
  468. this.style.backgroundColor = "#eef";
  469. }
  470. menuItems[i].onmouseout = function () {
  471. this.style.color = "";
  472. this.style.backgroundColor = "transparent";
  473. }
  474. }