my_article.js 11 KB

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