channal.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. var _my_channal = null;
  2. var gChannelId;
  3. var get_channel_list_callback = null;
  4. var enumChannelType = [
  5. {id:'translation',title:'translation',icon:''},
  6. {id:'original',title:'original',icon:''},
  7. {id:'nissaya',title:'nissaya',icon:''},
  8. {id:'commentary',title:'commentary',icon:''},
  9. ]
  10. channal_list();
  11. var share_win;
  12. function channal_list_init() {
  13. my_channal_list();
  14. share_win = iframe_win_init({ container: "share_win", name: "share", width: "500px" });
  15. channal_add_dlg_init("channal_add_div");
  16. }
  17. function channal_list() {
  18. $.post("../channal/get.php", {}, function (data) {
  19. try {
  20. _my_channal = JSON.parse(data);
  21. if (get_channel_list_callback) {
  22. get_channel_list_callback();
  23. }
  24. } catch (e) {
  25. console.error(e);
  26. }
  27. });
  28. }
  29. function channal_getById(id) {
  30. for (const iterator of _my_channal) {
  31. if (iterator.uid == id) {
  32. return iterator;
  33. }
  34. }
  35. return false;
  36. }
  37. function my_channal_list() {
  38. $.get(
  39. "../channal/get.php",
  40. {
  41. setting: "",
  42. },
  43. function (data, status) {
  44. if (status == "success") {
  45. try {
  46. let html = "";
  47. let result = JSON.parse(data);
  48. let key = 1;
  49. //表头
  50. html += '<div class="file_list_row" style="padding:5px;">';
  51. html += '<div style="max-width:2em;flex:1;"><input type="checkbox" /></div>';
  52. html += "<div style='flex:0.5;'>No.</div>";
  53. html += "<div style='flex:2;'>" + gLocal.gui.title + "</div>";
  54. html += "<div style='flex:1;'>" + gLocal.gui.type + "</a></div>";
  55. html += "<div style='flex:2;'>" + gLocal.gui.owner + "</div>";
  56. html += "<div style='flex:1;'>" + gLocal.gui.privacy + "</div>";
  57. html += "<div style='flex:1;'>" + gLocal.gui.permission + "</a></div>";
  58. html += "<div style='flex:1;'>" + gLocal.gui.edit + "</a></div>";
  59. html += "<div style='flex:1;'>" + gLocal.gui.collaborate + "</div>";
  60. html += "</div>";
  61. //列表
  62. for (const iterator of result) {
  63. html += '<div class="file_list_row" style="padding:5px;">';
  64. html += '<div style="max-width:2em;flex:1;"><input type="checkbox" /></div>';
  65. html += "<div style='flex:0.5;'>" + key++ + "</div>";
  66. //title
  67. html += "<div style='flex:2;'>";
  68. html += "<guide url='../channal/card.php' gid='" + iterator.uid + "'>";
  69. html += iterator.name;
  70. html += "</guide>";
  71. html += "</div>";
  72. //type
  73. html += "<div style='flex:1;'>";
  74. html += iterator.type;
  75. html += "</div>";
  76. //owner
  77. html += "<div style='flex:2;'>";
  78. if (parseInt(iterator.power) == 30) {
  79. html += gLocal.gui.your;
  80. } else {
  81. html += "<guide url='../ucenter/card.php' gid='" + iterator.owner + "'>";
  82. html += iterator.nickname;
  83. html += "</guide>";
  84. }
  85. html += "</div>";
  86. //privacy
  87. html += "<div style='flex:1;'>";
  88. let arrStatus = [
  89. { id: 0, string: gLocal.gui.disable },
  90. { id: 10, string: "🔐"+gLocal.gui.private },
  91. { id: 30, string: "🌐"+gLocal.gui.public },
  92. ];
  93. for (const status of arrStatus) {
  94. if (parseInt(iterator.status) == status.id) {
  95. html += status.string;
  96. }
  97. }
  98. //render_status(iterator.status) +
  99. html += "</div>";
  100. switch (parseInt(iterator.power)) {
  101. case 10:
  102. html += "<div style='flex:1;'>";
  103. html += gLocal.gui.read_only;
  104. html += "</div>";
  105. html += "<div style='flex:1;'>";
  106. html += "</div>";
  107. html += "<div style='flex:1;'>";
  108. html += "</div>";
  109. break;
  110. case 20:
  111. html += "<div style='flex:1;'>";
  112. html += gLocal.gui.write;
  113. html += "</div>";
  114. html += "<div style='flex:1;'>";
  115. html +=
  116. "<a href='../channal/my_channal_edit.php?id=" +
  117. iterator.id +
  118. "'>✏️" +
  119. gLocal.gui.edit +
  120. "</a></div><div style='flex:1;'>";
  121. html += "</div>";
  122. break;
  123. case 30:
  124. html += "<div style='flex:1;'>";
  125. html += gLocal.gui.owner;
  126. html += "</div>";
  127. html += "<div style='flex:1;'>";
  128. html +=
  129. "<a href='../channal/my_channal_edit.php?id=" +
  130. iterator.uid +
  131. "'>✏️" +
  132. gLocal.gui.edit +
  133. "</a></div><div style='flex:1;'>";
  134. html += " <a onclick=\"channel_share('" + iterator.uid + "')\">🔑"+gLocal.gui.share_to+"</a>";
  135. html += "</div>";
  136. break;
  137. default:
  138. break;
  139. }
  140. html += "</div>";
  141. }
  142. $("#my_channal_list").html(html);
  143. guide_init();
  144. } catch (e) {
  145. console.error(e);
  146. }
  147. } else {
  148. console.error("ajex error");
  149. }
  150. }
  151. );
  152. }
  153. function channel_share(id) {
  154. share_win.show("../share/share.php?id=" + id + "&type=2");
  155. }
  156. /*
  157. 编辑channel信息
  158. */
  159. function my_channal_edit(id) {
  160. gChannelId = id;
  161. $.get(
  162. "../channal/my_channal_get.php",
  163. {
  164. id: id,
  165. setting: "",
  166. },
  167. function (data, status) {
  168. if (status == "success") {
  169. try {
  170. let html = "";
  171. let result = JSON.parse(data);
  172. $("#article_collect").attr("a_id", result.id);
  173. html += '<div class="" style="padding:5px;">';
  174. html += '<div style="max-width:2em;flex:1;"></div>';
  175. html += "</div>";
  176. html += "<div style='width: 60%;padding: 1em;min-width: 25em;'>";
  177. html += '<div style="display:flex;line-height:32px;">';
  178. html += "<input type='hidden' name='id' value='" + result.id + "'/>";
  179. html += "</div>";
  180. html += '<div style="display:flex;line-height:32px;">';
  181. html += "<div style='flex:2;'>" + gLocal.gui.title + "</div>";
  182. html += "<div style='flex:8;'>";
  183. html +=
  184. "<input type='input' name='name' value='" +
  185. result.name +
  186. "' maxlength='32' placeholder='channel title'/>";
  187. html += "</div>";
  188. html += "</div>";
  189. html += "<div style='display:flex;'>";
  190. html += "<div style='flex:2;'>" + gLocal.gui.introduction + "</div>";
  191. html += "<div style='flex:8;'>";
  192. html += "<textarea name='summary'>" + result.summary + "</textarea>";
  193. html += "</div>";
  194. html += "</div>";
  195. html += '<div style="display:flex;line-height:32px;">';
  196. html += '<div style="flex:2;">' + gLocal.gui.language_select + "</div>";
  197. html += '<div style="flex:8;">';
  198. html +=
  199. '<input id="channal_lang_select" type="input" onchange="channal_lang_change()"' +
  200. ' placeholder = "try type chinese or en " ' +
  201. ' title="type language name/code" code="' +
  202. result.lang +
  203. '" value="' +
  204. result.lang +
  205. '" > <input id="channal_lang" type="hidden" name="lang" value="' +
  206. result.lang +
  207. '">';
  208. html += "</div>";
  209. html += "</div>";
  210. html += '<div style="display:flex;line-height:32px;">';
  211. html += '<div style="flex:2;">' + gLocal.gui.privacy + "</div>";
  212. html += '<div style="flex:8;">';
  213. html += "<select id = 'type' name = 'type'>";
  214. for (const iterator of enumChannelType) {
  215. html += "<option ";
  216. if (result.type == iterator.id) {
  217. html += " selected ";
  218. }
  219. html += " value='" + iterator.id + "'>" + iterator.title + "</option>";
  220. }
  221. html += "</select>";
  222. html += "</div>";
  223. html += "</div>";
  224. html += '<div style="display:flex;line-height:32px;">';
  225. html += '<div style="flex:2;">' + gLocal.gui.privacy + "</div>";
  226. html += '<div style="flex:8;">';
  227. let arrStatus = [
  228. { id: 0, string: gLocal.gui.disable, note: gLocal.gui.disable_note },
  229. { id: 10, string: gLocal.gui.private, note: gLocal.gui.private_note },
  230. { id: 30, string: gLocal.gui.public, note: gLocal.gui.public_note },
  231. ];
  232. html += "<select id = 'status' name = 'status' onchange='status_change(this)'>";
  233. let status_note = "";
  234. for (const iterator of arrStatus) {
  235. html += "<option ";
  236. if (parseInt(result.status) == iterator.id) {
  237. html += " selected ";
  238. status_note = iterator.note;
  239. }
  240. html += " value='" + iterator.id + "'>" + iterator.string + "</option>";
  241. }
  242. html += "</select>";
  243. html +=
  244. "<span id = 'status_help' style='margin: 0 1em;'>" +
  245. status_note +
  246. "</span>"+
  247. "<a href='#' target='_blank'>[" +
  248. gLocal.gui.infomation +
  249. "]</a>"+
  250. "</li>";
  251. html += "</div>";
  252. html += "</div>";
  253. html += "</div>";
  254. $("#channal_info").html(html);
  255. user_select_dlg_init("add_coop_user_dlg");
  256. tran_lang_select_init("channal_lang_select");
  257. $("#channal_title").html(result.name);
  258. $("#preview_inner").html();
  259. } catch (e) {
  260. console.error(e);
  261. }
  262. } else {
  263. console.error("ajex error");
  264. }
  265. }
  266. );
  267. }
  268. function add_coop_user() {
  269. user_select_dlg_show();
  270. }
  271. function user_selected(id) {
  272. $.post(
  273. "../channal/coop_new_user.php",
  274. {
  275. userid: id,
  276. channel_id: gChannelId,
  277. },
  278. function (data) {
  279. let error = JSON.parse(data);
  280. if (error.status == 0) {
  281. user_select_cancel();
  282. alert("ok");
  283. location.reload();
  284. } else {
  285. alert(error.message);
  286. }
  287. }
  288. );
  289. }
  290. function status_change(obj) {
  291. let arrStatus = [
  292. { id: 0, string: gLocal.gui.disable, note: gLocal.gui.disable_note },
  293. { id: 10, string: gLocal.gui.private, note: gLocal.gui.private_note },
  294. { id: 30, string: gLocal.gui.public, note: gLocal.gui.public_note },
  295. ];
  296. let newStatus = $(obj).val();
  297. for (const iterator of arrStatus) {
  298. if (parseInt(newStatus) == iterator.id) {
  299. $("#status_help").html(iterator.note);
  300. }
  301. }
  302. }
  303. function channal_lang_change() {
  304. let lang = $("#channal_lang_select").val();
  305. if (lang.split("_").length == 3) {
  306. $("#channal_lang").val(lang.split("_")[2]);
  307. } else {
  308. $("#channal_lang").val(lang);
  309. }
  310. }
  311. function my_channal_save() {
  312. $.ajax({
  313. type: "POST", //方法类型
  314. dataType: "json", //预期服务器返回的数据类型
  315. url: "../channal/my_channal_post.php", //url
  316. data: $("#channal_edit").serialize(),
  317. success: function (result) {
  318. console.log(result); //打印服务端返回的数据(调试用)
  319. if (result.status == 0) {
  320. alert("保存成功");
  321. } else {
  322. alert("error:" + result.message);
  323. }
  324. },
  325. error: function (data, status) {
  326. alert("异常!" + status + data.responseText);
  327. switch (status) {
  328. case "timeout":
  329. break;
  330. case "error":
  331. break;
  332. case "notmodified":
  333. break;
  334. case "parsererror":
  335. break;
  336. default:
  337. break;
  338. }
  339. },
  340. });
  341. }