my_article.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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/?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. html +=
  52. "<button class='icon_btn' onclick=\"copy_to_clipboard('"+WWW_DOMAIN_NAME+"/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 style='display:flex;'>";
  184. html += "<span style='flex:1;margin: auto;'>" + gLocal.gui.title + "</span>";
  185. html += '<span id="article_title" style="flex:7;"></span>';
  186. html += "</div>";
  187. html += "<div style='display:flex;'>";
  188. html += "<span style='flex:1;margin: auto;'>" + gLocal.gui.sub_title + "</span>";
  189. html += '<span id="article_title" style="flex:7;">';
  190. if(!result.subtitle){
  191. result.subtitle="";
  192. }
  193. html += '<input type="input" name="subtitle" value="'+result.subtitle+'" />'
  194. html += '</span>';
  195. html += "</div>";
  196. html += "<div id='channal_selector' form_name='channal' style='display:none;'></div>";
  197. html += "<div style='display:flex;'>";
  198. html += "<span style='flex:1;margin: auto;'>" + gLocal.gui.status + "</span>";
  199. html += '<span id="aritcle_status" style="flex:1;"></span>';
  200. let lang;
  201. if(typeof result.lang == "undefined"){
  202. lang = "en";
  203. }else{
  204. lang = result.lang;
  205. }
  206. //html += '<div style="width:100%;display:flex;" >';
  207. html +=
  208. '<span style="flex:2;margin: auto;text-align: center;">' +
  209. gLocal.gui.language_select +
  210. '</span>';
  211. html +='<input id="article_lang_select" style="flex:4;width:100%;" type="input" onchange="article_lang_change()" placeholder="' +
  212. gLocal.gui.input +
  213. " & " +
  214. gLocal.gui.language_select +
  215. "," +
  216. gLocal.gui.example +
  217. ':Engilish" code="' +
  218. lang +
  219. '" value="' +
  220. lang +
  221. '" >';
  222. html +=' <input id="article_lang" type="hidden" name="lang" value="'+lang+'">';
  223. //html +='</div>';
  224. html += "</div>";
  225. html += "<div style='display:flex;'>";
  226. html += "<span style='flex:1;margin:auto;'>" + gLocal.gui.introduction + "</span>";
  227. html += "<textarea style='flex:7;' name='summary' >" + result.summary + "</textarea></div>";
  228. html += "</div>";
  229. html += "</div>";
  230. html +=
  231. "<textarea id='article_content' name='content' style='height:calc(100vh - 7em - 220px);resize: vertical;'>" +
  232. result.content +
  233. "</textarea>";
  234. html += "</div>";
  235. html += "<div id='preview_div'>";
  236. html += "<div id='preview_inner' class='sent_mode vertical'></div>";
  237. html += "</div>";
  238. html += "</div>";
  239. $("#article_list").html(html);
  240. channal_select_init("channal_selector");
  241. tran_lang_select_init("article_lang_select");
  242. $("#aritcle_status").html(render_status(result.status, false));
  243. let html_title =
  244. "<input id='input_article_title' type='input' name='title' value='" + result.title + "' />";
  245. $("#article_title").html(html_title);
  246. $("#preview_inner").html(note_init(result.content));
  247. note_refresh_new();
  248. add_to_collect_dlg_init();
  249. } catch (e) {
  250. console.error(e);
  251. }
  252. } else {
  253. console.error("ajex error");
  254. }
  255. }
  256. );
  257. }
  258. function article_lang_change() {
  259. let lang = $("#article_lang_select").val();
  260. if (lang.split("_").length == 3) {
  261. $("#article_lang").val(lang.split("_")[2]);
  262. } else {
  263. $("#article_lang").val(lang);
  264. }
  265. }
  266. function article_preview() {
  267. $("#preview_inner").html(note_init($("#article_content").val()));
  268. note_refresh_new();
  269. }
  270. function my_article_custom_book() {
  271. $content = $("#article_content").val();
  272. if ($content == "") {
  273. alert("内容不能为空");
  274. return;
  275. }
  276. if ($content.indexOf("{{") >= 0) {
  277. alert("不能包含句子模版");
  278. return;
  279. }
  280. if (confirm("将此文档转换为自定义书模版吗?") == true) {
  281. document.querySelector("#import_custom_book").checked = true;
  282. my_article_save();
  283. }
  284. }
  285. function my_article_save() {
  286. $.ajax({
  287. type: "POST", //方法类型
  288. dataType: "json", //预期服务器返回的数据类型
  289. url: "../article/my_article_post.php", //url
  290. data: $("#article_edit").serialize(),
  291. success: function (result) {
  292. console.log(result); //打印服务端返回的数据(调试用)
  293. if (result.status == 0) {
  294. alert(gLocal.gui.saved + gLocal.gui.successful);
  295. window.location.reload();
  296. } else {
  297. alert("error:" + result.message);
  298. }
  299. },
  300. error: function (data, status) {
  301. alert("异常!" + data.responseText);
  302. switch (status) {
  303. case "timeout":
  304. break;
  305. case "error":
  306. break;
  307. case "notmodified":
  308. break;
  309. case "parsererror":
  310. break;
  311. default:
  312. break;
  313. }
  314. },
  315. });
  316. }
  317. function course_validate_required(field, alerttxt) {
  318. with (field) {
  319. if (value == null || value == "") {
  320. alert(alerttxt);
  321. return false;
  322. } else {
  323. return true;
  324. }
  325. }
  326. }
  327. function course_validate_form(thisform) {
  328. with (thisform) {
  329. if (course_validate_required(title, gLocal.gui.title_necessary + "!") == false) {
  330. title.focus();
  331. return false;
  332. }
  333. }
  334. }