my_article.js 9.9 KB

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