my_article.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 style='display:flex;'>";
  94. html += "<div style='flex:4;'>";
  95. html += '<div class="" style="padding:5px;">';
  96. html += '<div style="max-width:2em;flex:1;"></div>';
  97. html += "<input type='hidden' name='id' value='" + result.id + "'/>";
  98. html +=
  99. "<input type='hidden' name='tag' value='" + result.tag + "'/>";
  100. html +=
  101. "<textarea name='summary' >" + result.summary + "</textarea>";
  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 id='channal_selector' form_name='channal'></div>";
  110. html +=
  111. '<div> <input id="article_lang_select" type="input" onchange="article_lang_change()" title="type language name/code" code="' +
  112. result.lang +
  113. '" value="' +
  114. result.lang +
  115. '" > <input id="article_lang" type="hidden" name="lang" value=""></div>';
  116. html += "</div>";
  117. html += "</div>";
  118. html +=
  119. "<textarea id='article_content' name='content' style='height:500px;'>" +
  120. result.content +
  121. "</textarea>";
  122. html += "</div>";
  123. html += "<div id='preview_div'>";
  124. html += "<div id='preview_inner' ></div>";
  125. html += "</div>";
  126. html += "</div>";
  127. $("#article_list").html(html);
  128. channal_select_init("channal_selector");
  129. tran_lang_select_init("article_lang_select");
  130. $("#aritcle_status").html(render_status(result.status));
  131. let html_title =
  132. "<input id='input_article_title' type='input' name='title' value='" +
  133. result.title +
  134. "' />";
  135. $("#article_title").html(html_title);
  136. $("#preview_inner").html(note_init(result.content));
  137. note_refresh_new();
  138. add_to_collect_dlg_init();
  139. } catch (e) {
  140. console.error(e);
  141. }
  142. } else {
  143. console.error("ajex error");
  144. }
  145. }
  146. );
  147. }
  148. function article_lang_change() {
  149. let lang = $("#article_lang_select").val();
  150. if (lang.split("-").length == 3) {
  151. $("#article_lang").val(lang.split("-")[2]);
  152. } else {
  153. $("#article_lang").val(lang);
  154. }
  155. }
  156. function article_preview() {
  157. $("#preview_inner").html(note_init($("#article_content").val()));
  158. note_refresh_new();
  159. }
  160. function my_article_save() {
  161. $.ajax({
  162. type: "POST", //方法类型
  163. dataType: "json", //预期服务器返回的数据类型
  164. url: "../article/my_article_post.php", //url
  165. data: $("#article_edit").serialize(),
  166. success: function (result) {
  167. console.log(result); //打印服务端返回的数据(调试用)
  168. if (result.status == 0) {
  169. alert("保存成功");
  170. } else {
  171. alert("error:" + result.message);
  172. }
  173. },
  174. error: function (data, status) {
  175. alert("异常!" + data.responseText);
  176. switch (status) {
  177. case "timeout":
  178. break;
  179. case "error":
  180. break;
  181. case "notmodified":
  182. break;
  183. case "parsererror":
  184. break;
  185. default:
  186. break;
  187. }
  188. },
  189. });
  190. }
  191. function course_validate_required(field, alerttxt) {
  192. with (field) {
  193. if (value == null || value == "") {
  194. alert(alerttxt);
  195. return false;
  196. } else {
  197. return true;
  198. }
  199. }
  200. }
  201. function course_validate_form(thisform) {
  202. with (thisform) {
  203. if (course_validate_required(title, "Title must be filled out!") == false) {
  204. title.focus();
  205. return false;
  206. }
  207. }
  208. }