group.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. var _my_channal = null;
  2. var get_channel_list_callback = null;
  3. channal_list();
  4. function group_list_init() {
  5. if (typeof gGroupId == "undefined") {
  6. my_group_list();
  7. group_add_dlg_init("group_add_div");
  8. $("#button_new_group").show();
  9. } else {
  10. $("#button_new_sub_group").show();
  11. group_list(gGroupId, gList);
  12. team_add_dlg_init("sub_group_add_div");
  13. $("#member_list_shell").css("visibility", "visible");
  14. member_list(gGroupId);
  15. //初始化用户选择对话框
  16. user_select_dlg_init("user_select_div");
  17. }
  18. }
  19. function channal_list() {
  20. $.post("../channal/get.php", {}, function (data) {
  21. try {
  22. _my_channal = JSON.parse(data);
  23. if (get_channel_list_callback) {
  24. get_channel_list_callback();
  25. }
  26. } catch (e) {
  27. console.error(e);
  28. }
  29. });
  30. }
  31. function channal_getById(id) {
  32. for (const iterator of _my_channal) {
  33. if (iterator.id == id) {
  34. return iterator;
  35. }
  36. }
  37. return false;
  38. }
  39. function my_group_list() {
  40. $.get("../group/list.php", {}, function (data, status) {
  41. if (status == "success") {
  42. try {
  43. let html = "";
  44. let result = JSON.parse(data);
  45. let key = 1;
  46. if (result.length > 0) {
  47. for (const iterator of result) {
  48. html += '<div class="file_list_row" style="padding:5px;">';
  49. html += "<div style='flex:1;'>" + key++ + "</div>";
  50. html += "<div style='flex:2;'>" + iterator.group_name + "</div>";
  51. html += "<div style='flex:2;'>";
  52. if (iterator.power == 1) {
  53. html += "拥有者";
  54. }
  55. html += "</div>";
  56. html +=
  57. "<div style='flex:1;'><a href='../group/index.php?id=" +
  58. iterator.group_id +
  59. "'>进入</a></div>";
  60. html += "</div>";
  61. }
  62. } else {
  63. html += "你没有加入任何工作组 现在 创建 你的工作组。";
  64. }
  65. $("#my_group_list").html(html);
  66. } catch (e) {
  67. console.error(e);
  68. }
  69. } else {
  70. console.error("ajex error");
  71. }
  72. });
  73. }
  74. function group_list(id, list) {
  75. $.get(
  76. "../group/get.php",
  77. {
  78. id: id,
  79. list: list,
  80. },
  81. function (data, status) {
  82. if (status == "success") {
  83. try {
  84. let html = "";
  85. let result = JSON.parse(data);
  86. let key = 1;
  87. html += "<div class='info_block'>";
  88. html += "<h2>" + gLocal.gui.introduction + "</h2>";
  89. html += result.info.description;
  90. html += "</div>";
  91. $("#curr_group").html("/ <a>" + result.info.name + "</a>");
  92. if (result.parent) {
  93. $("#parent_group").html(
  94. " / <a href='../group/index.php?id=" +
  95. result.parent.id +
  96. "'>" +
  97. result.parent.name +
  98. "</a> "
  99. );
  100. } else {
  101. //子小组列表
  102. html += "<div class='info_block'>";
  103. html += "<h2>" + gLocal.gui.sub_group + "</h2>";
  104. if (result.children && result.children.length > 0) {
  105. for (const iterator of result.children) {
  106. html += '<div class="file_list_row" style="padding:5px;">';
  107. html += "<div style='flex:1;'>" + key++ + "</div>";
  108. html += "<div style='flex:2;'>" + iterator.name + "</div>";
  109. html += "<div style='flex:2;'>";
  110. if (iterator.power == 1) {
  111. html += "拥有者";
  112. }
  113. html += "</div>";
  114. html +=
  115. "<div style='flex:1;'><a href='../group/index.php?id=" +
  116. iterator.id +
  117. "&list=file'>进入</a></div>";
  118. html += "</div>";
  119. }
  120. } else {
  121. html += "尚未设置小组";
  122. }
  123. html += "</div>";
  124. }
  125. //共享文件列表
  126. key = 1;
  127. html += "<div class='info_block'>";
  128. html += "<h2>" + gLocal.gui.collaborate + "</h2>";
  129. if (result.file && result.file.length > 0) {
  130. for (const iterator of result.file) {
  131. html += '<div class="file_list_row" style="padding:5px;">';
  132. html += "<div style='flex:1;'>" + key++ + "</div>";
  133. html += "<div style='flex:2;'>" + iterator.title + "</div>";
  134. html += "<div style='flex:2;'>";
  135. switch (iterator.power) {
  136. case 10:
  137. html += gLocal.gui.read_only;
  138. break;
  139. case 20:
  140. break;
  141. case 30:
  142. html += gLocal.gui.write;
  143. break;
  144. default:
  145. break;
  146. }
  147. html += "</div>";
  148. html +=
  149. "<div style='flex:1;'><a href='../studio/project.php?op=open&doc_id=" +
  150. iterator.doc_id +
  151. "'>打开</a></div>";
  152. html += "</div>";
  153. }
  154. } else {
  155. html += "没有共享文档 在译经楼中添加";
  156. }
  157. html += "</div>";
  158. $("#my_group_list").html(html);
  159. } catch (e) {
  160. console.error(e);
  161. }
  162. } else {
  163. console.error("ajex error");
  164. }
  165. }
  166. );
  167. }
  168. function member_list(id) {
  169. $.get(
  170. "../group/list_member.php",
  171. {
  172. id: id,
  173. },
  174. function (data, status) {
  175. if (status == "success") {
  176. try {
  177. let html = "";
  178. let result = JSON.parse(data);
  179. $("#member_number").html("(" + result.length + ")");
  180. //子小组列表
  181. html += "<div class='info_block'>";
  182. if (result && result.length > 0) {
  183. for (const iterator of result) {
  184. html += '<div class="file_list_row" style="padding:5px;">';
  185. html += "<div style='flex:2;'>" + iterator.user_info.nickname + "</div>";
  186. html += "<div style='flex:2;'>";
  187. if (iterator.power == 1) {
  188. html += "拥有者";
  189. }
  190. html += "</div>";
  191. html += "<div style='flex:1;'>";
  192. html += "</div>";
  193. html += "</div>";
  194. }
  195. } else {
  196. html += "这是一个安静的地方";
  197. }
  198. html += "</div>";
  199. $("#member_list").html(html);
  200. } catch (e) {
  201. console.error(e);
  202. }
  203. } else {
  204. console.error("ajex error");
  205. }
  206. }
  207. );
  208. }
  209. /*
  210. 编辑channel信息
  211. */
  212. function my_channal_edit(id) {
  213. $.get(
  214. "../channal/my_channal_get.php",
  215. {
  216. id: id,
  217. setting: "",
  218. },
  219. function (data, status) {
  220. if (status == "success") {
  221. try {
  222. let html = "";
  223. let result = JSON.parse(data);
  224. $("#article_collect").attr("a_id", result.id);
  225. html += '<div class="" style="padding:5px;">';
  226. html += '<div style="max-width:2em;flex:1;"></div>';
  227. html += "</div>";
  228. html += "<div style='width: 60%;padding: 1em;min-width: 25em;'>";
  229. html += '<div style="display:flex;line-height:32px;">';
  230. html += "<input type='hidden' name='id' value='" + result.id + "'/>";
  231. html += "</div>";
  232. html += '<div style="display:flex;line-height:32px;">';
  233. html += "<div style='flex:2;'>" + gLocal.gui.title + "</div>";
  234. html += "<div style='flex:8;'>";
  235. html +=
  236. "<input type='input' name='name' value='" +
  237. result.name +
  238. "' maxlength='32' placeholder='channel title'/>";
  239. html += "</div>";
  240. html += "</div>";
  241. html += "<div style='display:flex;'>";
  242. html += "<div style='flex:2;'>" + gLocal.gui.introduction + "</div>";
  243. html += "<div style='flex:8;'>";
  244. html += "<textarea name='summary'>" + result.summary + "</textarea>";
  245. html += "</div>";
  246. html += "</div>";
  247. html += '<div style="display:flex;line-height:32px;">';
  248. html += '<div style="flex:2;">' + gLocal.gui.language_select + "</div>";
  249. html += '<div style="flex:8;">';
  250. html +=
  251. '<input id="channal_lang_select" type="input" onchange="channal_lang_change()"' +
  252. ' placeholder = "try type chinese or en " ' +
  253. ' title="type language name/code" code="' +
  254. result.lang +
  255. '" value="' +
  256. result.lang +
  257. '" > <input id="channal_lang" type="hidden" name="lang" value="' +
  258. result.lang +
  259. '">';
  260. html += "</div>";
  261. html += "</div>";
  262. html += '<div style="display:flex;line-height:32px;">';
  263. html += '<div style="flex:2;">' + gLocal.gui.privacy + "</div>";
  264. html += '<div style="flex:8;">';
  265. let arrStatus = [
  266. { id: 0, string: gLocal.gui.disable, note: gLocal.gui.disable_note },
  267. { id: 10, string: gLocal.gui.private, note: gLocal.gui.private_note },
  268. { id: 30, string: gLocal.gui.public, note: gLocal.gui.public_note },
  269. ];
  270. html += "<select id = 'status' name = 'status' onchange='status_change(this)'>";
  271. let status_note = "";
  272. for (const iterator of arrStatus) {
  273. html += "<option ";
  274. if (parseInt(result.status) == iterator.id) {
  275. html += " selected ";
  276. status_note = iterator.note;
  277. }
  278. html += " value='" + iterator.id + "'>" + iterator.string + "</option>";
  279. }
  280. html += "</select>";
  281. html +=
  282. "<span id = 'status_help' style='margin: 0 1em;'>" +
  283. status_note +
  284. "</span><a href='#' target='_blank'>[" +
  285. gLocal.gui.infomation +
  286. "]</li>";
  287. html += "</div>";
  288. html += "</div>";
  289. html += "</div>";
  290. html += "<div id='preview_div'>";
  291. html += "<div id='preview_inner' ></div>";
  292. html += "</div>";
  293. $("#channal_info").html(html);
  294. tran_lang_select_init("channal_lang_select");
  295. //$("#aritcle_status").html(render_status(result.status));
  296. $("#channal_title").html(result.name);
  297. $("#preview_inner").html();
  298. } catch (e) {
  299. console.error(e);
  300. }
  301. } else {
  302. console.error("ajex error");
  303. }
  304. }
  305. );
  306. }
  307. function status_change(obj) {
  308. let arrStatus = [
  309. { id: 0, string: gLocal.gui.disable, note: gLocal.gui.disable_note },
  310. { id: 10, string: gLocal.gui.private, note: gLocal.gui.private_note },
  311. { id: 30, string: gLocal.gui.public, note: gLocal.gui.public_note },
  312. ];
  313. let newStatus = $(obj).val();
  314. for (const iterator of arrStatus) {
  315. if (parseInt(newStatus) == iterator.id) {
  316. $("#status_help").html(iterator.note);
  317. }
  318. }
  319. }
  320. function channal_lang_change() {
  321. let lang = $("#channal_lang_select").val();
  322. if (lang.split("_").length == 3) {
  323. $("#channal_lang").val(lang.split("_")[2]);
  324. } else {
  325. $("#channal_lang").val(lang);
  326. }
  327. }
  328. function my_channal_save() {
  329. $.ajax({
  330. type: "POST", //方法类型
  331. dataType: "json", //预期服务器返回的数据类型
  332. url: "../channal/my_channal_post.php", //url
  333. data: $("#channal_edit").serialize(),
  334. success: function (result) {
  335. console.log(result); //打印服务端返回的数据(调试用)
  336. if (result.status == 0) {
  337. alert("保存成功");
  338. } else {
  339. alert("error:" + result.message);
  340. }
  341. },
  342. error: function (data, status) {
  343. alert("异常!" + status + data.responseText);
  344. switch (status) {
  345. case "timeout":
  346. break;
  347. case "error":
  348. break;
  349. case "notmodified":
  350. break;
  351. case "parsererror":
  352. break;
  353. default:
  354. break;
  355. }
  356. },
  357. });
  358. }