my_article.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. "'>" + gLocal.gui.edit + "</a></div>";
  34. html +=
  35. "<div style='flex:1;'><a href='../article/?id=" +
  36. iterator.id +
  37. "' target='_blank'>" + gLocal.gui.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: "<svg class='icon'><use xlink:href='../studio/svg/icon.svg#ic_lock'></use></svg>" + gLocal.gui.private, tip: gLocal.gui.private_note },
  56. { id: 2, name: "<svg class='icon'><use xlink:href='../studio/svg/icon.svg#eye_disable'></use></svg>" + gLocal.gui.unlisted, tip: gLocal.gui.unlisted_note },
  57. { id: 3, name: "<svg class='icon'><use xlink:href='../studio/svg/icon.svg#eye_enable'></use></svg>" + gLocal.gui.public, tip: gLocal.gui.public_note },
  58. ];
  59. html += "<span style='flex:3;margin:auto;'>" + gLocal.gui.privacy + '</span><div class="case_dropdown" style="flex:7;">';
  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 id="privacy_list" class="case_dropdown-content" style="background-color: var(--detail-color); color: var(--btn-color);">';
  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 += "<input type='checkbox' name='import' />" + gLocal.gui.import + gLocal.gui.text;
  107. html += "<div>";
  108. html += "<div style='display:flex;'>";
  109. html += "<span style='flex:3;margin:auto;'>" + gLocal.gui.title + "</span>"
  110. html += '<span id="article_title" style="flex:7;"></span></div>';
  111. html += "<div id='channal_selector' form_name='channal' style='display:flex;'></div>";
  112. html += "<div id='aritcle_status' style='display: flex; width: 100 %;'></div>";
  113. html +=
  114. '<div style="display:flex;width:100%;" ><span style="flex:3;margin: auto;">' + gLocal.gui.language_select + '</span> <input id="article_lang_select" style="flex:7;" type="input" onchange="article_lang_change()" placeholder="' + gLocal.gui.input + " & " + gLocal.gui.language_select + ',' + gLocal.gui.example + ':Engilish" code="' +
  115. result.lang +
  116. '" value="' +
  117. result.lang +
  118. '" > <input id="article_lang" type="hidden" name="lang" value=""></div>';
  119. html += "</div>";
  120. html += "</div>";
  121. html +=
  122. "<textarea id='article_content' name='content' style='height:500px;max-height: 40vh;'>" +
  123. result.content +
  124. "</textarea>";
  125. html += "</div>";
  126. html += "<div id='preview_div'>";
  127. html += "<div id='preview_inner' ></div>";
  128. html += "</div>";
  129. html += "</div>";
  130. $("#article_list").html(html);
  131. channal_select_init("channal_selector");
  132. tran_lang_select_init("article_lang_select");
  133. $("#aritcle_status").html(render_status(result.status));
  134. let html_title =
  135. "<input id='input_article_title' type='input' name='title' value='" +
  136. result.title +
  137. "' />";
  138. $("#article_title").html(html_title);
  139. $("#preview_inner").html(note_init(result.content));
  140. note_refresh_new();
  141. add_to_collect_dlg_init();
  142. } catch (e) {
  143. console.error(e);
  144. }
  145. } else {
  146. console.error("ajex error");
  147. }
  148. }
  149. );
  150. }
  151. function article_lang_change() {
  152. let lang = $("#article_lang_select").val();
  153. if (lang.split("-").length == 3) {
  154. $("#article_lang").val(lang.split("-")[2]);
  155. } else {
  156. $("#article_lang").val(lang);
  157. }
  158. }
  159. function article_preview() {
  160. $("#preview_inner").html(note_init($("#article_content").val()));
  161. note_refresh_new();
  162. }
  163. function my_article_save() {
  164. $.ajax({
  165. type: "POST", //方法类型
  166. dataType: "json", //预期服务器返回的数据类型
  167. url: "../article/my_article_post.php", //url
  168. data: $("#article_edit").serialize(),
  169. success: function (result) {
  170. console.log(result); //打印服务端返回的数据(调试用)
  171. if (result.status == 0) {
  172. alert(gLocal.gui.saved + gLocal.gui.successful);
  173. } else {
  174. alert("error:" + result.message);
  175. }
  176. },
  177. error: function (data, status) {
  178. alert("异常!" + data.responseText);
  179. switch (status) {
  180. case "timeout":
  181. break;
  182. case "error":
  183. break;
  184. case "notmodified":
  185. break;
  186. case "parsererror":
  187. break;
  188. default:
  189. break;
  190. }
  191. },
  192. });
  193. }
  194. function course_validate_required(field, alerttxt) {
  195. with (field) {
  196. if (value == null || value == "") {
  197. alert(alerttxt);
  198. return false;
  199. } else {
  200. return true;
  201. }
  202. }
  203. }
  204. function course_validate_form(thisform) {
  205. with (thisform) {
  206. if (course_validate_required(title, gLocal.gui.title_necessary + "!") == false) {
  207. title.focus();
  208. return false;
  209. }
  210. }
  211. }