my_article.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. "<input type='hidden' name='status' value='" +
  129. result.status +
  130. "'/>";
  131. html +=
  132. "<input type='checkbox' name='import' />" +
  133. gLocal.gui.import +
  134. gLocal.gui.text;
  135. html += "<div>";
  136. //html += "<div id='article_collect' vui='collect-dlg' ></div>"
  137. html += "<div style='display:flex;'>";
  138. html +=
  139. "<span style='flex:3;margin:auto;'>" + gLocal.gui.title + "</span>";
  140. html += '<span id="article_title" style="flex:7;"></span></div>';
  141. html +=
  142. "<div id='channal_selector' form_name='channal' style='display:flex;'></div>";
  143. html +=
  144. "<div id='aritcle_status' style='display: flex; width: 100 %;'></div>";
  145. html +=
  146. '<div style="display:flex;width:100%;" ><span style="flex:3;margin: auto;">' +
  147. gLocal.gui.language_select +
  148. '</span> <input id="article_lang_select" style="flex:7;" type="input" onchange="article_lang_change()" placeholder="' +
  149. gLocal.gui.input +
  150. " & " +
  151. gLocal.gui.language_select +
  152. "," +
  153. gLocal.gui.example +
  154. ':Engilish" code="' +
  155. result.lang +
  156. '" value="' +
  157. result.lang +
  158. '" > <input id="article_lang" type="hidden" name="lang" value=""></div>';
  159. html += "<div style='display:flex;'>";
  160. html += "<span style='flex:3;margin:auto;'>" + gLocal.gui.introduction + "</span>"
  161. html +=
  162. "<textarea style='flex:7;' name='summary' >" + result.summary + "</textarea></div>";
  163. html += "</div>";
  164. html += "</div>";
  165. html +=
  166. "<textarea id='article_content' name='content' style='height:500px;max-height: 40vh;'>" +
  167. result.content +
  168. "</textarea>";
  169. html += "</div>";
  170. html += "<div id='preview_div'>";
  171. html += "<div id='preview_inner' ></div>";
  172. html += "</div>";
  173. html += "</div>";
  174. $("#article_list").html(html);
  175. channal_select_init("channal_selector");
  176. tran_lang_select_init("article_lang_select");
  177. $("#aritcle_status").html(render_status(result.status));
  178. let html_title =
  179. "<input id='input_article_title' type='input' name='title' value='" +
  180. result.title +
  181. "' />";
  182. $("#article_title").html(html_title);
  183. $("#preview_inner").html(note_init(result.content));
  184. note_refresh_new();
  185. add_to_collect_dlg_init();
  186. } catch (e) {
  187. console.error(e);
  188. }
  189. } else {
  190. console.error("ajex error");
  191. }
  192. }
  193. );
  194. }
  195. function article_lang_change() {
  196. let lang = $("#article_lang_select").val();
  197. if (lang.split("-").length == 3) {
  198. $("#article_lang").val(lang.split("-")[2]);
  199. } else {
  200. $("#article_lang").val(lang);
  201. }
  202. }
  203. function article_preview() {
  204. $("#preview_inner").html(note_init($("#article_content").val()));
  205. note_refresh_new();
  206. }
  207. function my_article_save() {
  208. $.ajax({
  209. type: "POST", //方法类型
  210. dataType: "json", //预期服务器返回的数据类型
  211. url: "../article/my_article_post.php", //url
  212. data: $("#article_edit").serialize(),
  213. success: function (result) {
  214. console.log(result); //打印服务端返回的数据(调试用)
  215. if (result.status == 0) {
  216. alert(gLocal.gui.saved + gLocal.gui.successful);
  217. } else {
  218. alert("error:" + result.message);
  219. }
  220. },
  221. error: function (data, status) {
  222. alert("异常!" + data.responseText);
  223. switch (status) {
  224. case "timeout":
  225. break;
  226. case "error":
  227. break;
  228. case "notmodified":
  229. break;
  230. case "parsererror":
  231. break;
  232. default:
  233. break;
  234. }
  235. },
  236. });
  237. }
  238. function course_validate_required(field, alerttxt) {
  239. with (field) {
  240. if (value == null || value == "") {
  241. alert(alerttxt);
  242. return false;
  243. } else {
  244. return true;
  245. }
  246. }
  247. }
  248. function course_validate_form(thisform) {
  249. with (thisform) {
  250. if (
  251. course_validate_required(title, gLocal.gui.title_necessary + "!") ==
  252. false
  253. ) {
  254. title.focus();
  255. return false;
  256. }
  257. }
  258. }