give_auth.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. "use strict";
  2. function opennamu_give_auth_submit() {
  3. const url = window.location.pathname;
  4. const url_split = url.split('/');
  5. if(url_split.length === 3) {
  6. if(url_split[2] === 'give_total') {
  7. let auth = document.getElementById('opennamu_give_auth_select_org').value;
  8. let change_auth = document.getElementById('opennamu_give_auth_select').value;
  9. let send_data = new FormData();
  10. send_data.append('auth', auth);
  11. send_data.append('change_auth', change_auth);
  12. fetch('/api/v2/auth/give', {
  13. method : 'PATCH',
  14. body : send_data,
  15. }).then(() => {
  16. history.go(0);
  17. }).catch(err => {
  18. console.error(err);
  19. });;
  20. } else {
  21. let change_auth = document.getElementById('opennamu_give_auth_select').value;
  22. let user_name_data = document.getElementById('opennamu_give_auth_user_name').value;
  23. user_name_data = user_name_data.replace('\r', '');
  24. let user_name_arr = user_name_data.split("\n");
  25. for(let for_a = 0; for_a < user_name_arr.length; for_a++) {
  26. let send_data = new FormData();
  27. send_data.append('user_name', user_name_arr[for_a]);
  28. send_data.append('change_auth', change_auth);
  29. fetch('/api/v2/auth/give', {
  30. method : 'PATCH',
  31. body : send_data,
  32. }).then(() => {
  33. history.go(0);
  34. }).catch(err => {
  35. console.error(err);
  36. });;
  37. }
  38. }
  39. } else {
  40. let user_name = url_split[3];
  41. let change_auth = document.getElementById('opennamu_give_auth_select').value;
  42. let send_data = new FormData();
  43. send_data.append('user_name', user_name);
  44. send_data.append('change_auth', change_auth);
  45. fetch('/api/v2/auth/give', {
  46. method : 'PATCH',
  47. body : send_data,
  48. }).then(() => {
  49. history.go(0);
  50. }).catch(err => {
  51. console.error(err);
  52. });
  53. }
  54. }
  55. function opennamu_give_auth() {
  56. const url = window.location.pathname;
  57. const url_split = url.split('/');
  58. let mode = 0;
  59. if(url_split.length === 3) {
  60. if(url_split[2] === 'give_total') {
  61. mode = 1;
  62. }
  63. }
  64. let html_data = '';
  65. let user_name = '';
  66. fetch('/api/v2/list/auth').then(function(res) {
  67. return res.json();
  68. }).then(function(data) {
  69. let lang = data["language"];
  70. let data_list = data["data"];
  71. if(mode === 0) {
  72. if(url_split.length === 3) {
  73. html_data += '<textarea id="opennamu_give_auth_user_name" class="opennamu_textarea_100" placeholder="' + lang["many_delete_help"] + '"></textarea>';
  74. html_data += '<hr class="main_hr">';
  75. } else {
  76. user_name = url_split[3];
  77. html_data += '<div id="opennamu_get_user_info">' + opennamu_xss_filter(user_name) + '</div>';
  78. html_data += '<hr class="main_hr">';
  79. }
  80. } else {
  81. html_data += '<select id="opennamu_give_auth_select_org">';
  82. for(let for_a = 0; for_a < data_list.length; for_a++) {
  83. html_data += '<option value="' + data_list[for_a] + '">' + data_list[for_a] + '</option>';
  84. }
  85. html_data += '</select>';
  86. html_data += '<hr class="main_hr">';
  87. }
  88. html_data += '<select id="opennamu_give_auth_select">';
  89. for(let for_a = 0; for_a < data_list.length; for_a++) {
  90. html_data += '<option value="' + data_list[for_a] + '">' + data_list[for_a] + '</option>';
  91. }
  92. html_data += '</select>';
  93. html_data += '<hr class="main_hr">';
  94. html_data += '<button onclick="opennamu_give_auth_submit();">' + lang["send"] + '</button>';
  95. document.getElementById('opennamu_give_auth').innerHTML = html_data;
  96. if(user_name !== '') {
  97. fetch('/api/v2/auth/' + opennamu_do_url_encode(user_name)).then(function(res) {
  98. return res.json();
  99. }).then(function(data) {
  100. document.getElementById('opennamu_give_auth_select').value = data["name"];
  101. });
  102. }
  103. do_insert_user_info();
  104. });
  105. }