2
0

group.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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. } else {
  126. /*
  127. 关闭子小组功能
  128. if (result.info.owner == getCookie("userid")) {
  129. $("#button_new_sub_group").show();
  130. }
  131. //子小组列表
  132. html += "<div class='info_block'>";
  133. html += "<h2>" + gLocal.gui.sub_group + "</h2>";
  134. if (result.children && result.children.length > 0) {
  135. for (const iterator of result.children) {
  136. html += '<div class="file_list_row" style="padding:5px;">';
  137. html += "<div style='flex:1;'>" + key++ + "</div>";
  138. html += "<div style='flex:2;'>" + iterator.name + "</div>";
  139. html += "<div style='flex:2;'>";
  140. if (iterator.owner == getCookie("userid")) {
  141. html += gLocal.gui.owner;
  142. }
  143. html += "</div>";
  144. html +=
  145. "<div style='flex:1;'><a href='../group/index.php?id=" +
  146. iterator.id +
  147. "&list=file'>" +
  148. gLocal.gui.enter +
  149. "</a></div>";
  150. html += "<div style='flex:1;'><div class='hover_button'>";
  151. if (iterator.owner == getCookie("userid")) {
  152. html +=
  153. "<button onclick=\"group_del('" +
  154. iterator.id +
  155. "')\">" +
  156. gLocal.gui.delete +
  157. "</button>";
  158. }
  159. html += "</div></div>";
  160. html += "</div>";
  161. }
  162. } else {
  163. html += "尚未设置小组";
  164. }
  165. html += "</div>";
  166. */
  167. }
  168. //共享文件列表
  169. key = 1;
  170. html += "<div class='info_block'>";
  171. html += "<h2>" + gLocal.gui.collaborate + "</h2>";
  172. if (result.file && result.file.length > 0) {
  173. for (const iterator of result.file) {
  174. html += '<div class="file_list_row" style="padding:5px;">';
  175. html += "<div style='flex:1;'>" + key++ + "</div>";
  176. html += "<div style='flex:1;'>";
  177. //资源类型
  178. html += "<svg class='icon'>";
  179. let cardUrl = "";
  180. let doing = "";
  181. switch (parseInt(iterator.res_type)) {
  182. case 1: //pcs
  183. html += "<use xlink:href='../studio/svg/icon.svg#article'></use>";
  184. cardUrl = "../doc/card.php";
  185. doing +=
  186. "<a href='../studio/project.php?op=open&doc_id=" +
  187. iterator.res_id +
  188. "'>打开</a>";
  189. break;
  190. case 2: //channel
  191. html += "<use xlink:href='../studio/svg/icon.svg#channel_leaves'></use>";
  192. cardUrl = "../channal/card.php";
  193. break;
  194. case 3: //article
  195. html += "<use xlink:href='../studio/svg/icon.svg#article-1'></use>";
  196. cardUrl = "../article/card.php";
  197. doing +=
  198. "<a href='../article/?id=" + iterator.res_id + "' target='_blank'>查看</a>";
  199. doing +=
  200. "|<a href='../article/my_article_edit.php?id=" +
  201. iterator.res_id +
  202. "' target='_blank'>编辑</a>";
  203. break;
  204. case 4: //collection
  205. break;
  206. case 5: //channel片段
  207. break;
  208. default:
  209. html += "unkow";
  210. break;
  211. }
  212. html += "</svg>";
  213. html += "</div>";
  214. html += "<div style='flex:2;'>";
  215. html += "<guide url='" + cardUrl + "' gid='" + iterator.res_id + "'>";
  216. html += iterator.res_title + "</guide></div>";
  217. html += "<div style='flex:2;'>";
  218. switch (parseInt(iterator.power)) {
  219. case 10:
  220. html += gLocal.gui.read_only;
  221. break;
  222. case 20:
  223. html += gLocal.gui.write;
  224. break;
  225. case 30:
  226. break;
  227. default:
  228. break;
  229. }
  230. html += "</div>";
  231. html += "<div style='flex:1;'>";
  232. //可用的操作
  233. html += doing;
  234. html += "</div>";
  235. html += "</div>";
  236. }
  237. } else {
  238. html += "没有共享文档 在译经楼中添加";
  239. }
  240. html += "</div>";
  241. $("#my_group_list").html(html);
  242. guide_init();
  243. } catch (e) {
  244. console.error(e);
  245. }
  246. } else {
  247. console.error("ajex error");
  248. }
  249. }
  250. );
  251. }
  252. function member_list(id) {
  253. $.get(
  254. "../group/list_member.php",
  255. {
  256. id: id,
  257. },
  258. function (data, status) {
  259. if (status == "success") {
  260. try {
  261. let html = "";
  262. let result = JSON.parse(data);
  263. $("#member_number").html("(" + result.length + ")");
  264. //人员
  265. html += "<div class='info_block'>";
  266. if (result && result.length > 0) {
  267. for (const iterator of result) {
  268. html += '<div class="file_list_row" style="padding:5px;">';
  269. html += "<div style='flex:2;'>" + iterator.user_info.nickname + "</div>";
  270. html += "<div style='flex:2;'>";
  271. if (iterator.power == 1) {
  272. html += "拥有者";
  273. }
  274. html += "</div>";
  275. html += "<div style='position: absolute;margin-top: -1.5em;right: 1em;'><div class='hover_button'>";
  276. //if (iterator.owner == getCookie("userid"))
  277. {
  278. html +=
  279. "<button style='background: var(--bg-color);' onclick=\"member_del('" +
  280. id +
  281. "','" +
  282. iterator.user_id +
  283. "')\">❌</button>";
  284. }
  285. html += "</div></div>";
  286. html += "</div>";
  287. }
  288. } else {
  289. html += "这是一个安静的地方";
  290. }
  291. html += "</div>";
  292. $("#member_list").html(html);
  293. } catch (e) {
  294. console.error(e);
  295. }
  296. } else {
  297. console.error("ajex error");
  298. }
  299. }
  300. );
  301. }
  302. function user_selected(id) {
  303. $.post(
  304. "../group/member_put.php",
  305. {
  306. userid: id,
  307. groupid: gGroupId,
  308. },
  309. function (data) {
  310. let error = JSON.parse(data);
  311. if (error.status == 0) {
  312. user_select_cancel();
  313. alert("ok");
  314. location.reload();
  315. } else {
  316. user_select_cancel();
  317. alert(error.message);
  318. }
  319. }
  320. );
  321. }
  322. function user_select_new() {
  323. $.post(
  324. "../group/my_group_put.php",
  325. {
  326. name: $("#user_select_title").val(),
  327. parent: parentid,
  328. },
  329. function (data) {
  330. let error = JSON.parse(data);
  331. if (error.status == 0) {
  332. alert("ok");
  333. user_select_cancel();
  334. location.reload();
  335. } else {
  336. alert(error.message);
  337. }
  338. }
  339. );
  340. }
  341. function group_del(group_id) {
  342. if (
  343. confirm(
  344. "此操作将删除组/项目。\n以及切断分享到此组/项目文件的链接。\n但是不会删除该文件。\n此操作不能恢复。仍然要删除吗!"
  345. )
  346. ) {
  347. $.post(
  348. "../group/group_del.php",
  349. {
  350. groupid: group_id,
  351. },
  352. function (data) {
  353. let error = JSON.parse(data);
  354. if (error.status == 0) {
  355. alert("ok");
  356. location.reload();
  357. } else {
  358. alert(error.message);
  359. }
  360. }
  361. );
  362. }
  363. }
  364. function member_del(group_id, user_id) {
  365. if (confirm("此操作将移除成员。\n此操作不能恢复。仍然要移除吗!")) {
  366. $.post(
  367. "../group/member_del.php",
  368. {
  369. groupid: group_id,
  370. userid: user_id,
  371. },
  372. function (data) {
  373. let error = JSON.parse(data);
  374. if (error.status == 0) {
  375. alert("ok");
  376. location.reload();
  377. } else {
  378. alert(error.message);
  379. }
  380. }
  381. );
  382. }
  383. }