index_mydoc.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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. }
  23. else {
  24. var Local_time_string = d.toLocaleTimeString()
  25. }
  26. if (date.toLocaleDateString() == today_date.toLocaleDateString()) {//如果是今天的消息,只显示时间
  27. return (Local_time_string);
  28. }
  29. else if (date.toLocaleDateString().slice(0, 5) == today_date.toLocaleDateString().slice(0, 5)) {//如果是今年但非今天的消息,只显示月日
  30. var date_length = date.toLocaleDateString().length;
  31. return (date.toLocaleDateString().slice(5, date_length));
  32. }
  33. else {//如果不是今年的消息,显示年月日
  34. return (date.toLocaleDateString());
  35. }
  36. }
  37. //显示最近查看列表
  38. function file_list_refresh() {
  39. var d = new Date();
  40. $.get("getfilelist.php",
  41. {
  42. t: d.getTime(),
  43. keyword: my_file_title,
  44. status: $("#id_index_status").val(),
  45. orderby: "accese_time",
  46. order: "DESC",
  47. currLanguage: $("#id_language").val()
  48. },
  49. function (data, status) {
  50. try {
  51. let file_list = JSON.parse(data);
  52. let html = "";
  53. for (x in file_list) {
  54. html += "<div class=\"file_list_row\">";
  55. html += "<div class=\"file_list_col_1\">";
  56. html += "<input id='file_check_" + x + "' type=\"checkbox\" />";
  57. html += "<input id='file_id_" + x + "' value='" + file_list[x].id + "' type=\"hidden\" />";
  58. html += "</div>";
  59. html += "<div class=\"file_list_col_2\">";
  60. if ((file_list[x].parent_id == null || file_list[x].parent_id == "") && parseInt(file_list[x].share) == 1) {
  61. //shared
  62. html += "<span onclick=\"file_show_coop_win('" + file_list[x].id + "')\">";
  63. }
  64. else {
  65. html += "<span>";
  66. }
  67. html += "<svg class='icon' style='margin: 0 5px;'>";
  68. if (file_list[x].parent_id == null || file_list[x].parent_id == "") {
  69. if (parseInt(file_list[x].share) == 1) {
  70. //shared
  71. html += "<use xlink:href=\"./svg/icon.svg#share_to_other\"></use>";
  72. }
  73. else {
  74. //my document
  75. html += "<use xlink:href=\"./svg/icon.svg#ic_person\"></use>";
  76. }
  77. }
  78. else {
  79. //fork
  80. html += "<use xlink:href=\"./svg/icon.svg#other_share_to_me\"></use>";
  81. }
  82. html += "</svg>";
  83. html += "</span>";
  84. html += "<div id='coop_show_" + file_list[x].id + "' style='display:inline;'></div>";
  85. let $link;
  86. if (file_list[x].doc_info && file_list[x].doc_info.length > 1) {
  87. $link = "<a href='editor.php?op=opendb&fileid=" + file_list[x].id + "' target='_blank'>[db]";
  88. }
  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 +='<span class="icon_btn_tip" style="margin-top: 0.7em;margin-left: 2.5em;">'+gLocal.gui.rename+'</span>';
  97. html +="<button id='edit_title' type='button' class='icon_btn' onclick=\"title_change('"+file_list[x].id+"','"+file_list[x].title+"')\" >";
  98. html +=' <svg class="icon">';
  99. html +=' <use xlink:href="./svg/icon.svg#ic_rename"></use>';
  100. html +=' </svg>';
  101. html +='</button>';
  102. html +='</span> ';
  103. html += "</div>";
  104. html += "<div class=\"file_list_col_3\">";
  105. if ((file_list[x].parent_id && file_list[x].parent_id.length > 10) || parseInt(file_list[x].share) == 1) {
  106. html += "<svg class='icon'>";
  107. html += "<use xlink:href=\"./svg/icon.svg#ic_two_person\"></use>";
  108. html += "</svg>";
  109. }
  110. html += "</div>";
  111. html += "<div class=\"file_list_col_4\">";
  112. let d = new Date();
  113. let today_date = d.toLocaleDateString();
  114. d.setTime(file_list[x].accese_time);
  115. let Local_time = "";
  116. Local_time = time_standardize(d);
  117. /*
  118. if(d.getHours()<=9){
  119. Local_time +=":0"+d.getHours();
  120. }
  121. else{
  122. Local_time += ":"+d.getHours();
  123. }
  124. if(d.getMinutes()<=9){
  125. Local_time +=":0"+d.getMinutes();
  126. }
  127. else{
  128. Local_time += ":"+d.getMinutes();
  129. }
  130. let Local_date = d.toLocaleDateString();
  131. if(today_date==Local_date){
  132. html += gLocal.gui.today+Local_time;
  133. }
  134. else{
  135. html += Local_date;
  136. }
  137. */
  138. html += Local_time
  139. html += "</div>";
  140. html += "<div class=\"file_list_col_5\">";
  141. if (file_list[x].file_size < 102) {
  142. $str_size = file_list[x].file_size + "B";
  143. }
  144. else if (file_list[x].file_size < (1024 * 902)) {
  145. $str_size = (file_list[x].file_size / 1024).toFixed(0) + "KB";
  146. }
  147. else {
  148. $str_size = (file_list[x].file_size / (1024 * 1024)).toFixed(1) + "MB";
  149. }
  150. html += $str_size;
  151. if (!(file_list[x].doc_info && file_list[x].doc_info.length > 1)) {
  152. html += "<a href='../doc/pcs2db.php?doc_id=" + file_list[x].id + "' target='_blank'>转数据库格式</a>";
  153. }
  154. html += "</div>";
  155. html+="<div>";
  156. html +='<span class="icon_btn_div hidden_function">';
  157. html +='<span class="icon_btn_tip">'+gLocal.gui.copy_share_link+'</span>';
  158. html +="<button id='edit_title' type='button' class='icon_btn' onclick=\"share_link_copy_to_clipboard('"+file_list[x].id+"')\" >";
  159. //html +=' <svg class="icon">';
  160. //html +=' <use xlink:href="./svg/icon.svg#ic_rename"></use>';
  161. //html +=' </svg>';
  162. html +='<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>';
  163. html +='</button>';
  164. html +='</span> ';
  165. html += "</div>";
  166. html += "</div>";
  167. }
  168. html += "<input id='file_count' type='hidden' value='" + file_list.length + "'/>"
  169. $("#userfilelist").html(html);
  170. }
  171. catch (e) {
  172. console.error(e.message);
  173. }
  174. });
  175. }
  176. function showUserFilaList() {
  177. file_list_refresh();
  178. }
  179. function title_change(id,title){
  180. let newTitle = prompt("新的标题",title);
  181. if(newTitle){
  182. _doc_info_title_change(id,newTitle,function(data,status){
  183. let result = JSON.parse(data);
  184. if(result.error==false){
  185. $("#title_"+id).text(newTitle);
  186. }
  187. else{
  188. alert(result.message);
  189. }
  190. });
  191. }
  192. }
  193. function share_link_copy_to_clipboard(id){
  194. copy_to_clipboard("https://www.wikipali.org/app/studio/project.php?op=open&doc_id="+id)
  195. }
  196. function mydoc_file_select(doSelect) {
  197. if (doSelect) {
  198. $("#file_tools").show();
  199. $("#file_filter").hide();
  200. $(".file_select_checkbox").show();
  201. $(".file_select_checkbox").css("display", "inline-block");
  202. if ($("#id_index_status").val() == "recycle") {
  203. $("#button_group_recycle").show();
  204. $("#button_group_nomal").hide();
  205. }
  206. else {
  207. $("#button_group_recycle").hide();
  208. $("#button_group_nomal").show();
  209. }
  210. }
  211. else {
  212. $("#file_tools").hide();
  213. $("#file_filter").show();
  214. $(".file_select_checkbox").hide();
  215. }
  216. }
  217. function file_del() {
  218. var file_list = new Array();
  219. var file_count = $("#file_count").val();
  220. for (var i = 0; i < file_count; i++) {
  221. if (document.getElementById("file_check_" + i).checked) {
  222. file_list.push($("#file_id_" + i).val());
  223. }
  224. }
  225. if (file_list.length > 0) {
  226. $.post("file_index.php",
  227. {
  228. op: "delete",
  229. file: file_list.join()
  230. },
  231. function (data, status) {
  232. ntf_show(data);
  233. file_list_refresh();
  234. });
  235. }
  236. }
  237. //彻底删除
  238. function file_remove() {
  239. var file_list = new Array();
  240. var file_count = $("#file_count").val();
  241. for (var i = 0; i < file_count; i++) {
  242. if (document.getElementById("file_check_" + i).checked) {
  243. file_list.push($("#file_id_" + i).val());
  244. }
  245. }
  246. if (file_list.length > 0) {
  247. $.post("file_index.php",
  248. {
  249. op: "remove",
  250. file: file_list.join()
  251. },
  252. function (data, status) {
  253. ntf_show(data);
  254. file_list_refresh();
  255. });
  256. }
  257. }
  258. //从回收站中恢复
  259. function file_restore() {
  260. var file_list = new Array();
  261. var file_count = $("#file_count").val();
  262. for (var i = 0; i < file_count; i++) {
  263. if (document.getElementById("file_check_" + i).checked) {
  264. file_list.push($("#file_id_" + i).val());
  265. }
  266. }
  267. if (file_list.length > 0) {
  268. $.post("file_index.php",
  269. {
  270. op: "restore",
  271. file: file_list.join()
  272. },
  273. function (data, status) {
  274. ntf_show(data);
  275. file_list_refresh();
  276. });
  277. }
  278. }
  279. function file_share(isShare) {
  280. var file_list = new Array();
  281. var file_count = $("#file_count").val();
  282. for (var i = 0; i < file_count; i++) {
  283. if (document.getElementById("file_check_" + i).checked) {
  284. file_list.push($("#file_id_" + i).val());
  285. }
  286. }
  287. if (file_list.length > 0) {
  288. if (isShare) {
  289. var share = 1;
  290. }
  291. else {
  292. var share = 0;
  293. }
  294. $.post("file_index.php",
  295. {
  296. op: "share",
  297. share: share,
  298. file: file_list.join()
  299. },
  300. function (data, status) {
  301. alert(data);
  302. //mydoc_file_select(false);
  303. file_list_refresh();
  304. });
  305. }
  306. }
  307. function file_show_coop_win(doc_id) {
  308. let xFileHead = document.getElementById("coop_show_" + doc_id);
  309. let xCoopWin = document.getElementById("rs_doc_coop_win");
  310. xFileHead.appendChild(xCoopWin);
  311. coop_init(doc_id, "rs_doc_coop_win_inner");
  312. coop_list();
  313. }
  314. function file_coop_win_close() {
  315. let xShell = document.getElementById("rs_doc_coop_shell");
  316. let xCoopWin = document.getElementById("rs_doc_coop_win");
  317. xShell.appendChild(xCoopWin);
  318. }