channal.js 11 KB

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