my_article.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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;'>" + gLocal.gui.copy_link + "</div>";
  30. html +=
  31. "<div style='flex:1;'><a href='../article/my_article_edit.php?id=" +
  32. iterator.id +
  33. "'>" +
  34. gLocal.gui.edit +
  35. "</a></div>";
  36. html +=
  37. "<div style='flex:1;'><a href='../article/?id=" +
  38. iterator.id +
  39. "' target='_blank'>" +
  40. gLocal.gui.preview +
  41. "</a></div>";
  42. html += "<div style='flex:1;'>15</div>";
  43. html += "</div>";
  44. }
  45. $("#article_list").html(html);
  46. } catch (e) {
  47. console.error(e);
  48. }
  49. } else {
  50. console.error("ajex error");
  51. }
  52. }
  53. );
  54. }
  55. function render_status(status) {
  56. status = parseInt(status);
  57. let html = "";
  58. let objStatus = [
  59. {
  60. id: 1,
  61. name:
  62. "<svg class='icon'><use xlink:href='../studio/svg/icon.svg#ic_lock'></use></svg>" +
  63. gLocal.gui.private,
  64. tip: gLocal.gui.private_note,
  65. },
  66. {
  67. id: 2,
  68. name:
  69. "<svg class='icon'><use xlink:href='../studio/svg/icon.svg#eye_disable'></use></svg>" +
  70. gLocal.gui.unlisted,
  71. tip: gLocal.gui.unlisted_note,
  72. },
  73. {
  74. id: 3,
  75. name:
  76. "<svg class='icon'><use xlink:href='../studio/svg/icon.svg#eye_enable'></use></svg>" +
  77. gLocal.gui.public,
  78. tip: gLocal.gui.public_note,
  79. },
  80. ];
  81. html +=
  82. "<span style='flex:3;margin:auto;'>" +
  83. gLocal.gui.privacy +
  84. '</span><div class="case_dropdown" style="flex:7;">';
  85. html += '<input type="hidden" name="status" value ="' + status + '" />';
  86. for (const iterator of objStatus) {
  87. if (iterator.id == status) {
  88. html += "<div >" + iterator.name + "</div>";
  89. }
  90. }
  91. html +=
  92. '<div id="privacy_list" class="case_dropdown-content" style="background-color: var(--detail-color); color: var(--btn-color);">';
  93. for (const iterator of objStatus) {
  94. let active = "";
  95. if (iterator.id == status) {
  96. active = "active";
  97. }
  98. html += "<a class='" + active + "' onclick='setStatus(this)'>";
  99. html += "<div style='font-size:110%'>" + iterator.name + "</div>";
  100. html += "<div style='font-size:80%'>" + iterator.tip + "</div>";
  101. html += "</a>";
  102. }
  103. html += "</div></div>";
  104. return html;
  105. }
  106. function setStatus(obj) {}
  107. function my_article_edit(id) {
  108. $.get(
  109. "../article/get.php",
  110. {
  111. id: id,
  112. setting: "",
  113. },
  114. function (data, status) {
  115. if (status == "success") {
  116. try {
  117. let html = "";
  118. let result = JSON.parse(data);
  119. $("#article_collect").attr("a_id", result.id);
  120. html += "<div style='display:flex;'>";
  121. html += "<div style='flex:4;'>";
  122. html += '<div class="" style="padding:5px;">';
  123. html += '<div style="max-width:2em;flex:1;"></div>';
  124. html += "<input type='hidden' name='id' value='" + result.id + "'/>";
  125. html +=
  126. "<input type='hidden' name='tag' value='" + result.tag + "'/>";
  127. html +=
  128. "<textarea name='summary' >" + result.summary + "</textarea>";
  129. html +=
  130. "<input type='hidden' name='status' value='" +
  131. result.status +
  132. "'/>";
  133. html +=
  134. "<input type='checkbox' name='import' />" +
  135. gLocal.gui.import +
  136. gLocal.gui.text;
  137. html += "<div>";
  138. html += "<div style='display:flex;'>";
  139. html +=
  140. "<span style='flex:3;margin:auto;'>" + gLocal.gui.title + "</span>";
  141. html += '<span id="article_title" style="flex:7;"></span></div>';
  142. html +=
  143. "<div id='channal_selector' form_name='channal' style='display:flex;'></div>";
  144. html +=
  145. "<div id='aritcle_status' style='display: flex; width: 100 %;'></div>";
  146. html +=
  147. '<div style="display:flex;width:100%;" ><span style="flex:3;margin: auto;">' +
  148. gLocal.gui.language_select +
  149. '</span> <input id="article_lang_select" style="flex:7;" type="input" onchange="article_lang_change()" placeholder="' +
  150. gLocal.gui.input +
  151. " & " +
  152. gLocal.gui.language_select +
  153. "," +
  154. gLocal.gui.example +
  155. ':Engilish" code="' +
  156. result.lang +
  157. '" value="' +
  158. result.lang +
  159. '" > <input id="article_lang" type="hidden" name="lang" value=""></div>';
  160. html += "</div>";
  161. html += "</div>";
  162. html +=
  163. "<textarea id='article_content' name='content' style='height:500px;max-height: 40vh;'>" +
  164. result.content +
  165. "</textarea>";
  166. html += "</div>";
  167. html += "<div id='preview_div'>";
  168. html += "<div id='preview_inner' ></div>";
  169. html += "</div>";
  170. html += "</div>";
  171. $("#article_list").html(html);
  172. channal_select_init("channal_selector");
  173. tran_lang_select_init("article_lang_select");
  174. $("#aritcle_status").html(render_status(result.status));
  175. let html_title =
  176. "<input id='input_article_title' type='input' name='title' value='" +
  177. result.title +
  178. "' />";
  179. $("#article_title").html(html_title);
  180. $("#preview_inner").html(note_init(result.content));
  181. note_refresh_new();
  182. add_to_collect_dlg_init();
  183. } catch (e) {
  184. console.error(e);
  185. }
  186. } else {
  187. console.error("ajex error");
  188. }
  189. }
  190. );
  191. }
  192. function article_lang_change() {
  193. let lang = $("#article_lang_select").val();
  194. if (lang.split("-").length == 3) {
  195. $("#article_lang").val(lang.split("-")[2]);
  196. } else {
  197. $("#article_lang").val(lang);
  198. }
  199. }
  200. function article_preview() {
  201. $("#preview_inner").html(note_init($("#article_content").val()));
  202. note_refresh_new();
  203. }
  204. function my_article_save() {
  205. $.ajax({
  206. type: "POST", //方法类型
  207. dataType: "json", //预期服务器返回的数据类型
  208. url: "../article/my_article_post.php", //url
  209. data: $("#article_edit").serialize(),
  210. success: function (result) {
  211. console.log(result); //打印服务端返回的数据(调试用)
  212. if (result.status == 0) {
  213. alert(gLocal.gui.saved + gLocal.gui.successful);
  214. } else {
  215. alert("error:" + result.message);
  216. }
  217. },
  218. error: function (data, status) {
  219. alert("异常!" + data.responseText);
  220. switch (status) {
  221. case "timeout":
  222. break;
  223. case "error":
  224. break;
  225. case "notmodified":
  226. break;
  227. case "parsererror":
  228. break;
  229. default:
  230. break;
  231. }
  232. },
  233. });
  234. }
  235. function course_validate_required(field, alerttxt) {
  236. with (field) {
  237. if (value == null || value == "") {
  238. alert(alerttxt);
  239. return false;
  240. } else {
  241. return true;
  242. }
  243. }
  244. }
  245. function course_validate_form(thisform) {
  246. with (thisform) {
  247. if (
  248. course_validate_required(title, gLocal.gui.title_necessary + "!") ==
  249. false
  250. ) {
  251. title.focus();
  252. return false;
  253. }
  254. }
  255. }