my_article.js 8.5 KB

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