channal.js 8.5 KB

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