my_article.js 8.9 KB

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