my_article.js 9.5 KB

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