share.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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>" + iterator.name + ' <a onclick="userlist_del(' + arrIndex + ')">删除</a>';
  123. if (iterator.type == 1) {
  124. //如果是小组,显示项目列表
  125. html += "<div>";
  126. html += "<div><input id='prj_" + iterator.id + "' checked type='checkbox' />全组可用</div>";
  127. if (typeof iterator.project != "undefined") {
  128. for (const project of iterator.project) {
  129. html += "<div><input id='prj_" + project.id + "' type='checkbox' />" + project.name + "</div>";
  130. }
  131. }
  132. html += "</div>";
  133. }
  134. html += "</li>";
  135. arrIndex++;
  136. }
  137. html += "</ul>";
  138. return html;
  139. }
  140. //从候选列表中删除一个元素
  141. function userlist_del(index) {
  142. let deleted = gUserList.splice(index, 1);
  143. $("#user_list").html(render_user_list());
  144. if (gUserList.length == 0) {
  145. $("#coop_new_tools").hide();
  146. }
  147. }
  148. function username_search(keyword, type) {
  149. //let obj = document.querySelector("#cooperator_type_user");
  150. if (type == 1) {
  151. $.get(
  152. "../ucenter/get.php",
  153. {
  154. username: keyword,
  155. },
  156. function (data, status) {
  157. let result;
  158. try {
  159. result = JSON.parse(data);
  160. } catch (error) {
  161. console(error);
  162. }
  163. let html = "<ul id='user_search_list'>";
  164. if (result.length > 0) {
  165. $("#coop_new_tools").show();
  166. for (const iterator of result) {
  167. html +=
  168. "<li onclick=\"user_selected('" +
  169. iterator.id +
  170. "','" +
  171. iterator.username +
  172. "',0)\">" +
  173. iterator.nickname +
  174. "@" +
  175. iterator.username +
  176. "</li>";
  177. }
  178. } else {
  179. $("#coop_new_tools").hide();
  180. }
  181. html += "</ul>";
  182. $("#user_search").html(html);
  183. }
  184. );
  185. } else {
  186. $.get(
  187. "../group/get_name.php",
  188. {
  189. name: keyword,
  190. },
  191. function (data, status) {
  192. let result;
  193. try {
  194. result = JSON.parse(data);
  195. } catch (error) {
  196. console(error);
  197. }
  198. let html = "<ul id='user_search_list'>";
  199. if (result.length > 0) {
  200. $("#coop_new_tools").show();
  201. for (const iterator of result) {
  202. html +=
  203. "<li onclick=\"user_selected('" +
  204. iterator.id +
  205. "','" +
  206. iterator.name +
  207. "',1)\">" +
  208. iterator.name +
  209. "</li>";
  210. }
  211. } else {
  212. $("#coop_new_tools").hide();
  213. }
  214. html += "</ul>";
  215. $("#user_search").html(html);
  216. }
  217. );
  218. }
  219. }
  220. function add_coop() {
  221. let coopList = new Array();
  222. for (const itUser of gUserList) {
  223. if (itUser.type == 0) {
  224. coopList.push({ id: itUser.id, type: itUser.type });
  225. } else if (itUser.type == 1) {
  226. let obj = document.querySelector("#prj_" + itUser.id);
  227. if (obj.checked) {
  228. coopList.push({ id: itUser.id, type: itUser.type });
  229. }
  230. if (typeof itUser.project != "undefined") {
  231. for (const project of itUser.project) {
  232. obj = document.querySelector("#prj_" + project.id);
  233. if (obj.checked) {
  234. coopList.push({ id: project.id, type: itUser.type });
  235. }
  236. }
  237. }
  238. }
  239. }
  240. $.post(
  241. "../share/coop_put.php",
  242. {
  243. res_id: _res_id,
  244. res_type: _res_type,
  245. user_info: JSON.stringify(coopList),
  246. power: $("#coop_new_power").val(),
  247. },
  248. function (data, status) {
  249. cancel_coop();
  250. let result = JSON.parse(data);
  251. if (parseInt(result.status) == 0) {
  252. refresh_coop_list(_res_id);
  253. } else {
  254. alert(result.message);
  255. }
  256. }
  257. );
  258. }
  259. function cancel_coop() {
  260. $("#user_list").html("");
  261. $("#user_search").html("");
  262. $("#coop_new_tools").hide();
  263. $("#search_user").val("");
  264. gUserList = new Array();
  265. }
  266. function coop_remove(userid, username) {
  267. let strMsg = "要删除%name%吗?";
  268. if (confirm(strMsg.replace("%name%", username))) {
  269. $.post(
  270. "../share/coop_del.php",
  271. {
  272. res_id: _res_id,
  273. res_type: _res_type,
  274. user_id: userid,
  275. },
  276. function (data, status) {
  277. cancel_coop();
  278. let result = JSON.parse(data);
  279. if (parseInt(result.status) == 0) {
  280. refresh_coop_list(_res_id);
  281. } else {
  282. alert(result.message);
  283. }
  284. }
  285. );
  286. }
  287. }
  288. function coop_set_power(userid, power) {
  289. {
  290. $.post(
  291. "../share/coop_post.php",
  292. {
  293. res_id: _res_id,
  294. res_type: _res_type,
  295. user_id: userid,
  296. power: $(power).val(),
  297. },
  298. function (data, status) {
  299. cancel_coop();
  300. let result = JSON.parse(data);
  301. if (parseInt(result.status) == 0) {
  302. refresh_coop_list(_res_id);
  303. } else {
  304. alert(result.message);
  305. }
  306. }
  307. );
  308. }
  309. }
  310. function get_group_project(id) {
  311. $.get(
  312. "../group/get.php",
  313. {
  314. id: id,
  315. },
  316. function (data, status) {
  317. let result = JSON.parse(data);
  318. if (parseInt(result.status) == 0) {
  319. refresh_coop_list(_res_id);
  320. } else {
  321. alert(result.message);
  322. }
  323. }
  324. );
  325. }