group.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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. html += "<use xlink:href='../studio/svg/icon.svg#collection'></use>";
  206. cardUrl = "../collect/card.php";
  207. doing +=
  208. "<a href='../article/?collect=" +
  209. iterator.res_id +
  210. "' target='_blank'>查看</a>";
  211. doing +=
  212. "|<a href='../article/my_collect_edit.php?id=" +
  213. iterator.res_id +
  214. "' target='_blank'>编辑</a>";
  215. break;
  216. case 5: //channel片段
  217. break;
  218. default:
  219. html += "unkow";
  220. break;
  221. }
  222. html += "</svg>";
  223. html += "</div>";
  224. html += "<div style='flex:2;'>";
  225. html += "<guide url='" + cardUrl + "' gid='" + iterator.res_id + "'>";
  226. html += iterator.res_title + "</guide></div>";
  227. html += "<div style='flex:2;'>";
  228. switch (parseInt(iterator.power)) {
  229. case 10:
  230. html += gLocal.gui.read_only;
  231. break;
  232. case 20:
  233. html += gLocal.gui.write;
  234. break;
  235. case 30:
  236. break;
  237. default:
  238. break;
  239. }
  240. html += "</div>";
  241. html += "<div style='flex:1;'>";
  242. //可用的操作
  243. html += doing;
  244. html += "</div>";
  245. html += "</div>";
  246. }
  247. } else {
  248. html += "没有共享文档 在译经楼中添加";
  249. }
  250. html += "</div>";
  251. $("#my_group_list").html(html);
  252. guide_init();
  253. } catch (e) {
  254. console.error(e);
  255. }
  256. } else {
  257. console.error("ajex error");
  258. }
  259. }
  260. );
  261. }
  262. function member_list(id) {
  263. $.get(
  264. "../group/list_member.php",
  265. {
  266. id: id,
  267. },
  268. function (data, status) {
  269. if (status == "success") {
  270. try {
  271. let html = "";
  272. let result = JSON.parse(data);
  273. $("#member_number").html("(" + result.length + ")");
  274. //人员
  275. html += "<div class='info_block'>";
  276. if (result && result.length > 0) {
  277. for (const iterator of result) {
  278. html += '<div class="file_list_row" style="padding:5px;">';
  279. html += "<div style='flex:2;'>" + iterator.user_info.nickname + "</div>";
  280. html += "<div style='flex:2;'>";
  281. if (iterator.power == 1) {
  282. html += "拥有者";
  283. }
  284. html += "</div>";
  285. html += "<div style='position: absolute;margin-top: -1.5em;right: 1em;'><div class='hover_button'>";
  286. //if (iterator.owner == getCookie("userid"))
  287. {
  288. html +=
  289. "<button style='background: var(--bg-color);' onclick=\"member_del('" +
  290. id +
  291. "','" +
  292. iterator.user_id +
  293. "')\">❌</button>";
  294. }
  295. html += "</div></div>";
  296. html += "</div>";
  297. }
  298. } else {
  299. html += "这是一个安静的地方";
  300. }
  301. html += "</div>";
  302. $("#member_list").html(html);
  303. } catch (e) {
  304. console.error(e);
  305. }
  306. } else {
  307. console.error("ajex error");
  308. }
  309. }
  310. );
  311. }
  312. function user_selected(id) {
  313. $.post(
  314. "../group/member_put.php",
  315. {
  316. userid: id,
  317. groupid: gGroupId,
  318. },
  319. function (data) {
  320. let error = JSON.parse(data);
  321. if (error.status == 0) {
  322. user_select_cancel();
  323. alert("ok");
  324. location.reload();
  325. } else {
  326. user_select_cancel();
  327. alert(error.message);
  328. }
  329. }
  330. );
  331. }
  332. function user_select_new() {
  333. $.post(
  334. "../group/my_group_put.php",
  335. {
  336. name: $("#user_select_title").val(),
  337. parent: parentid,
  338. },
  339. function (data) {
  340. let error = JSON.parse(data);
  341. if (error.status == 0) {
  342. alert("ok");
  343. user_select_cancel();
  344. location.reload();
  345. } else {
  346. alert(error.message);
  347. }
  348. }
  349. );
  350. }
  351. function group_del(group_id) {
  352. if (
  353. confirm(
  354. "此操作将删除组/项目。\n以及切断分享到此组/项目文件的链接。\n但是不会删除该文件。\n此操作不能恢复。仍然要删除吗!"
  355. )
  356. ) {
  357. $.post(
  358. "../group/group_del.php",
  359. {
  360. groupid: group_id,
  361. },
  362. function (data) {
  363. let error = JSON.parse(data);
  364. if (error.status == 0) {
  365. alert("ok");
  366. location.reload();
  367. } else {
  368. alert(error.message);
  369. }
  370. }
  371. );
  372. }
  373. }
  374. function member_del(group_id, user_id) {
  375. if (confirm("此操作将移除成员。\n此操作不能恢复。仍然要移除吗!")) {
  376. $.post(
  377. "../group/member_del.php",
  378. {
  379. groupid: group_id,
  380. userid: user_id,
  381. },
  382. function (data) {
  383. let error = JSON.parse(data);
  384. if (error.status == 0) {
  385. alert("ok");
  386. location.reload();
  387. } else {
  388. alert(error.message);
  389. }
  390. }
  391. );
  392. }
  393. }