2
0

group.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. group_list(gGroupId, gList);
  11. team_add_dlg_init("sub_group_add_div");
  12. $("#member_list_shell").css("visibility", "visible");
  13. member_list(gGroupId);
  14. //初始化用户选择对话框
  15. user_select_dlg_init("user_select_div");
  16. }
  17. }
  18. function channal_list() {
  19. $.post("../channal/get.php", {}, function (data) {
  20. try {
  21. _my_channal = JSON.parse(data);
  22. if (get_channel_list_callback) {
  23. get_channel_list_callback();
  24. }
  25. } catch (e) {
  26. console.error(e);
  27. }
  28. });
  29. }
  30. function channal_getById(id) {
  31. for (const iterator of _my_channal) {
  32. if (iterator.id == id) {
  33. return iterator;
  34. }
  35. }
  36. return false;
  37. }
  38. function my_group_list() {
  39. $.get("../group/list.php", {}, function (data, status) {
  40. if (status == "success") {
  41. try {
  42. let html = "";
  43. let result = JSON.parse(data);
  44. let key = 1;
  45. if (result.length > 0) {
  46. for (const iterator of result) {
  47. html += '<div class="file_list_row" style="padding:5px;">';
  48. html += "<div style='flex:1;'>" + key++ + "</div>";
  49. html += "<div style='flex:2;'>" + iterator.group_name + "</div>";
  50. html += "<div style='flex:2;'>";
  51. switch (parseInt(iterator.power)) {
  52. case 0:
  53. html += gLocal.gui.owner;
  54. break;
  55. case 1:
  56. html += gLocal.gui.manager;
  57. break;
  58. case 2:
  59. html += gLocal.gui.member;
  60. break;
  61. default:
  62. break;
  63. }
  64. html += "</div>";
  65. html +=
  66. "<div style='flex:1;'><a href='../group/index.php?id=" +
  67. iterator.group_id +
  68. "'>" +
  69. gLocal.gui.enter +
  70. "</a></div>";
  71. html += "<div style='flex:1;'><div class='hover_button'>";
  72. if (parseInt(iterator.power) == 0) {
  73. //只有管理员可以删除group
  74. html +=
  75. "<button onclick=\"group_del('" +
  76. iterator.group_id +
  77. "')\">" +
  78. gLocal.gui.delete +
  79. "</button>";
  80. }
  81. html += "</div></div>";
  82. html += "</div>";
  83. }
  84. } else {
  85. html += "你没有加入任何工作组 现在 创建 你的工作组。";
  86. }
  87. $("#my_group_list").html(html);
  88. } catch (e) {
  89. console.error(e);
  90. }
  91. } else {
  92. console.error("ajex error");
  93. }
  94. });
  95. }
  96. function group_list(id, list) {
  97. $.get(
  98. "../group/get.php",
  99. {
  100. id: id,
  101. list: list,
  102. },
  103. function (data, status) {
  104. if (status == "success") {
  105. try {
  106. let html = "";
  107. let result = JSON.parse(data);
  108. let key = 1;
  109. if (typeof result.info.description != "undefined" && result.info.description.length > 0) {
  110. html += "<div class='info_block'>";
  111. html += "<h2>" + gLocal.gui.introduction + "</h2>";
  112. html += marked(result.info.description);
  113. html += "</div>";
  114. }
  115. $("#curr_group").html("/" + result.info.name);
  116. if (result.parent) {
  117. //如果是project 显示 group名称
  118. $("#parent_group").html(
  119. " / <a href='../group/index.php?id=" +
  120. result.parent.id +
  121. "'>" +
  122. result.parent.name +
  123. "</a> "
  124. );
  125. }
  126. //共享文件列表
  127. key = 1;
  128. html += "<div class='info_block'>";
  129. html += "<h2>" + gLocal.gui.collaborate + "</h2>";
  130. if (result.file && result.file.length > 0) {
  131. for (const iterator of result.file) {
  132. html += '<div class="file_list_row" style="padding:5px;">';
  133. html += "<div style='flex:1;'>" + key+ "</div>";
  134. html += "<div style='flex:1;'>";
  135. //资源类型
  136. html += "<svg class='icon'>";
  137. let cardUrl = "";
  138. let doing = "";
  139. let viewLink = "<a>";
  140. switch (parseInt(iterator.res_type)) {
  141. case 1: //pcs
  142. html += "<use xlink:href='../studio/svg/icon.svg#article'></use>";
  143. cardUrl = "../doc/card.php";
  144. doing +=
  145. "<a href='../studio/project.php?op=open&doc_id=" +
  146. iterator.res_id +
  147. "'>"+gLocal.gui.open+"</a>";
  148. break;
  149. case 2: //channel
  150. html += "<use xlink:href='../studio/svg/icon.svg#channel_leaves'></use>";
  151. cardUrl = "../channal/card.php";
  152. break;
  153. case 3: //article
  154. html += "<use xlink:href='../studio/svg/icon.svg#article_1'></use>";
  155. cardUrl = "../article/card.php";
  156. viewLink = "<a href='../article/?view=article&id=" + iterator.res_id + "' target='_blank'>";
  157. doing +=
  158. "<a href='../article/my_article_edit.php?id=" +
  159. iterator.res_id +
  160. "' target='_blank'>"+gLocal.gui.edit+"</a>";
  161. break;
  162. case 4: //collection
  163. html += "<use xlink:href='../studio/svg/icon.svg#collection'></use>";
  164. cardUrl = "../collect/card.php";
  165. viewLink ="<a href='../article/?view=collection&collection=" + iterator.res_id + "' target='_blank'>";
  166. doing +=
  167. "<a href='../article/my_collect_edit.php?id=" +
  168. iterator.res_id +
  169. "' target='_blank'>"+gLocal.gui.edit+"</a>";
  170. break;
  171. case 5: //channel片段
  172. break;
  173. default:
  174. html += "unkow";
  175. break;
  176. }
  177. html += "</svg>";
  178. html += "</div>";
  179. html += "<div style='flex:2;'>";
  180. html += viewLink+iterator.res_title+"</a>" ;
  181. html += "<guide url='" + cardUrl + "' gid='" + iterator.res_id + "'></guide>";
  182. html += "</div>";
  183. html += "<div style='flex:2;'>";
  184. switch (parseInt(iterator.power)) {
  185. case 10:
  186. html += gLocal.gui.read_only;
  187. break;
  188. case 20:
  189. html += gLocal.gui.write;
  190. break;
  191. case 30:
  192. break;
  193. default:
  194. break;
  195. }
  196. html += "</div>";
  197. html += "<div style='flex:1;'>";
  198. //可用的操作
  199. html += doing;
  200. html += "</div>";
  201. html += "</div>";
  202. }
  203. } else {
  204. html += "没有共享文档 在译经楼中添加";
  205. }
  206. html += "</div>";
  207. $("#my_group_list").html(html);
  208. guide_init();
  209. } catch (e) {
  210. console.error(e);
  211. }
  212. } else {
  213. console.error("ajex error");
  214. }
  215. }
  216. );
  217. }
  218. function member_list(id) {
  219. $.get(
  220. "../group/list_member.php",
  221. {
  222. id: id,
  223. },
  224. function (data, status) {
  225. if (status == "success") {
  226. try {
  227. let html = "";
  228. let result = JSON.parse(data);
  229. $("#member_number").html("(" + result.length + ")");
  230. //人员
  231. html += "<div class='info_block'>";
  232. if (result && result.length > 0) {
  233. for (const iterator of result) {
  234. html += '<div class="file_list_row" style="padding:5px;">';
  235. html += "<div style='flex:2;'>" + iterator.user_info.nickname + "</div>";
  236. html += "<div style='flex:2;'>";
  237. if (iterator.power == 1) {
  238. html += "拥有者";
  239. }
  240. html += "</div>";
  241. html += "<div style='position: absolute;margin-top: -1.5em;right: 1em;'><div class='hover_button'>";
  242. //if (iterator.owner == getCookie("userid"))
  243. {
  244. html +=
  245. "<button style='background: var(--bg-color);' onclick=\"member_del('" +
  246. id +
  247. "','" +
  248. iterator.user_id +
  249. "')\">❌</button>";
  250. }
  251. html += "</div></div>";
  252. html += "</div>";
  253. }
  254. } else {
  255. html += "这是一个安静的地方";
  256. }
  257. html += "</div>";
  258. $("#member_list").html(html);
  259. } catch (e) {
  260. console.error(e);
  261. }
  262. } else {
  263. console.error("ajex error");
  264. }
  265. }
  266. );
  267. }
  268. function user_selected(id) {
  269. $.post(
  270. "../group/member_put.php",
  271. {
  272. userid: id,
  273. groupid: gGroupId,
  274. },
  275. function (data) {
  276. let error = JSON.parse(data);
  277. if (error.status == 0) {
  278. user_select_cancel();
  279. alert("ok");
  280. location.reload();
  281. } else {
  282. user_select_cancel();
  283. alert(error.message);
  284. }
  285. }
  286. );
  287. }
  288. function user_select_new() {
  289. $.post(
  290. "../group/my_group_put.php",
  291. {
  292. name: $("#user_select_title").val(),
  293. parent: parentid,
  294. },
  295. function (data) {
  296. let error = JSON.parse(data);
  297. if (error.status == 0) {
  298. alert("ok");
  299. user_select_cancel();
  300. location.reload();
  301. } else {
  302. alert(error.message);
  303. }
  304. }
  305. );
  306. }
  307. function group_del(group_id) {
  308. if (
  309. confirm(
  310. "此操作将删除组/项目。\n以及切断分享到此组/项目文件的链接。\n但是不会删除该文件。\n此操作不能恢复。仍然要删除吗!"
  311. )
  312. ) {
  313. $.post(
  314. "../group/group_del.php",
  315. {
  316. groupid: group_id,
  317. },
  318. function (data) {
  319. let error = JSON.parse(data);
  320. if (error.status == 0) {
  321. alert("ok");
  322. location.reload();
  323. } else {
  324. alert(error.message);
  325. }
  326. }
  327. );
  328. }
  329. }
  330. function member_del(group_id, user_id) {
  331. if (confirm("此操作将移除成员。\n此操作不能恢复。仍然要移除吗!")) {
  332. $.post(
  333. "../group/member_del.php",
  334. {
  335. groupid: group_id,
  336. userid: user_id,
  337. },
  338. function (data) {
  339. let error = JSON.parse(data);
  340. if (error.status == 0) {
  341. alert("ok");
  342. location.reload();
  343. } else {
  344. alert(error.message);
  345. }
  346. }
  347. );
  348. }
  349. }