channal.js 7.7 KB

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