my_article.js 5.7 KB

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