my_article.js 7.7 KB

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