my_article.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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;'>No.</div>";
  25. html += "<div style='flex:4;'>" + gLocal.gui.title + "</div>";
  26. html += "<div style='flex:2;'>" + gLocal.gui.privacy + "</div>";
  27. html += "<div style='flex:1;'>" + gLocal.gui.edit + "</a></div>";
  28. html += "<div style='flex:1;'>" + gLocal.gui.preview + "</a></div>";
  29. html += "<div style='flex:1;'>" + gLocal.gui.copy_link + "</div>";
  30. html += "<div style='flex:1;'>" + gLocal.gui.share_to + "</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:4;'>" + iterator.title + "</div>";
  38. html += "<div style='flex:2;'>" + render_status(iterator.status) + "</div>";
  39. html +=
  40. "<div style='flex:1;'><a href='../article/my_article_edit.php?id=" +
  41. iterator.id +
  42. "' title='" +
  43. gLocal.gui.edit +
  44. "'>";
  45. html += "<button class='icon_btn'>";
  46. html += "<svg class='icon'>";
  47. html += "<use xlink:href='../studio/svg/icon.svg#ic_mode_edit'></use>";
  48. html += "</svg>";
  49. html += "</button>";
  50. html += "</a></div>";
  51. html +=
  52. "<div style='flex:1;'><a href='../article/?id=" +
  53. iterator.id +
  54. "' target='_blank' title='" +
  55. gLocal.gui.preview +
  56. "' >";
  57. html += "<button class='icon_btn'>";
  58. html += "<svg class='icon'>";
  59. html += "<use xlink:href='../studio/svg/icon.svg#preview'></use>";
  60. html += "</svg>";
  61. html += "</button>";
  62. html += "</a></div>";
  63. html += "<div style='flex:1;'>";
  64. html +=
  65. "<button class='icon_btn' onclick=\"copy_to_clipboard('www.wikipali.org/app/article/?id=" +
  66. iterator.id +
  67. "')\" title='" +
  68. gLocal.gui.copy_link +
  69. "'>";
  70. html += "<svg class='icon'>";
  71. html += "<use xlink:href='../studio/svg/icon.svg#copy'></use>";
  72. html += "</svg>";
  73. html += "</button>";
  74. html += "</div>";
  75. html += "<div style='flex:1;'>";
  76. html +=
  77. "<button title='" +
  78. gLocal.gui.share_to +
  79. "' class='icon_btn' onclick=\"article_share('" +
  80. iterator.id +
  81. "')\">";
  82. html += "<svg class='icon'>";
  83. html += "<use xlink:href='../studio/svg/icon.svg#share_to'></use>";
  84. html += "</svg>";
  85. html += "</button>";
  86. html += "</div>";
  87. html += "</div>";
  88. }
  89. $("#article_list").html(html);
  90. } catch (e) {
  91. console.error(e);
  92. }
  93. } else {
  94. console.error("ajex error");
  95. }
  96. }
  97. );
  98. }
  99. function article_share(id) {
  100. share_win.show("../share/share.php?id=" + id + "&type=3");
  101. }
  102. function render_status(status, readonly = true) {
  103. status = parseInt(status);
  104. let html = "";
  105. let objStatus = [
  106. {
  107. id: 10,
  108. icon: "<svg class='icon'><use xlink:href='../studio/svg/icon.svg#ic_lock'></use></svg>",
  109. name: gLocal.gui.private,
  110. tip: gLocal.gui.private_note,
  111. } /*
  112. ,{
  113. id: 20,
  114. icon: "<svg class='icon'><use xlink:href='../studio/svg/icon.svg#eye_disable'></use></svg>",
  115. name: gLocal.gui.unlisted,
  116. tip: gLocal.gui.unlisted_note,
  117. }*/,
  118. {
  119. id: 30,
  120. icon: "<svg class='icon'><use xlink:href='../studio/svg/icon.svg#eye_enable'></use></svg>",
  121. name: gLocal.gui.public,
  122. tip: gLocal.gui.public_note,
  123. },
  124. ];
  125. if (readonly) {
  126. for (const iterator of objStatus) {
  127. if (iterator.id == status) {
  128. return "<div >" + iterator.icon + iterator.name + "</div>";
  129. }
  130. }
  131. } else {
  132. let html = "";
  133. html += "<select name='status'>";
  134. for (const iterator of objStatus) {
  135. html += "<option value='" + iterator.id + "' ";
  136. if (iterator.id == status) {
  137. html += "selected";
  138. }
  139. html += " >";
  140. html += iterator.name;
  141. html += "</option>";
  142. }
  143. html += "</select>";
  144. return html;
  145. }
  146. html += '<div class="case_dropdown" style="flex:7;">';
  147. html += '<input type="hidden" name="status" value ="' + status + '" />';
  148. for (const iterator of objStatus) {
  149. if (iterator.id == status) {
  150. html += "<div >" + iterator.name + "</div>";
  151. }
  152. }
  153. html +=
  154. '<div id="privacy_list" class="case_dropdown-content" style="background-color: var(--detail-color); color: var(--btn-color);">';
  155. for (const iterator of objStatus) {
  156. let active = "";
  157. if (iterator.id == status) {
  158. active = "active";
  159. }
  160. html += "<a class='" + active + "' onclick='setStatus(this)'>";
  161. html += "<div style='font-size:110%'>" + iterator.name + "</div>";
  162. html += "<div style='font-size:80%'>" + iterator.tip + "</div>";
  163. html += "</a>";
  164. }
  165. html += "</div></div>";
  166. return html;
  167. }
  168. function setStatus(obj) {}
  169. function my_article_edit(id) {
  170. $.get(
  171. "../article/get.php",
  172. {
  173. id: id,
  174. setting: "",
  175. },
  176. function (data, status) {
  177. if (status == "success") {
  178. try {
  179. let html = "";
  180. let result = JSON.parse(data);
  181. $("#article_collect").attr("a_id", result.id);
  182. html += "<div style='display:flex;'>";
  183. html += "<div style='flex:4;'>";
  184. html += '<div class="" style="padding:5px;">';
  185. html += '<div style="max-width:2em;flex:1;"></div>';
  186. html += "<input type='hidden' name='id' value='" + result.id + "'/>";
  187. html += "<input type='hidden' name='tag' value='" + result.tag + "'/>";
  188. html += "<input type='hidden' name='status' value='" + result.status + "'/>";
  189. html += "<div style='display:none;'>";
  190. html +=
  191. "<input type='checkbox' name='import' id='import_custom_book' />" +
  192. gLocal.gui.import +
  193. gLocal.gui.text;
  194. html += "</div>";
  195. html += "<div>";
  196. //html += "<div id='article_collect' vui='collect-dlg' ></div>"
  197. html += "<div style='display:flex;'>";
  198. html += "<span style='flex:1;'>" + gLocal.gui.title + "</span>";
  199. html += '<span id="article_title" style="flex:7;"></span>';
  200. html += "</div>";
  201. html += "<div id='channal_selector' form_name='channal' style='display:none;'></div>";
  202. html += "<div style='display:flex;'>";
  203. html += "<span style='flex:1;'>" + gLocal.gui.status + "</span>";
  204. html += '<span id="aritcle_status" style="flex:7;"></span>';
  205. html += "</div>";
  206. html += '<div style="width:100%;" >';
  207. html +=
  208. '<span style="flex:3;margin: auto;">' +
  209. gLocal.gui.language_select +
  210. '</span> <input id="article_lang_select" style="flex:7;width:100%;" type="input" onchange="article_lang_change()" placeholder="' +
  211. gLocal.gui.input +
  212. " & " +
  213. gLocal.gui.language_select +
  214. "," +
  215. gLocal.gui.example +
  216. ':Engilish" code="' +
  217. result.lang +
  218. '" value="' +
  219. result.lang +
  220. '" > <input id="article_lang" type="hidden" name="lang" value=""></div>';
  221. html += "<div style='display:flex;'>";
  222. html += "<span style='flex:1;margin:auto;'>" + gLocal.gui.introduction + "</span>";
  223. html += "<textarea style='flex:7;' name='summary' >" + result.summary + "</textarea></div>";
  224. html += "</div>";
  225. html += "</div>";
  226. html +=
  227. "<textarea id='article_content' name='content' style='height:480px;resize: vertical;'>" +
  228. result.content +
  229. "</textarea>";
  230. html += "</div>";
  231. html += "<div id='preview_div'>";
  232. html += "<div id='preview_inner' class='sent_mode vertical'></div>";
  233. html += "</div>";
  234. html += "</div>";
  235. $("#article_list").html(html);
  236. channal_select_init("channal_selector");
  237. tran_lang_select_init("article_lang_select");
  238. $("#aritcle_status").html(render_status(result.status, false));
  239. let html_title =
  240. "<input id='input_article_title' type='input' name='title' value='" + result.title + "' />";
  241. $("#article_title").html(html_title);
  242. $("#preview_inner").html(note_init(result.content));
  243. note_refresh_new();
  244. add_to_collect_dlg_init();
  245. } catch (e) {
  246. console.error(e);
  247. }
  248. } else {
  249. console.error("ajex error");
  250. }
  251. }
  252. );
  253. }
  254. function article_lang_change() {
  255. let lang = $("#article_lang_select").val();
  256. if (lang.split("-").length == 3) {
  257. $("#article_lang").val(lang.split("_")[2]);
  258. } else {
  259. $("#article_lang").val(lang);
  260. }
  261. }
  262. function article_preview() {
  263. $("#preview_inner").html(note_init($("#article_content").val()));
  264. note_refresh_new();
  265. }
  266. function my_article_custom_book() {
  267. $content = $("#article_content").val();
  268. if ($content == "") {
  269. alert("内容不能为空");
  270. return;
  271. }
  272. if ($content.indexOf("{{") >= 0) {
  273. alert("不能包含句子模版");
  274. return;
  275. }
  276. if (confirm("将此文档转换为自定义书模版吗?") == true) {
  277. document.querySelector("#import_custom_book").checked = true;
  278. my_article_save();
  279. }
  280. }
  281. function my_article_save() {
  282. $.ajax({
  283. type: "POST", //方法类型
  284. dataType: "json", //预期服务器返回的数据类型
  285. url: "../article/my_article_post.php", //url
  286. data: $("#article_edit").serialize(),
  287. success: function (result) {
  288. console.log(result); //打印服务端返回的数据(调试用)
  289. if (result.status == 0) {
  290. alert(gLocal.gui.saved + gLocal.gui.successful);
  291. window.location.reload();
  292. } else {
  293. alert("error:" + result.message);
  294. }
  295. },
  296. error: function (data, status) {
  297. alert("异常!" + data.responseText);
  298. switch (status) {
  299. case "timeout":
  300. break;
  301. case "error":
  302. break;
  303. case "notmodified":
  304. break;
  305. case "parsererror":
  306. break;
  307. default:
  308. break;
  309. }
  310. },
  311. });
  312. }
  313. function course_validate_required(field, alerttxt) {
  314. with (field) {
  315. if (value == null || value == "") {
  316. alert(alerttxt);
  317. return false;
  318. } else {
  319. return true;
  320. }
  321. }
  322. }
  323. function course_validate_form(thisform) {
  324. with (thisform) {
  325. if (course_validate_required(title, gLocal.gui.title_necessary + "!") == false) {
  326. title.focus();
  327. return false;
  328. }
  329. }
  330. }