my_article.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. var _display = "para";
  2. function my_article_init() {
  3. my_article_list();
  4. article_add_dlg_init("article_add_div");
  5. }
  6. function my_article_list() {
  7. $.get(
  8. "../article/list.php",
  9. {
  10. userid: getCookie("userid"),
  11. setting: "",
  12. },
  13. function (data, status) {
  14. if (status == "success") {
  15. try {
  16. let html = "";
  17. let result = JSON.parse(data);
  18. let key = 1;
  19. for (const iterator of result) {
  20. html += '<div class="file_list_row" style="padding:5px;">';
  21. html +=
  22. '<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 +=
  26. "<div style='flex:2;'>" +
  27. render_status(iterator.status) +
  28. "</div>";
  29. html += "<div style='flex:1;'>Copy Link</div>";
  30. html +=
  31. "<div style='flex:1;'><a href='../article/my_article_edit.php?id=" +
  32. iterator.id +
  33. "'>Edit</a></div>";
  34. html +=
  35. "<div style='flex:1;'><a href='../article/?id=" +
  36. iterator.id +
  37. "' target='_blank'>Preview</a></div>";
  38. html += "<div style='flex:1;'>15</div>";
  39. html += "</div>";
  40. }
  41. $("#article_list").html(html);
  42. } catch (e) {
  43. console.error(e);
  44. }
  45. } else {
  46. console.error("ajex error");
  47. }
  48. }
  49. );
  50. }
  51. function render_status(status) {
  52. status = parseInt(status);
  53. let html = "";
  54. let objStatus = [
  55. { id: 1, name: "私有", tip: "仅自己可见" },
  56. { id: 2, name: "不公开列出", tip: "不能被搜索到,只能通过链接访问" },
  57. { id: 3, name: "公开", tip: "所有人均可看到" },
  58. ];
  59. html += '<div class="case_dropdown">';
  60. html += '<input type="hidden" name="status" value ="' + status + '" />';
  61. for (const iterator of objStatus) {
  62. if (iterator.id == status) {
  63. html += "<div >" + iterator.name + "</div>";
  64. }
  65. }
  66. html += '<div class="case_dropdown-content">';
  67. for (const iterator of objStatus) {
  68. let active = "";
  69. if (iterator.id == status) {
  70. active = "active";
  71. }
  72. html += "<a class='" + active + "' onclick='setStatus(this)'>";
  73. html += "<div style='font-size:110%'>" + iterator.name + "</div>";
  74. html += "<div style='font-size:80%'>" + iterator.tip + "</div>";
  75. html += "</a>";
  76. }
  77. html += "</div></div>";
  78. return html;
  79. }
  80. function my_article_edit(id) {
  81. $.get(
  82. "../article/get.php",
  83. {
  84. id: id,
  85. setting: "",
  86. },
  87. function (data, status) {
  88. if (status == "success") {
  89. try {
  90. let html = "";
  91. let result = JSON.parse(data);
  92. $("#article_collect").attr("a_id", result.id);
  93. html += '<div class="" style="padding:5px;">';
  94. html += '<div style="max-width:2em;flex:1;"></div>';
  95. html += "<input type='hidden' name='id' value='" + result.id + "'/>";
  96. html +=
  97. "<input type='hidden' name='tag' value='" + result.tag + "'/>";
  98. html +=
  99. "<input type='hidden' name='summary' value='" +
  100. result.summary +
  101. "'/>";
  102. html += "<input type='hidden' name='id' value='" + result.id + "'/>";
  103. html +=
  104. "<input type='hidden' name='status' value='" +
  105. result.status +
  106. "'/>";
  107. html += "<button onclick='article_preview()'>Preview</button>";
  108. html += "<input type='checkbox' name='import' />Import Data";
  109. html += "</div>";
  110. html += "<div style='display:flex;'>";
  111. html += "<div style='flex:4;'>";
  112. html +=
  113. "<textarea id='article_content' name='content' style='height:500px;'>" +
  114. result.content +
  115. "</textarea>";
  116. html += "</div>";
  117. html += "<div id='preview_div'>";
  118. html += "<div id='preview_inner' ></div>";
  119. html += "</div>";
  120. html += "</div>";
  121. $("#article_list").html(html);
  122. $("#aritcle_status").html(render_status(result.status));
  123. let html_title =
  124. "<input id='input_article_title' type='input' name='title' value='" +
  125. result.title +
  126. "' />";
  127. $("#article_title").html(html_title);
  128. $("#preview_inner").html(note_init(result.content));
  129. note_refresh_new();
  130. add_to_collect_dlg_init();
  131. } catch (e) {
  132. console.error(e);
  133. }
  134. } else {
  135. console.error("ajex error");
  136. }
  137. }
  138. );
  139. }
  140. function article_preview() {
  141. $("#preview_inner").html(note_init($("#article_content").val()));
  142. note_refresh_new();
  143. }
  144. function my_article_save() {
  145. $.ajax({
  146. //几个参数需要注意一下
  147. type: "POST", //方法类型
  148. dataType: "json", //预期服务器返回的数据类型
  149. url: "../article/my_article_post.php", //url
  150. data: $("#article_edit").serialize(),
  151. success: function (result) {
  152. console.log(result); //打印服务端返回的数据(调试用)
  153. if (result.status == 0) {
  154. alert("保存成功");
  155. } else {
  156. alert("error:" + result.message);
  157. }
  158. },
  159. error: function (data, status) {
  160. alert("异常!" + data.responseText);
  161. switch (status) {
  162. case "timeout":
  163. break;
  164. case "error":
  165. break;
  166. case "notmodified":
  167. break;
  168. case "parsererror":
  169. break;
  170. default:
  171. break;
  172. }
  173. },
  174. });
  175. }
  176. function course_validate_required(field, alerttxt) {
  177. with (field) {
  178. if (value == null || value == "") {
  179. alert(alerttxt);
  180. return false;
  181. } else {
  182. return true;
  183. }
  184. }
  185. }
  186. function course_validate_form(thisform) {
  187. with (thisform) {
  188. if (course_validate_required(title, "Title must be filled out!") == false) {
  189. title.focus();
  190. return false;
  191. }
  192. }
  193. }