user_select_dlg.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. var _user_select_dlg_div;
  2. function user_select_dlg_init(div) {
  3. _user_select_dlg_div = div;
  4. let html = "";
  5. html += "<div id='user_select_dlg'>";
  6. html += "<div >";
  7. html += "<div >" + gLocal.gui.nick_name + "/" + gLocal.gui.group + "</div>";
  8. html += "<input type='text' id='user_select_title' maxlength='32' placeholder='" + gLocal.gui.name + "' ";
  9. html += 'onkeyup="username_search_keyup(event,this)"';
  10. html += "/>";
  11. html += "</div>";
  12. html += "<div id='user_list'>";
  13. html += "</div>";
  14. html += "<div style='display:flex;justify-content: space-between;padding-top: 1em;'>";
  15. html += "<div>";
  16. html += "</div>";
  17. html += "<div>";
  18. html += "<button onclick='user_select_cancel()'>" + gLocal.gui.cancel + "</button>";
  19. html += "</div>";
  20. html += "</div>";
  21. html += "</div>";
  22. $("#" + div).append(html);
  23. }
  24. function user_select_dlg_show() {
  25. $("#" + _user_select_dlg_div).show();
  26. }
  27. function user_select_dlg_hide() {
  28. $("#" + _user_select_dlg_div).hide();
  29. }
  30. function user_select_cancel() {
  31. user_select_dlg_hide();
  32. $("#user_select_title").val("");
  33. }
  34. function username_search_keyup(e, obj) {
  35. var keynum;
  36. if (window.event) {
  37. // IE
  38. keynum = e.keyCode;
  39. } else if (e.which) {
  40. // Netscape/Firefox/Opera
  41. keynum = e.which;
  42. }
  43. var keychar = String.fromCharCode(keynum);
  44. if (keynum == 13) {
  45. //dict_search(obj.value);
  46. } else {
  47. username_search(obj.value, 1);
  48. }
  49. }
  50. function username_search(keyword, type) {
  51. //let obj = document.querySelector("#cooperator_type_user");
  52. if (type == 1) {
  53. $.get(
  54. "../ucenter/get.php",
  55. {
  56. username: keyword,
  57. },
  58. function (data, status) {
  59. let result;
  60. try {
  61. result = JSON.parse(data);
  62. } catch (error) {
  63. console(error);
  64. }
  65. let html = "<ul id='user_search_list'>";
  66. if (result.length > 0) {
  67. for (x in result) {
  68. html +=
  69. "<li><a onclick=\"user_selected('" +
  70. result[x].id +
  71. "',0)\">" +
  72. result[x].nickname +
  73. "[" +
  74. result[x].email +
  75. "]</a></li>";
  76. }
  77. }
  78. html += "</ul>";
  79. $("#user_list").html(html);
  80. }
  81. );
  82. } else {
  83. $.get(
  84. "../group/get_name.php",
  85. {
  86. name: keyword,
  87. },
  88. function (data, status) {
  89. let result;
  90. try {
  91. result = JSON.parse(data);
  92. } catch (error) {
  93. console(error);
  94. }
  95. let html = "<ul id='user_search_list'>";
  96. if (result.length > 0) {
  97. for (const iterator of result) {
  98. html +=
  99. "<li><a onclick=\"coop_add('" +
  100. iterator.id +
  101. "',1)\">" +
  102. iterator.name +
  103. "[" +
  104. iterator.username.nickname +
  105. "]</a></li>";
  106. }
  107. }
  108. html += "</ul>";
  109. $("#search_result").html(html);
  110. }
  111. );
  112. }
  113. }