share.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. var _res_id;
  2. var _res_type;
  3. var gUserList = new Array();
  4. function share_load(id, type) {
  5. refresh_coop_list(id);
  6. }
  7. function refresh_coop_list(id) {
  8. $.get(
  9. "../share/coop_get.php",
  10. {
  11. res_id: id,
  12. },
  13. function (data, status) {
  14. if (status == "success") {
  15. let result = JSON.parse(data);
  16. $("#coop_list").html(render_coop_list(result));
  17. }
  18. }
  19. );
  20. }
  21. function render_coop_list(cooplist) {
  22. let html = "";
  23. if (typeof cooplist == "undefined" || cooplist.length == 0) {
  24. html += gLocal.gui.empty_null_mark;
  25. } else {
  26. for (const coop of cooplist) {
  27. html += '<div class="file_list_row" style="padding:5px;">';
  28. let username;
  29. if (coop.cooperator_type == 0) {
  30. username = coop.user.nickname;
  31. html += '<div style="flex:1;" title="' + gLocal.gui.personal + '">';
  32. html += "<svg class='icon'>";
  33. html += " <use xlink:href='../studio/svg/icon.svg#ic_person'></use>";
  34. html += "</svg>";
  35. html += "</div>";
  36. html += "<div style='flex:3;'>" + username + "</div>";
  37. } else {
  38. username = coop.user;
  39. html += '<div style="flex:1;" title="' + gLocal.gui.group + '">';
  40. html += "<svg class='icon'>";
  41. html += " <use xlink:href='../studio/svg/icon.svg#ic_two_person'></use>";
  42. html += "</svg>";
  43. html += "</div>";
  44. html += "<div style='flex:3;'>";
  45. if (coop.parent_name != "") {
  46. html += coop.parent_name + "/";
  47. }
  48. html += username + "</div>";
  49. }
  50. html += "<div style='flex:3;'>";
  51. let power = [
  52. { id: 10, string: "查看者" },
  53. { id: 20, string: "编辑者" },
  54. ];
  55. html += "<select onchange=\"coop_set_power('" + coop.cooperator_id + "',this)\">";
  56. for (const iterator of power) {
  57. html += "<option value='" + iterator.id + "' ";
  58. if (iterator.id == coop.power) {
  59. html += " selected ";
  60. }
  61. html += ">" + iterator.string + "</option>";
  62. }
  63. html += "</select>";
  64. html += "</div>";
  65. html += "<div class='hover_button' style='flex:3;'>";
  66. html +=
  67. "<button onclick=\"coop_remove('" +
  68. coop.cooperator_id +
  69. "','" +
  70. username +
  71. "')\">" +
  72. gLocal.gui.remove +
  73. "</button>";
  74. html += "</div>";
  75. html += "</div>";
  76. }
  77. }
  78. return html;
  79. }
  80. function username_search_keyup(e, obj) {
  81. var keynum;
  82. if (window.event) {
  83. // IE
  84. keynum = e.keyCode;
  85. } else if (e.which) {
  86. // Netscape/Firefox/Opera
  87. keynum = e.which;
  88. }
  89. var keychar = String.fromCharCode(keynum);
  90. if (keynum == 13) {
  91. } else {
  92. if (obj.value.length > 0) {
  93. let type = $("#user_type").val();
  94. username_search(obj.value, type);
  95. } else {
  96. $("#user_search").html("");
  97. }
  98. }
  99. }
  100. function user_selected(id, name, type) {
  101. if (parseInt(type) == 0) {
  102. gUserList.push({ id: id, name: name, type: type });
  103. $("#user_list").html(render_user_list());
  104. $("#user_search").html("");
  105. } else {
  106. $.get("../group/get.php", { id: id }, function (data, status) {
  107. if (status == "success") {
  108. try {
  109. let result = JSON.parse(data);
  110. gUserList.push({ id: id, name: name, type: type, project: result.children });
  111. $("#user_list").html(render_user_list());
  112. $("#user_search").html("");
  113. } catch (e) {}
  114. }
  115. });
  116. }
  117. }
  118. function render_user_list() {
  119. let html = "<ul>";
  120. let arrIndex = 0;
  121. for (const iterator of gUserList) {
  122. html += "<li> <a class='btn_del' onclick=\"userlist_del(' + arrIndex + ')\">删除</a>" + iterator.name;
  123. if (iterator.type == 1) {
  124. //如果是小组,显示项目列表
  125. html += "<div>";
  126. html +=
  127. "<div><input id='prj_" +
  128. iterator.id +
  129. "' checked type='radio' name='prj_" +
  130. iterator.id +
  131. "' />全组成员</div>";
  132. if (typeof iterator.project != "undefined") {
  133. for (const project of iterator.project) {
  134. html +=
  135. "<div><input id='prj_" +
  136. project.id +
  137. "' type='radio' name='prj_" +
  138. iterator.id +
  139. "' />" +
  140. project.name +
  141. "</div>";
  142. }
  143. }
  144. html += "</div>";
  145. }
  146. html += "</li>";
  147. arrIndex++;
  148. }
  149. html += "</ul>";
  150. return html;
  151. }
  152. //从候选列表中删除一个元素
  153. function userlist_del(index) {
  154. let deleted = gUserList.splice(index, 1);
  155. $("#user_list").html(render_user_list());
  156. if (gUserList.length == 0) {
  157. $("#coop_new_tools").hide();
  158. }
  159. }
  160. function username_search(keyword, type) {
  161. //let obj = document.querySelector("#cooperator_type_user");
  162. if (type == 1) {
  163. $.get(
  164. "../ucenter/get.php",
  165. {
  166. username: keyword,
  167. },
  168. function (data, status) {
  169. let result;
  170. try {
  171. result = JSON.parse(data);
  172. } catch (error) {
  173. console(error);
  174. }
  175. let html = "<ul id='user_search_list'>";
  176. if (result.length > 0) {
  177. $("#coop_new_tools").show();
  178. for (const iterator of result) {
  179. html +=
  180. "<li onclick=\"user_selected('" +
  181. iterator.id +
  182. "','" +
  183. iterator.username +
  184. "',0)\">" +
  185. iterator.nickname +
  186. "@" +
  187. iterator.username +
  188. "</li>";
  189. }
  190. } else {
  191. $("#coop_new_tools").hide();
  192. }
  193. html += "</ul>";
  194. $("#user_search").html(html);
  195. }
  196. );
  197. } else {
  198. $.get(
  199. "../group/get_name.php",
  200. {
  201. name: keyword,
  202. },
  203. function (data, status) {
  204. let result;
  205. try {
  206. result = JSON.parse(data);
  207. } catch (error) {
  208. console(error);
  209. }
  210. let html = "<ul id='user_search_list'>";
  211. if (result.length > 0) {
  212. $("#coop_new_tools").show();
  213. for (const iterator of result) {
  214. html +=
  215. "<li onclick=\"user_selected('" +
  216. iterator.id +
  217. "','" +
  218. iterator.name +
  219. "',1)\">" +
  220. iterator.name +
  221. "</li>";
  222. }
  223. } else {
  224. $("#coop_new_tools").hide();
  225. }
  226. html += "</ul>";
  227. $("#user_search").html(html);
  228. }
  229. );
  230. }
  231. }
  232. function add_coop() {
  233. let coopList = new Array();
  234. for (const itUser of gUserList) {
  235. if (itUser.type == 0) {
  236. coopList.push({ id: itUser.id, type: itUser.type });
  237. } else if (itUser.type == 1) {
  238. let obj = document.querySelector("#prj_" + itUser.id);
  239. if (obj.checked) {
  240. coopList.push({ id: itUser.id, type: itUser.type });
  241. }
  242. if (typeof itUser.project != "undefined") {
  243. for (const project of itUser.project) {
  244. obj = document.querySelector("#prj_" + project.id);
  245. if (obj.checked) {
  246. coopList.push({ id: project.id, type: itUser.type });
  247. }
  248. }
  249. }
  250. }
  251. }
  252. $.post(
  253. "../share/coop_put.php",
  254. {
  255. res_id: _res_id,
  256. res_type: _res_type,
  257. user_info: JSON.stringify(coopList),
  258. power: $("#coop_new_power").val(),
  259. },
  260. function (data, status) {
  261. cancel_coop();
  262. let result = JSON.parse(data);
  263. if (parseInt(result.status) == 0) {
  264. refresh_coop_list(_res_id);
  265. } else {
  266. alert(result.message);
  267. }
  268. }
  269. );
  270. }
  271. function cancel_coop() {
  272. $("#user_list").html("");
  273. $("#user_search").html("");
  274. $("#coop_new_tools").hide();
  275. $("#search_user").val("");
  276. gUserList = new Array();
  277. }
  278. function coop_remove(userid, username) {
  279. let strMsg = "要删除%name%吗?";
  280. if (confirm(strMsg.replace("%name%", username))) {
  281. $.post(
  282. "../share/coop_del.php",
  283. {
  284. res_id: _res_id,
  285. res_type: _res_type,
  286. user_id: userid,
  287. },
  288. function (data, status) {
  289. cancel_coop();
  290. let result = JSON.parse(data);
  291. if (parseInt(result.status) == 0) {
  292. refresh_coop_list(_res_id);
  293. } else {
  294. alert(result.message);
  295. }
  296. }
  297. );
  298. }
  299. }
  300. function coop_set_power(userid, power) {
  301. {
  302. $.post(
  303. "../share/coop_post.php",
  304. {
  305. res_id: _res_id,
  306. res_type: _res_type,
  307. user_id: userid,
  308. power: $(power).val(),
  309. },
  310. function (data, status) {
  311. cancel_coop();
  312. let result = JSON.parse(data);
  313. if (parseInt(result.status) == 0) {
  314. refresh_coop_list(_res_id);
  315. } else {
  316. alert(result.message);
  317. }
  318. }
  319. );
  320. }
  321. }
  322. function get_group_project(id) {
  323. $.get(
  324. "../group/get.php",
  325. {
  326. id: id,
  327. },
  328. function (data, status) {
  329. let result = JSON.parse(data);
  330. if (parseInt(result.status) == 0) {
  331. refresh_coop_list(_res_id);
  332. } else {
  333. alert(result.message);
  334. }
  335. }
  336. );
  337. }