my_collect.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. var share_win;
  2. function my_collect_init() {
  3. my_collect_list();
  4. share_win = iframe_win_init({ container: "share_win", name: "share", width: "500px" });
  5. collect_add_dlg_init("collect_add_div");
  6. }
  7. function my_collect_list() {
  8. $.get(
  9. "../article/collect_list.php",
  10. {
  11. userid: getCookie("userid"),
  12. setting: "",
  13. },
  14. function (data, status) {
  15. if (status == "success") {
  16. try {
  17. let html = "";
  18. let result = JSON.parse(data);
  19. let key = 1;
  20. for (const iterator of result) {
  21. html += '<div class="file_list_row" style="padding:5px;">';
  22. html += '<div style="max-width:2em;flex:1;"><input type="checkbox" /></div>';
  23. html += "<div style='flex:1;'>" + key++ + "</div>";
  24. html += "<div style='flex:2;'>" + iterator.title + "</div>";
  25. html += "<div style='flex:2;'>" + render_status(iterator.status) + "</div>";
  26. html += "<div style='flex:1;'>" + gLocal.gui.copy_link + "</div>";
  27. html +=
  28. "<div style='flex:1;'><a href='../article/my_collect_edit.php?id=" +
  29. iterator.id +
  30. "'>" +
  31. gLocal.gui.edit +
  32. "</a></div>";
  33. html +=
  34. "<div style='flex:1;'><a href='../article/?collect=" +
  35. iterator.id +
  36. "' target='_blank'>" +
  37. gLocal.gui.preview +
  38. "</a></div>";
  39. html += "<div style='flex:1;'>";
  40. html += "<a onclick=\"collection_share('" + iterator.id + "')\">share</a>";
  41. html += "</div>";
  42. html += "</div>";
  43. }
  44. $("#article_list").html(html);
  45. } catch (e) {
  46. console.error(e);
  47. }
  48. } else {
  49. console.error("ajex error");
  50. }
  51. }
  52. );
  53. }
  54. var _arrArticleList;
  55. var _arrArticleOrder = new Array();
  56. function my_collect_edit(id) {
  57. $.get(
  58. "../article/collect_get.php",
  59. {
  60. id: id,
  61. setting: "",
  62. },
  63. function (data, status) {
  64. if (status == "success") {
  65. try {
  66. let html = "";
  67. let result = JSON.parse(data);
  68. $("#article_collect").attr("a_id", result.id);
  69. html += '<div class="" style="padding:5px;">';
  70. html += '<div style="max-width:2em;flex:1;"></div>';
  71. html += "<input type='hidden' name='id' value='" + result.id + "'/>";
  72. html += "<div style='display:flex;'>";
  73. html += "<div style='flex:2;'>" + gLocal.gui.title + "</div>";
  74. html += "<div style='flex:8;'>";
  75. html += "<input type='input' name='title' value='" + result.title + "'/>";
  76. html += "</div></div>";
  77. html += "<div style='display:flex;'>";
  78. html += "<div style='flex:2;'>" + gLocal.gui.sub_title + "</div>";
  79. html += "<div style='flex:8;'>";
  80. html += "<input type='input' name='subtitle' value='" + result.subtitle + "'/>";
  81. html += "</div></div>";
  82. html += "<div style='display:flex;'>";
  83. html += "<div style='flex:2;'>" + gLocal.gui.summary + "</div>";
  84. html += "<div style='flex:8;'>";
  85. html += "<input type='input' name='summary' value='" + result.summary + "'/>";
  86. html += "</div></div>";
  87. html += "<div style='display:flex;'>";
  88. html += "<div style='flex:2;'>" + gLocal.gui.status + "</div>";
  89. html += "<div style='flex:8;'>";
  90. html += render_status(result.status, false);
  91. html += "</div></div>";
  92. html += "<div style='display:flex;'>";
  93. html += "<div style='flex:2;'>" + gLocal.gui.language + "</div>";
  94. html += "<div style='flex:8;'>";
  95. html += "<input type='input' name='lang' value='" + result.lang + "'/>";
  96. html += "</div></div>";
  97. html +=
  98. "<input id='form_article_list' type='hidden' name='article_list' value='" +
  99. result.article_list +
  100. "'/>";
  101. html += "</div>";
  102. html += "<div style='display:flex;'>";
  103. html += "<div style='flex:4;'>";
  104. _arrArticleList = JSON.parse(result.article_list);
  105. html += "<ul id='ul_article_list'>";
  106. for (let index = 0; index < _arrArticleList.length; index++) {
  107. const element = _arrArticleList[index];
  108. html += my_collect_render_article(index, element);
  109. _arrArticleOrder.push(index);
  110. }
  111. html += "</ul>";
  112. html += "</div>";
  113. html += "<div id='preview_div'>";
  114. html += "<div id='preview_inner' ></div>";
  115. html += "</div>";
  116. html += "</div>";
  117. $("#article_list").html(html);
  118. $("#collection_title").html(result.title);
  119. $("#ul_article_list").sortable({
  120. update: function (event, ui) {
  121. let sortedIDs = $("#ul_article_list").sortable("toArray");
  122. _arrArticleOrder = new Array();
  123. for (const iSorted of sortedIDs) {
  124. let newindex = parseInt($("#" + iSorted).attr("article_index"));
  125. _arrArticleOrder.push(_arrArticleList[newindex]);
  126. }
  127. $("#form_article_list").val(JSON.stringify(_arrArticleOrder));
  128. },
  129. });
  130. } catch (e) {
  131. console.error(e);
  132. }
  133. } else {
  134. console.error("ajex error");
  135. }
  136. }
  137. );
  138. }
  139. function my_collect_render_article(index, article) {
  140. let html = "";
  141. html += "<li id='article_item_" + index + "' article_index='" + index + "' class='file_list_row'>";
  142. html += "<span style='flex:1;'>";
  143. html += "<select>";
  144. let selected = "";
  145. for (let i = 1; i < 9; i++) {
  146. if (parseInt(article.level) == i) {
  147. selected = "selected";
  148. } else {
  149. selected = "";
  150. }
  151. html += "<option " + selected + " value='" + i + "' >H " + i + "</option>";
  152. }
  153. html += "</select>";
  154. html += "</span>";
  155. html += "<span style='flex:3;'>";
  156. html += "<a href='../article/my_article_edit.php?id=" + article.article + "'>";
  157. html += article.title;
  158. html += "</a>";
  159. html += "</span>";
  160. html += "<span style='flex:1;' onclick=\"article_preview('" + article.article + "')\">";
  161. html += "Preview";
  162. html += "</span>";
  163. html += "</li>";
  164. return html;
  165. }
  166. function article_preview(id) {
  167. $.get(
  168. "../article/get.php",
  169. {
  170. id: id,
  171. setting: "",
  172. },
  173. function (data, status) {
  174. if (status == "success") {
  175. try {
  176. let html = "";
  177. let result = JSON.parse(data);
  178. $("#preview_inner").html(note_init(result.content));
  179. note_refresh_new();
  180. } catch (e) {
  181. console.error(e.message);
  182. }
  183. }
  184. }
  185. );
  186. }
  187. function my_collect_save() {
  188. $.ajax({
  189. type: "POST", //方法类型
  190. dataType: "json", //预期服务器返回的数据类型
  191. url: "../article/my_collect_post.php", //url
  192. data: $("#collect_edit").serialize(),
  193. success: function (result) {
  194. console.log(result); //打印服务端返回的数据(调试用)
  195. if (result.status == 0) {
  196. alert("保存成功");
  197. } else {
  198. alert("error:" + result.message);
  199. }
  200. },
  201. error: function (data, status) {
  202. alert("异常!" + data.responseText);
  203. switch (status) {
  204. case "timeout":
  205. break;
  206. case "error":
  207. break;
  208. case "notmodified":
  209. break;
  210. case "parsererror":
  211. break;
  212. default:
  213. break;
  214. }
  215. },
  216. });
  217. }
  218. function collection_share(id) {
  219. share_win.show("../share/share.php?id=" + id + "&type=4");
  220. }