my_article.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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/mint/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 += "<input type='checkbox' name='import' />" + gLocal.gui.import + gLocal.gui.text;
  190. html += "<div>";
  191. //html += "<div id='article_collect' vui='collect-dlg' ></div>"
  192. html += "<div style='display:flex;'>";
  193. html += "<span style='flex:3;margin:auto;'>" + gLocal.gui.title + "</span>";
  194. html += '<span id="article_title" style="flex:7;"></span></div>';
  195. html += "<div id='channal_selector' form_name='channal' style='display:none;'></div>";
  196. html += "<div id='aritcle_status' style='display: flex; '></div>";
  197. html +=
  198. '<div style="display:none;width:100%;" ><span style="flex:3;margin: auto;">' +
  199. gLocal.gui.language_select +
  200. '</span> <input id="article_lang_select" style="flex:7;width:100%;" type="input" onchange="article_lang_change()" placeholder="' +
  201. gLocal.gui.input +
  202. " & " +
  203. gLocal.gui.language_select +
  204. "," +
  205. gLocal.gui.example +
  206. ':Engilish" code="' +
  207. result.lang +
  208. '" value="' +
  209. result.lang +
  210. '" > <input id="article_lang" type="hidden" name="lang" value=""></div>';
  211. html += "<div style='display:flex;'>";
  212. html += "<span style='flex:3;margin:auto;'>" + gLocal.gui.introduction + "</span>";
  213. html += "<textarea style='flex:7;' name='summary' >" + result.summary + "</textarea></div>";
  214. html += "</div>";
  215. html += "</div>";
  216. html +=
  217. "<textarea id='article_content' name='content' style='height:500px;max-height: 40vh;'>" +
  218. result.content +
  219. "</textarea>";
  220. html += "</div>";
  221. html += "<div id='preview_div'>";
  222. html += "<div id='preview_inner' class='sent_mode vertical'></div>";
  223. html += "</div>";
  224. html += "</div>";
  225. $("#article_list").html(html);
  226. channal_select_init("channal_selector");
  227. tran_lang_select_init("article_lang_select");
  228. $("#aritcle_status").html(render_status(result.status, false));
  229. let html_title =
  230. "<input id='input_article_title' type='input' name='title' value='" + result.title + "' />";
  231. $("#article_title").html(html_title);
  232. $("#preview_inner").html(note_init(result.content));
  233. note_refresh_new();
  234. add_to_collect_dlg_init();
  235. } catch (e) {
  236. console.error(e);
  237. }
  238. } else {
  239. console.error("ajex error");
  240. }
  241. }
  242. );
  243. }
  244. function article_lang_change() {
  245. let lang = $("#article_lang_select").val();
  246. if (lang.split("-").length == 3) {
  247. $("#article_lang").val(lang.split("_")[2]);
  248. } else {
  249. $("#article_lang").val(lang);
  250. }
  251. }
  252. function article_preview() {
  253. $("#preview_inner").html(note_init($("#article_content").val()));
  254. note_refresh_new();
  255. }
  256. function my_article_save() {
  257. $.ajax({
  258. type: "POST", //方法类型
  259. dataType: "json", //预期服务器返回的数据类型
  260. url: "../article/my_article_post.php", //url
  261. data: $("#article_edit").serialize(),
  262. success: function (result) {
  263. console.log(result); //打印服务端返回的数据(调试用)
  264. if (result.status == 0) {
  265. alert(gLocal.gui.saved + gLocal.gui.successful);
  266. } else {
  267. alert("error:" + result.message);
  268. }
  269. },
  270. error: function (data, status) {
  271. alert("异常!" + data.responseText);
  272. switch (status) {
  273. case "timeout":
  274. break;
  275. case "error":
  276. break;
  277. case "notmodified":
  278. break;
  279. case "parsererror":
  280. break;
  281. default:
  282. break;
  283. }
  284. },
  285. });
  286. }
  287. function course_validate_required(field, alerttxt) {
  288. with (field) {
  289. if (value == null || value == "") {
  290. alert(alerttxt);
  291. return false;
  292. } else {
  293. return true;
  294. }
  295. }
  296. }
  297. function course_validate_form(thisform) {
  298. with (thisform) {
  299. if (course_validate_required(title, gLocal.gui.title_necessary + "!") == false) {
  300. title.focus();
  301. return false;
  302. }
  303. }
  304. }