share.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. var _res_id;
  2. var _res_type;
  3. var gUserList = new Array();
  4. function share_load(id, type) {
  5. refresh_coop_list(id, type);
  6. }
  7. function refresh_coop_list(id, type) {
  8. $.get(
  9. "../share/coop_get.php",
  10. {
  11. res_id: id,
  12. res_type: type,
  13. },
  14. function (data, status) {
  15. if (status == "success") {
  16. let result = JSON.parse(data);
  17. $("#coop_list").html(render_coop_list(result));
  18. }
  19. }
  20. );
  21. }
  22. function render_coop_list(cooplist) {
  23. let html = "";
  24. if (typeof cooplist == "undefined" || cooplist.length == 0) {
  25. html += gLocal.gui.empty_null_mark;
  26. } else {
  27. for (const coop of cooplist) {
  28. html += '<div class="file_list_row" style="padding:5px;">';
  29. let username;
  30. if (coop.cooperator_type == 0) {
  31. username = coop.user.nickname;
  32. html += '<div style="flex:1;" title="' + gLocal.gui.personal + '">';
  33. html += "<svg class='icon'>";
  34. html += " <use xlink:href='../studio/svg/icon.svg#ic_person'></use>";
  35. html += "</svg>";
  36. html += "</div>";
  37. html += "<div style='flex:3;'>" + username + "</div>";
  38. } else {
  39. username = coop.user;
  40. html += '<div style="flex:1;" title="' + gLocal.gui.group + '">';
  41. html += "<svg class='icon'>";
  42. html += " <use xlink:href='../studio/svg/icon.svg#ic_two_person'></use>";
  43. html += "</svg>";
  44. html += "</div>";
  45. html += "<div style='flex:3;'>";
  46. if (coop.parent_name != "") {
  47. html += coop.parent_name + "/";
  48. }
  49. html += username + "</div>";
  50. }
  51. html += "<div style='flex:3;'>";
  52. let power = [
  53. { id: 10, string: gLocal.gui.viewer },
  54. { id: 20, string: gLocal.gui.editor },
  55. ];
  56. html += "<select onchange=\"coop_set_power('" + coop.cooperator_id + "',this)\">";
  57. for (const iterator of power) {
  58. html += "<option value='" + iterator.id + "' ";
  59. if (iterator.id == coop.power) {
  60. html += " selected ";
  61. }
  62. html += ">" + iterator.string + "</option>";
  63. }
  64. html += "</select>";
  65. html += "</div>";
  66. html += "<div class='hover_button' style='flex:3;'>";
  67. html +=
  68. "<button onclick=\"coop_remove('" +
  69. coop.cooperator_id +
  70. "','" +
  71. username +
  72. "')\">" +
  73. gLocal.gui.remove +
  74. "</button>";
  75. html += "</div>";
  76. html += "</div>";
  77. }
  78. }
  79. return html;
  80. }
  81. function username_search_keyup(e, obj) {
  82. var keynum;
  83. if (window.event) {
  84. // IE
  85. keynum = e.keyCode;
  86. } else if (e.which) {
  87. // Netscape/Firefox/Opera
  88. keynum = e.which;
  89. }
  90. var keychar = String.fromCharCode(keynum);
  91. if (keynum == 13) {
  92. } else {
  93. if (obj.value.length > 0) {
  94. let type = $("#user_type").val();
  95. username_search(obj.value, type);
  96. } else {
  97. $("#user_search").html("");
  98. }
  99. }
  100. }
  101. function user_selected(id, name, type) {
  102. if (parseInt(type) == 0) {
  103. gUserList.push({ id: id, name: name, type: type });
  104. $("#user_list").html(render_user_list());
  105. $("#user_search").html("");
  106. } else {
  107. $.get("../group/get.php", { id: id }, function (data, status) {
  108. if (status == "success") {
  109. try {
  110. let result = JSON.parse(data);
  111. gUserList.push({ id: id, name: name, type: type, project: result.children });
  112. $("#user_list").html(render_user_list());
  113. $("#user_search").html("");
  114. } catch (e) {}
  115. }
  116. });
  117. }
  118. }
  119. function render_user_list() {
  120. let html = "<ul>";
  121. let arrIndex = 0;
  122. for (const iterator of gUserList) {
  123. html += "<li>";
  124. html += "<span>";
  125. if (iterator.type == 1) {
  126. //小组
  127. html += "👥";
  128. } else {
  129. html += "👤";
  130. }
  131. html += iterator.name;
  132. html += "</span>";
  133. html += "<a class='btn_del' onclick=\"userlist_del(' + arrIndex + ')\">"+gLocal.gui.delete+"</a>";
  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. coopList.push({ id: itUser.id, type: itUser.type });
  224. /*
  225. if (itUser.type == 0) {
  226. coopList.push({ id: itUser.id, type: itUser.type });
  227. } else if (itUser.type == 1) {
  228. let obj = document.querySelector("#prj_" + itUser.id);
  229. if (obj.checked) {
  230. coopList.push({ id: itUser.id, type: itUser.type });
  231. }
  232. if (typeof itUser.project != "undefined") {
  233. for (const project of itUser.project) {
  234. obj = document.querySelector("#prj_" + project.id);
  235. if (obj.checked) {
  236. coopList.push({ id: project.id, type: itUser.type });
  237. }
  238. }
  239. }
  240. }
  241. */
  242. }
  243. $.post(
  244. "../share/coop_put.php",
  245. {
  246. res_id: _res_id,
  247. res_type: _res_type,
  248. user_info: JSON.stringify(coopList),
  249. power: $("#coop_new_power").val(),
  250. },
  251. function (data, status) {
  252. cancel_coop();
  253. let result = JSON.parse(data);
  254. if (parseInt(result.status) == 0) {
  255. refresh_coop_list(_res_id, _res_type);
  256. } else {
  257. alert(result.message);
  258. }
  259. }
  260. );
  261. }
  262. function cancel_coop() {
  263. $("#user_list").html("");
  264. $("#user_search").html("");
  265. $("#coop_new_tools").hide();
  266. $("#search_user").val("");
  267. gUserList = new Array();
  268. }
  269. function coop_remove(userid, username) {
  270. let strMsg = "要删除%name%吗?";
  271. if (confirm(strMsg.replace("%name%", username))) {
  272. $.post(
  273. "../share/coop_del.php",
  274. {
  275. res_id: _res_id,
  276. res_type: _res_type,
  277. user_id: userid,
  278. },
  279. function (data, status) {
  280. cancel_coop();
  281. let result = JSON.parse(data);
  282. if (parseInt(result.status) == 0) {
  283. refresh_coop_list(_res_id, _res_type);
  284. } else {
  285. alert(result.message);
  286. }
  287. }
  288. );
  289. }
  290. }
  291. function coop_set_power(userid, power) {
  292. {
  293. $.post(
  294. "../share/coop_post.php",
  295. {
  296. res_id: _res_id,
  297. res_type: _res_type,
  298. user_id: userid,
  299. power: $(power).val(),
  300. },
  301. function (data, status) {
  302. cancel_coop();
  303. let result = JSON.parse(data);
  304. if (parseInt(result.status) == 0) {
  305. refresh_coop_list(_res_id, _res_type);
  306. } else {
  307. alert(result.message);
  308. }
  309. }
  310. );
  311. }
  312. }