channal.js 9.9 KB

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