my_article.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. html += '<div class="" style="padding:5px;">';
  93. html += '<div style="max-width:2em;flex:1;"></div>';
  94. html += "<input type='hidden' name='id' value='" + result.id + "'/>";
  95. html +=
  96. "<input type='hidden' name='tag' value='" + result.tag + "'/>";
  97. html +=
  98. "<input type='hidden' name='summary' value='" +
  99. result.summary +
  100. "'/>";
  101. html += "<input type='hidden' name='id' value='" + result.id + "'/>";
  102. html +=
  103. "<input type='hidden' name='status' value='" +
  104. result.status +
  105. "'/>";
  106. html += "<button onclick='article_preview()'>Preview</button>";
  107. html += "<input type='checkbox' name='import' />Import Data";
  108. html += "</div>";
  109. html += "<div style='display:flex;'>";
  110. html += "<div style='flex:4;'>";
  111. html +=
  112. "<textarea id='article_content' name='content' style='height:500px;'>" +
  113. result.content +
  114. "</textarea>";
  115. html += "</div>";
  116. html += "<div id='preview_div'>";
  117. html += "<div id='preview_inner' ></div>";
  118. html += "</div>";
  119. html += "</div>";
  120. $("#article_list").html(html);
  121. $("#aritcle_status").html(render_status(result.status));
  122. let html_title =
  123. "<input type='input' name='title' value='" + result.title + "' />";
  124. $("#article_title").html(html_title);
  125. $("#preview_inner").html(note_init(result.content));
  126. note_refresh_new();
  127. } catch (e) {
  128. console.error(e);
  129. }
  130. } else {
  131. console.error("ajex error");
  132. }
  133. }
  134. );
  135. }
  136. function article_preview() {
  137. $("#preview_inner").html(note_init($("#article_content").val()));
  138. note_refresh_new();
  139. }
  140. function my_article_save() {
  141. $.ajax({
  142. //几个参数需要注意一下
  143. type: "POST", //方法类型
  144. dataType: "json", //预期服务器返回的数据类型
  145. url: "../article/my_article_post.php", //url
  146. data: $("#article_edit").serialize(),
  147. success: function (result) {
  148. console.log(result); //打印服务端返回的数据(调试用)
  149. if (result.status == 0) {
  150. alert("保存成功");
  151. } else {
  152. alert("error:" + result.message);
  153. }
  154. },
  155. error: function (data, status) {
  156. alert("异常!" + data.responseText);
  157. switch (status) {
  158. case "timeout":
  159. break;
  160. case "error":
  161. break;
  162. case "notmodified":
  163. break;
  164. case "parsererror":
  165. break;
  166. default:
  167. break;
  168. }
  169. },
  170. });
  171. }
  172. function course_validate_required(field, alerttxt) {
  173. with (field) {
  174. if (value == null || value == "") {
  175. alert(alerttxt);
  176. return false;
  177. } else {
  178. return true;
  179. }
  180. }
  181. }
  182. function course_validate_form(thisform) {
  183. with (thisform) {
  184. if (course_validate_required(title, "Title must be filled out!") == false) {
  185. title.focus();
  186. return false;
  187. }
  188. }
  189. }