index_mydoc.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. var my_file_title = "";
  2. var my_file_status = "all"; //recycle
  3. var my_file_order = "DESC"; //ASC
  4. function file_search_keyup() {
  5. file_list_refresh();
  6. }
  7. function recycleInit() {
  8. ntf_init();
  9. file_list_refresh();
  10. }
  11. function indexInit() {
  12. ntf_init();
  13. file_list_refresh();
  14. }
  15. function time_standardize(date) {
  16. var today_date = new Date();
  17. var Local_time = date.toLocaleTimeString();
  18. //將時間去掉秒的信息
  19. if (Local_time && Local_time.split(":").length == 3) {
  20. var Local_time_string = Local_time.split(":")[0] + ":" + Local_time.split(":")[1];
  21. Local_time_string += Local_time.split(":")[2].slice(2);
  22. } else {
  23. var Local_time_string = d.toLocaleTimeString();
  24. }
  25. if (date.toLocaleDateString() == today_date.toLocaleDateString()) {
  26. //如果是今天的消息,只显示时间
  27. return Local_time_string;
  28. } else if (date.toLocaleDateString().slice(0, 5) == today_date.toLocaleDateString().slice(0, 5)) {
  29. //如果是今年但非今天的消息,只显示月日
  30. var date_length = date.toLocaleDateString().length;
  31. return date.toLocaleDateString().slice(5, date_length);
  32. } else {
  33. //如果不是今年的消息,显示年月日
  34. return date.toLocaleDateString();
  35. }
  36. }
  37. //显示最近查看列表
  38. function file_list_refresh() {
  39. var d = new Date();
  40. $.get(
  41. "getfilelist.php",
  42. {
  43. t: d.getTime(),
  44. keyword: my_file_title,
  45. status: $("#id_index_status").val(),
  46. orderby: "accese_time",
  47. order: "DESC",
  48. currLanguage: $("#id_language").val(),
  49. },
  50. function (data, status) {
  51. try {
  52. let file_list = JSON.parse(data);
  53. let html = "";
  54. for (x in file_list) {
  55. html += '<div class="file_list_row">';
  56. html += '<div class="file_list_col_1">';
  57. html += "<input id='file_check_" + x + '\' type="checkbox" />';
  58. html += "<input id='file_id_" + x + "' value='" + file_list[x].id + '\' type="hidden" />';
  59. html += "</div>";
  60. html += '<div class="file_list_col_2">';
  61. if (
  62. (file_list[x].parent_id == null || file_list[x].parent_id == "") &&
  63. parseInt(file_list[x].share) == 1
  64. ) {
  65. //shared
  66. html += "<span onclick=\"file_show_coop_win('" + file_list[x].id + "')\">";
  67. } else {
  68. html += "<span>";
  69. }
  70. html += "<svg class='icon' style='margin: 0 5px;'>";
  71. if (file_list[x].parent_id == null || file_list[x].parent_id == "") {
  72. if (parseInt(file_list[x].share) == 1) {
  73. //shared
  74. html += '<use xlink:href="./svg/icon.svg#share_to_other"></use>';
  75. } else {
  76. //my document
  77. html += '<use xlink:href="./svg/icon.svg#ic_person"></use>';
  78. }
  79. } else {
  80. //fork
  81. html += '<use xlink:href="./svg/icon.svg#other_share_to_me"></use>';
  82. }
  83. html += "</svg>";
  84. html += "</span>";
  85. html += "<div id='coop_show_" + file_list[x].id + "' style='display:inline;'></div>";
  86. let $link;
  87. if (file_list[x].doc_info && file_list[x].doc_info.length > 1) {
  88. $link = "<a href='editor.php?op=opendb&fileid=" + file_list[x].id + "' target='_blank'>";
  89. } else {
  90. $link = "<a href='editor.php?op=open&fileid=" + file_list[x].id + "' target='_blank'>";
  91. }
  92. html += $link + "<span id='title_" + file_list[x].id + "'>" + file_list[x].title;
  93. html += "</span></a>";
  94. //html +="<input type='input' style='diaplay:none;' id='input_title_"+file_list[x].id+"' value='"+file_list[x].title+"' />"
  95. html += '<span class="icon_btn_div hidden_function">';
  96. html +=
  97. '<span class="icon_btn_tip" style="margin-top: 0.7em;margin-left: 2.5em;">' +
  98. gLocal.gui.rename +
  99. "</span>";
  100. html +=
  101. "<button id='edit_title' type='button' class='icon_btn' onclick=\"title_change('" +
  102. file_list[x].id +
  103. "','" +
  104. file_list[x].title +
  105. "')\" >";
  106. html += ' <svg class="icon">';
  107. html += ' <use xlink:href="./svg/icon.svg#ic_rename"></use>';
  108. html += " </svg>";
  109. html += "</button>";
  110. html += "</span> ";
  111. html += "</div>";
  112. html += '<div class="file_list_col_3">';
  113. if (
  114. (file_list[x].parent_id && file_list[x].parent_id.length > 10) ||
  115. parseInt(file_list[x].share) == 1
  116. ) {
  117. html += "<svg class='icon'>";
  118. html += '<use xlink:href="./svg/icon.svg#ic_two_person"></use>';
  119. html += "</svg>";
  120. }
  121. html += "</div>";
  122. html += '<div class="file_list_col_4">';
  123. let d = new Date();
  124. let today_date = d.toLocaleDateString();
  125. d.setTime(file_list[x].accese_time);
  126. let Local_time = "";
  127. Local_time = time_standardize(d);
  128. /*
  129. if(d.getHours()<=9){
  130. Local_time +=":0"+d.getHours();
  131. }
  132. else{
  133. Local_time += ":"+d.getHours();
  134. }
  135. if(d.getMinutes()<=9){
  136. Local_time +=":0"+d.getMinutes();
  137. }
  138. else{
  139. Local_time += ":"+d.getMinutes();
  140. }
  141. let Local_date = d.toLocaleDateString();
  142. if(today_date==Local_date){
  143. html += gLocal.gui.today+Local_time;
  144. }
  145. else{
  146. html += Local_date;
  147. }
  148. */
  149. html += Local_time;
  150. html += "</div>";
  151. html += '<div class="file_list_col_5">';
  152. if (file_list[x].file_size < 102) {
  153. $str_size = file_list[x].file_size + "B";
  154. } else if (file_list[x].file_size < 1024 * 902) {
  155. $str_size = (file_list[x].file_size / 1024).toFixed(0) + "KB";
  156. } else {
  157. $str_size = (file_list[x].file_size / (1024 * 1024)).toFixed(1) + "MB";
  158. }
  159. html += $str_size;
  160. if (!(file_list[x].doc_info && file_list[x].doc_info.length > 1)) {
  161. html +=
  162. "<a href='../doc/pcs2db.php?doc_id=" +
  163. file_list[x].id +
  164. "' target='_blank'>转数据库格式</a>";
  165. }
  166. html += "</div>";
  167. html += "<div>";
  168. html += '<span class="icon_btn_div hidden_function">';
  169. html += '<span class="icon_btn_tip">' + gLocal.gui.copy_share_link + "</span>";
  170. html +=
  171. "<button id='edit_title' type='button' class='icon_btn' onclick=\"share_link_copy_to_clipboard('" +
  172. file_list[x].id +
  173. "')\" >";
  174. //html +=' <svg class="icon">';
  175. //html +=' <use xlink:href="./svg/icon.svg#ic_rename"></use>';
  176. //html +=' </svg>';
  177. html +=
  178. '<svg t="1611985739555" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6173" width="200" height="200"><path d="M423.198 640a83.84 83.84 0 0 1-64-28.8 259.84 259.84 0 0 1-26.88-308.48L441.118 128a261.12 261.12 0 1 1 448 272l-35.2 57.6a83.84 83.84 0 1 1-145.92-90.24l35.2-57.6a92.8 92.8 0 0 0-158.72-96.64l-107.52 176.64a92.8 92.8 0 0 0 9.6 109.44 83.84 83.84 0 0 1-64 139.52z" p-id="6174"></path><path d="M357.918 1024a261.12 261.12 0 0 1-222.72-397.44l31.36-50.56a83.84 83.84 0 1 1 144 87.68l-31.36 51.2a92.8 92.8 0 0 0 30.72 128 91.52 91.52 0 0 0 70.4 10.88 92.16 92.16 0 0 0 57.6-41.6l107.52-177.92a93.44 93.44 0 0 0-6.4-105.6 83.84 83.84 0 1 1 134.4-103.68 262.4 262.4 0 0 1 17.28 296.96L581.278 896a259.84 259.84 0 0 1-163.84 120.32 263.68 263.68 0 0 1-59.52 7.68z" p-id="6175"></path></svg>';
  179. html += "</button>";
  180. html += "</span> ";
  181. html += "</div>";
  182. html += "</div>";
  183. }
  184. html += "<input id='file_count' type='hidden' value='" + file_list.length + "'/>";
  185. $("#userfilelist").html(html);
  186. } catch (e) {
  187. console.error(e.message);
  188. }
  189. }
  190. );
  191. }
  192. function showUserFilaList() {
  193. file_list_refresh();
  194. }
  195. function title_change(id, title) {
  196. let newTitle = prompt("新的标题", title);
  197. if (newTitle) {
  198. _doc_info_title_change(id, newTitle, function (data, status) {
  199. let result = JSON.parse(data);
  200. if (result.error == false) {
  201. $("#title_" + id).text(newTitle);
  202. } else {
  203. alert(result.message);
  204. }
  205. });
  206. }
  207. }
  208. function share_link_copy_to_clipboard(id) {
  209. copy_to_clipboard("https://www.wikipali.org/app/studio/project.php?op=open&doc_id=" + id);
  210. }
  211. function mydoc_file_select(doSelect) {
  212. if (doSelect) {
  213. $("#file_tools").show();
  214. $("#file_filter").hide();
  215. $(".file_select_checkbox").show();
  216. $(".file_select_checkbox").css("display", "inline-block");
  217. if ($("#id_index_status").val() == "recycle") {
  218. $("#button_group_recycle").show();
  219. $("#button_group_nomal").hide();
  220. } else {
  221. $("#button_group_recycle").hide();
  222. $("#button_group_nomal").show();
  223. }
  224. } else {
  225. $("#file_tools").hide();
  226. $("#file_filter").show();
  227. $(".file_select_checkbox").hide();
  228. }
  229. }
  230. function file_del() {
  231. var file_list = new Array();
  232. var file_count = $("#file_count").val();
  233. for (var i = 0; i < file_count; i++) {
  234. if (document.getElementById("file_check_" + i).checked) {
  235. file_list.push($("#file_id_" + i).val());
  236. }
  237. }
  238. if (file_list.length > 0) {
  239. $.post(
  240. "file_index.php",
  241. {
  242. op: "delete",
  243. file: file_list.join(),
  244. },
  245. function (data, status) {
  246. ntf_show(data);
  247. file_list_refresh();
  248. }
  249. );
  250. }
  251. }
  252. //彻底删除
  253. function file_remove() {
  254. var file_list = new Array();
  255. var file_count = $("#file_count").val();
  256. for (var i = 0; i < file_count; i++) {
  257. if (document.getElementById("file_check_" + i).checked) {
  258. file_list.push($("#file_id_" + i).val());
  259. }
  260. }
  261. if (file_list.length > 0) {
  262. $.post(
  263. "file_index.php",
  264. {
  265. op: "remove",
  266. file: file_list.join(),
  267. },
  268. function (data, status) {
  269. ntf_show(data);
  270. file_list_refresh();
  271. }
  272. );
  273. }
  274. }
  275. //从回收站中恢复
  276. function file_restore() {
  277. var file_list = new Array();
  278. var file_count = $("#file_count").val();
  279. for (var i = 0; i < file_count; i++) {
  280. if (document.getElementById("file_check_" + i).checked) {
  281. file_list.push($("#file_id_" + i).val());
  282. }
  283. }
  284. if (file_list.length > 0) {
  285. $.post(
  286. "file_index.php",
  287. {
  288. op: "restore",
  289. file: file_list.join(),
  290. },
  291. function (data, status) {
  292. ntf_show(data);
  293. file_list_refresh();
  294. }
  295. );
  296. }
  297. }
  298. function file_share(isShare) {
  299. var file_list = new Array();
  300. var file_count = $("#file_count").val();
  301. for (var i = 0; i < file_count; i++) {
  302. if (document.getElementById("file_check_" + i).checked) {
  303. file_list.push($("#file_id_" + i).val());
  304. }
  305. }
  306. if (file_list.length > 0) {
  307. if (isShare) {
  308. var share = 1;
  309. } else {
  310. var share = 0;
  311. }
  312. $.post(
  313. "file_index.php",
  314. {
  315. op: "share",
  316. share: share,
  317. file: file_list.join(),
  318. },
  319. function (data, status) {
  320. alert(data);
  321. //mydoc_file_select(false);
  322. file_list_refresh();
  323. }
  324. );
  325. }
  326. }
  327. function file_show_coop_win(doc_id) {
  328. let xFileHead = document.getElementById("coop_show_" + doc_id);
  329. let xCoopWin = document.getElementById("rs_doc_coop_win");
  330. xFileHead.appendChild(xCoopWin);
  331. coop_init(doc_id, "rs_doc_coop_win_inner");
  332. coop_list();
  333. }
  334. function file_coop_win_close() {
  335. let xShell = document.getElementById("rs_doc_coop_shell");
  336. let xCoopWin = document.getElementById("rs_doc_coop_win");
  337. xShell.appendChild(xCoopWin);
  338. }