channal.js 11 KB

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